How to setup Prometheus and Grafana to monitor ( Part2)

Setup Prometheus and Grafana in Centos7


  • Centos 7
  • Windows Server 2012


Setup Prometheus:

  • Create User
    sudo groupadd --system prometheus
    sudo useradd -s /sbin/nologin --system -g prometheus prometheus
  • Create Folder For Prometheus:
    mkdir /etc/prometheus
    mkdir /var/lib/prometheus
  • Change the owner and group of these folders to Prometheus (User just created).
    sudo mkdir -p -m 775 /etc/prometheus/{rules,rules.d,files_sd}
  • Disable SELINUX : Open the /etc/selinux/config file and set the SELINUX mod to disabled

  • Setup Prometheus by packet:

    tar xvzf prometheus-2.20.1.linux-amd64.tar.gz
    cd prometheus-2.20.1.linux-amd64
  • Copy Prometheus binary, console and console_libraries.
    sudo cp prometheus promtool /usr/local/bin/
    sudo cp -r consoles/ console_libraries/ /etc/prometheus/
  • Create configuration file:
sudo vi /etc/prometheus/prometheus.yml

  scrape_interval:     15s 
  evaluation_interval: 15s 
  scrape_timeout: 15s  
  - job_name: 'prometheus'
    - targets: ['localhost:9090']
  • Create Service:
sudo vi /etc/systemd/system/prometheus.service


ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus \
  --web.console.templates=/etc/prometheus/consoles \
  --web.console.libraries=/etc/prometheus/console_libraries \
  --web.listen-address= \


  • Continue to change directory permissions:
    sudo chown -R prometheus:prometheus /etc/prometheus
    sudo chown -R prometheus:prometheus /var/lib/prometheus/
  • Restart Service:
    sudo systemctl daemon-reload
    sudo systemctl start prometheus
  • If you want to management from another PC:
    firewall-cmd --permanent --add-port=9090/tcp
    firewall-cmd --reload
    That's it, we can go to the address on the machine localhost:9090 to go to the prometheus page. By default, in the prometheus.yml file, only the job is localhost, if you want to add many different machines, you must install the node_exporter package for each machine.

Setup Grafana:

Grafana Download

  • Download :
    sudo yum install grafana-7.1.3-1.x86_64.rpm
  • Start and enable service:

    sudo service grafana-server start
    sudo /sbin/chkconfig –add grafana-server
    systemctl enable --now grafana-server.service
  • Open Port 3000
    firewall-cmd --permanent --add-port=3000/tcp
    firewall-cmd --reload
  • Visit Grafana's website: http://IP:3000
  • Setup Data Source: IPLocal:9090

Setup Grafana monitor Server 2012 by Prometheus:

  • Download json for Grafana: Json-windows
  • Download wmi_exporter for winserver 2012: wmi_exporter

    Connect Grafana to prometheus:

  • Select Configuration, then select the data source type as Prometheus
  • Enter information of prometheus (ip of Prometheus server), then save.
  • So we have completed the connection between Grafana and Prometheus.
  • Open port 9182 on windows server 2012 to let service.

    There are 2 versions of Agent:

  • wmi_exporter.exe (click to run, for those of you who just need the metrics enabled).
  • wmi_exporter.msi (used to install via CMD, enable advanced metric collection features).

    Open CMD run with admin:

    msiexec /i C:\xxx ENABLED_COLLECTORS=”ad,cpu,cs,logon,memory,logical_disk,os,service,system,process,tcp,net,textfile,thermalzone”
    trong đó xxx là tên file exporter
    ENABLED_COLLECTORS=”types of metrics to collect, the name of the metric type in the image above
    -After the installation is complete, check if the service can see WMI_Exporter, if so, you have successfully installed it.
  • Check http://IP:9182
  • We return to Prometheus.yml to edit the job with the following content:
vi /etc/prometheus/prometheus.yml

  job_name: ‘windows’


    targets: [‘IP Windows 2012:9182’]
  • Restart Service Prometheus:
systemctl restart prometheus
systemctl status prometheus
  • Then go back to prometheus' web manager: IP:9090 to see the target.
  • Create Dashboard monitor Windows server on Grafana.
  • Go to Grafana, then select Manage Dashboards:
  • Select Import, select the json file you just downloaded.
  • Click OK.
  • Done.


No Comments Yet