Monitoring Windows Servers Using WMI Exporter & Prometheus
In the previous blog , I have explained on how to create Windows EC2 Instance using AWS console.
In this guide , We will see how to setup a monitoring for windows servers using WMI exporter and Prometheus and also setup a monitoring using Grafana
If you havn’t Implemented Prometheus & Grafana , Check the below article.
How to install and configure Prometheus
Setup Grafana & Prometheus Monitoring
What Is WMI Exporter?
WMI expoter is a exporter used for windows servers to collects metrics such as CPU usage , memory and Disk usage.
It is a open source which can be installed on the windows servers using .msi installer.
Installing WMI Exporter
The latest version of WMI exporter’s installation package can downloed from the below link.
Download the package depending on the CPU architecture.
I will be downloading the .msi file.
Once the package is downloaded ,
If you are prompted by the firewall , Accept it to make sure the wmi exporter runs properly.
Go to Downloads and click Run
The MSI installer doesn’t show any response , But it will run as Windows service on the server.
To verify whether the exporter is running fine , In the search box , Type services and Click Services
You will be taken to the following Services page , Where we can find all the windows services.
The old name of the service was called as WMI exporter , From the latest release , We can see a service running in the name windows_exporter
By default , wmi exporter runs on the port 9182.
To verify that , Open the command prompt and run,
netstat -a -b
We have confirmed that the wmi exporter is running and on the port 9182.
The exporter will start exposing metrics on http://localhost:9182/metrics
Now we have system metrics collected by the exporter.Lets send these metrics to the Prometheus and setup a monitoring using Grafana.
Integrating Prometheus With WMI Exporter
As we already know that the Prometheus scrapes targets for the metrics.
To configure this , Login to prometheus server and Open the configuration file.
The prometheus configuration should look something like as shown below.
We are going to add a job for the wmi exporter under the scrape_configs as shown below.
- job_name: 'wmiexporter' scrape_interval: 30s static_configs: targets: ['WindowsIP:9182']
Once added , Save and close the file.
We need to restart the prometheus service.
systemctl restart prometheus
And we can check the status of the prometheus,
systemctl status prometheus
Now the WMI exporter server is added under prometheus targets. The proemtheus should be able to scrape the metrics collected by WMI exporter.
To verify that , Login to Prometheus Web UI,
We should see the following page.
Under Status , Click Targets
WMI exporter is UP and able to scrape the metrics.
By this time , We have WMI exporter running fine and the Prometheus service is able to scrape the metrics from the wmi exporter.
Now Its time to setup alerting for the windows server using Grafana with the help of prometheus as the data source.
Integrating Prometheus With Grafana
I assume that you have grafana server UP and running , If not , Check this article to setup grafana.
Once the Grafana setup is implemented , Login to Grafana Web interface,
To check the wmi exporters metrics which is already stored in the prometheus server , We need to integrate prometheus with grafana.
To integrate , Hover to Settings icon and choose Datasources
Under Configuration , You can add the datasources here.
Grafana can query data from these datasource to plot the graphs.
For this tutorial , We are going to use Prometheus as the datasource.
Click Add Data source and then choose Prometheus
Here we will asked to provide few information such as Prometheus URL.
Provide a name for the datasource , and then provide the ip address and the port in which Prometheus is Running.
In our case , It is
Grafana should be able to access port 9090 and it should be whitelisted in the Firewall.
Now click Save and Test , It should response as Data source is working
We have now integrated both the services.
Now Its time to setup alerting mechanism
Setup Alerting In Grafana
For the Grafana to alert to a specific channel or medium, We need to add / configure the same.
Choose Alerting and then click Notification channels
Click Add channel , From the lists of available notification channels , Choose the one where you will be active.
Provide a name for the Notification Channel and then choose Type.
Once done , Click Save.
Now We have datasource and the alerting mechanism.
Lets go ahead and setup dashboard and configure the alerting for the same.
Setting Up Grafana Dashboards
We can setup dashboard by ourselves from the scratch or we can import the existing dashboard from Grafana.
To setup a dashboard for the WMI Exporter metrics.
In the left side , Hover to + icon and choose Import
It will ask us the id of the dashboard. The id to import the WMI exporter graph is 2129.
Provide the id and then click Load
Give a name for the dashboard and then choose the data source as Prometheus.
and then click Import.
It will collect all the metrics from the Prometheus data source and plot the graph as per the metrics such as CPU usage , Disk usage , Memory usage etc.
Using the dashboard we have created , We can check the resources used by the servers.
To setup alerting for each of the above metrics ,
Click on CPU load and choose Edit , Select the alert icon
Provide a name for the Alert rule , and mention how often the evaluation should happen for the condition we set.
The condition for the rule is , if the threshold is above certain percentage / value during the evaluation period we will be alerted.
For notification , Click + icon and choose the notification channel we have created and add a description for the alerts messages.
Follow the same procedure for the Disk usage and the Memory usage.
By doing so , We can actively monitor the performance and the resources utilised by the services running in the servers.So that we can take the necessary actions prior to services or servers going unreachable.
We have successfully implemented a complete monitoring and alerting mechanism for the windows servers using Prometheus , WMI exporter and Grafana.
Hope you find it helpful.Please do check out my other articles.