Wmi exporter prometheus windows

config.file# windows_exporter

A Prometheus exporter for Windows machines.

Collectors

Name Description Enabled by default
ad Active Directory Domain Services
adcs Active Directory Certificate Services
adfs Active Directory Federation Services
cache Cache metrics
cpu CPU usage
cpu_info CPU Information
cs «Computer System» metrics (system properties, num cpus/total memory)
container Container metrics
diskdrive Diskdrive metrics
dfsr DFSR metrics
dhcp DHCP Server
dns DNS Server
exchange Exchange metrics
filetime FileTime metrics
fsrmquota Microsoft File Server Resource Manager (FSRM) Quotas collector
hyperv Hyper-V hosts
iis IIS sites and applications
license Windows license status
logical_disk Logical disks, disk I/O
memory Memory usage metrics
mscluster MSCluster metrics
msmq MSMQ queues
mssql SQL Server Performance Objects metrics
netframework .NET Framework metrics
net Network interface I/O
os OS metrics (memory, processes, users)
pagefile pagefile metrics
performancecounter Custom performance counter metrics
physical_disk physical disk metrics
printer Printer metrics
process Per-process metrics
remote_fx RemoteFX protocol (RDP) metrics
scheduled_task Scheduled Tasks metrics
service Service state metrics
smb SMB Server
smbclient SMB Client
smtp IIS SMTP Server
system System calls
tcp TCP connections
terminal_services Terminal services (RDS)
textfile Read prometheus metrics from a text file
thermalzone Thermal information
time Windows Time Service
udp UDP connections
update Windows Update Service
vmware Performance counters installed by the Vmware Guest agent

See the linked documentation on each collector for more information on reported metrics, configuration settings and usage examples.

Filtering enabled collectors

The windows_exporter will expose all metrics from enabled collectors by default. This is the recommended way to collect metrics to avoid errors when comparing metrics of different families.

For advanced use the windows_exporter can be passed an optional list of collectors to filter metrics. The collect[] parameter may be used multiple times. In Prometheus configuration you can use this syntax under the scrape config.

  params:
    collect[]:
      - foo
      - bar

This can be useful for having different Prometheus servers collect specific metrics from nodes.

Flags

windows_exporter accepts flags to configure certain behaviours. The ones configuring the global behaviour of the exporter are listed below, while collector-specific ones are documented in the respective collector documentation above.

Flag Description Default value
--web.listen-address host:port for exporter. :9182
--telemetry.path URL path for surfacing collected metrics. /metrics
--telemetry.max-requests Maximum number of concurrent requests. 0 to disable. 5
--collectors.enabled Comma-separated list of collectors to use. Use [defaults] as a placeholder which gets expanded containing all the collectors enabled by default. [defaults]
--collectors.print If true, print available collectors and exit.
--scrape.timeout-margin Seconds to subtract from the timeout allowed by the client. Tune to allow for overhead or high loads. 0.5
--web.config.file A web config for setting up TLS and Auth None
--config.file Using a config file from path or URL None
--log.file Output file of log messages. One of [stdout, stderr, eventlog, <path to log file>]
NOTE: The MSI installer will add a default argument to the installed service setting this to eventlog
stderr

Installation

The latest release can be downloaded from the releases page.

All binaries and installation packages are signed with an self-signed certificate. The public key can be found here.
Once import into the trusted root certificate store, the binaries and installation packages will be trusted.

Each release provides a .msi installer. The installer will setup the windows_exporter as a Windows service, as well as create an exception in the Windows Firewall.

If the installer is run without any parameters, the exporter will run with default settings for enabled collectors, ports, etc.

The installer provides a configuration file to customize the exporter.

The configuration file

  • is located in the same directory as the exporter executable.
  • has the YAML format and is provided with the --config.file parameter.
  • can be used to enable or disable collectors, set collector-specific parameters, and set global parameters.

The following parameters are available:

Name Description
ENABLED_COLLECTORS As the --collectors.enabled flag, provide a comma-separated list of enabled collectors
CONFIG_FILE Use the --config.file flag to specify a config file. If empty, no config file will be set. The special value config.yaml set the path to the config.yaml at install dir
LISTEN_ADDR The IP address to bind to. Defaults to an empty string. (any local address)
LISTEN_PORT The port to bind to. Defaults to 9182.
METRICS_PATH The path at which to serve metrics. Defaults to /metrics
TEXTFILE_DIRS Use the --collector.textfile.directories flag to specify one or more directories, separated by commas, where the collector should read text files containing metrics
REMOTE_ADDR Allows setting comma separated remote IP addresses for the Windows Firewall exception (allow list). Defaults to an empty string (any remote address).
EXTRA_FLAGS Allows passing full CLI flags. Defaults to an empty string. For --collectors.enabled and --config.file, use the specialized properties ENABLED_COLLECTORS and CONFIG_FILE
ADDLOCAL Enables features within the windows_exporter installer. Supported values: FirewallException
REMOVE Disables features within the windows_exporter installer. Supported values: FirewallException
APPLICATIONFOLDER Directory to install windows_exporter. Defaults to C:\Program Files\windows_exporter

Parameters are sent to the installer via msiexec.
On PowerShell, the --% should be passed before defining properties.

Example invocations:

msiexec /i <path-to-msi-file> --% ENABLED_COLLECTORS=os,iis LISTEN_PORT=5000

Example service collector with a custom query.

msiexec /i <path-to-msi-file> --% ENABLED_COLLECTORS=os,service EXTRA_FLAGS="--collectors.exchange.enabled=""ADAccessProcesses"""

Define a config file.

msiexec /i <path-to-msi-file> --% CONFIG_FILE="D:\config.yaml"

Alternative install directory

msiexec /i <path-to-msi-file> --% ADDLOCAL=FirewallException APPLICATIONFOLDER="F:\Program Files\windows_exporter"

On some older versions of Windows,
you may need to surround parameter values with double quotes to get the installation command parsing properly:

msiexec /i C:\Users\Administrator\Downloads\windows_exporter.msi --% ENABLED_COLLECTORS="ad,iis,logon,memory,process,tcp,textfile,thermalzone" TEXTFILE_DIRS="C:\custom_metrics\"

To install the exporter with creating a firewall exception, use the following command:

msiexec /i <path-to-msi-file> --% ADDLOCAL=FirewallException

PowerShell versions 7.3 and above require PSNativeCommandArgumentPassing to be set to Legacy when using --% EXTRA_FLAGS:

$PSNativeCommandArgumentPassing = 'Legacy'
msiexec /i <path-to-msi-file> ENABLED_COLLECTORS=os,service --% EXTRA_FLAGS="--collectors.exchange.enabled=""ADAccessProcesses"""

Docker Implementation

The windows_exporter can be run as a Docker container. The Docker image is available on

  • Docker Hub: docker.io/prometheuscommunity/windows-exporter
  • GitHub Container Registry: ghcr.io/prometheus-community/windows-exporter
  • quay.io Registry: quay.io/prometheuscommunity/windows-exporter

Tags

The Docker image is tagged with the version of the exporter. The latest tag is also available and points to the latest release.

Additionally, a flavor hostprocess with -hostprocess as suffix is based on the https://github.com/microsoft/windows-host-process-containers-base-image
which is designed to run as a Windows host process container. The size of that images is smaller than the default one.

Kubernetes Implementation

See detailed steps to install on Windows Kubernetes here.

Supported versions

windows_exporter supports Windows Server versions 2016 and later, and desktop Windows version 10 and 11 (21H2 or later).

Windows Server 2012 and 2012R2 are supported as best-effort only, but not guaranteed to work.

Usage

go get -u github.com/prometheus/promu
go get -u github.com/prometheus-community/windows_exporter
cd $env:GOPATH/src/github.com/prometheus-community/windows_exporter
promu build -v
.\windows_exporter.exe

The prometheus metrics will be exposed on localhost:9182

HTTP Endpoints

windows_exporter provides the following HTTP endpoints:

  • /metrics: Exposes metrics in the Prometheus text format.
  • /health: Returns 200 OK when the exporter is running.
  • /debug/pprof/: Exposes the pprof endpoints. Only, if --debug.enabled is set.

Examples

Enable only service collector and specify a custom query

.\windows_exporter.exe --collectors.enabled "service" --collector.service.include="windows_exporter"

Enable only process collector and specify a custom query

.\windows_exporter.exe --collectors.enabled "process" --collector.process.include="firefox.+"

When there are multiple processes with the same name, WMI represents those after the first instance as process-name#index. So to get them all, rather than just the first one, the regular expression must use .+. See process for more information.

Using [defaults] with --collectors.enabled argument

Using [defaults] with --collectors.enabled argument which gets expanded with all default collectors.

.\windows_exporter.exe --collectors.enabled "[defaults],process,container"

This enables the additional process and container collectors on top of the defaults.

Using a configuration file

YAML configuration files can be specified with the --config.file flag. e.g. .\windows_exporter.exe --config.file=config.yml. If you are using the absolute path, make sure to quote the path, e.g. .\windows_exporter.exe --config.file="C:\Program Files\windows_exporter\config.yml"

It is also possible to load the configuration from a URL. e.g. .\windows_exporter.exe --config.file="https://example.com/config.yml"

If you need to skip TLS verification, you can use the --config.file.insecure-skip-verify flag. e.g. .\windows_exporter.exe --config.file="https://example.com/config.yml" --config.file.insecure-skip-verify

collectors:
  enabled: cpu,net,service
collector:
  service:
    include: windows_exporter
log:
  level: warn

An example configuration file can be found here.

Configuration file notes

Configuration file values can be mixed with CLI flags. E.G.

.\windows_exporter.exe --collectors.enabled=cpu,logon

CLI flags enjoy a higher priority over values specified in the configuration file.

License

Under MIT

In this article we will monitor windows server with prometheus wmi_exporter. With linux server, you can read my following article.

Recommended Reading: Monitor linux server with Prometheus node exporter

Install wmi_exporter on windows server

First, you need to check the version to install at this link. The current version is v0.13.0.

Log in to the windows server you need to monitor, download the msi installation package with the link below.

You Might Be Interested In

https://github.com/prometheus-community/windows_exporter/releases/download/v0.13.0/windows_exporter-0.13.0-amd64.msi

After downloading, install the software like you install other software. Double click on the installation file and next until finished.

Then, open Task Manager and go to the Processes tab, find the windows_exporter process and see if it is running. If the process is running, it is ok.

Monitor windows server with Prometheus wmi_exporter

Monitor windows server with prometheus wmi_exporter.

Now the windows exporter will run on port 9182. You need to open the firewall on the windows server to allow access to port 9182.

Set up prometheus configuration

And now, we will set up prometheus to call the windows exporter on the windows server.

You open the configuration file.

nano /etc/prometheus/prometheus.yml

You add the content below at the end of the file.

  - job_name: 'wmi_exporter'
    metrics_path: /metrics
    scrape_interval: 5s
    static_configs:
    - targets:
      - hostname-winserver:9182

Next, find the paragraph below and declare the rule alert file path for the windows server.

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
    - "/etc/prometheus/rules/windows.yml"

After editing, save the file but do not reload or restart the prometheus service.

Set up the alert server windows rule file

As you can see above, we set up prometheus to call a file containing alert rules for the windows server.

Now you create the file as below.

nano /etc/prometheus/rules/windows.yml

Then you use the rule structure as below to add it to the file.

groups:
- name: Windows Server
  rules:
  - alert: Server Windows Down
    expr: up{job="wmi_exporter"} == 0
    for: 10s
    labels:
      severity: "Critical"
    annotations:
      Summary: 'Server "{{ $labels.instance }}" down.'

You can download the full rule file for windows server at my gitlab link.

Now you have reloaded the prometheus service.

systemctl reload prometheus

Set up the Grafana monitor server windows dashboard

You can import and use the dashboard with ID 10467. However, this dashboard is displayed in Chinese.

If you want to use English, you can download the json file from my gitlab and import it.

Conclusion

Very fast and simple, isn’t it? You can now set up monitor server windows easily. Grafana provides you with a complete interface to view resources on the server. Alertmanager will ensure to send you notifications when the server has resource problems.

Daniel Pham

Hi my friend, I am a DevOps/DevSecOps engineer. I am living and working in Da Nang, Vietnam.

In this article we are going to cover How Install Install Prometheus and Grafana on Windows with WMI Exporter, Configure Prometheus as Grafana DataSource.

Table of Contents

What is prometheus?

  • Prometheus is a open source Linux Server Monitoring tool mainly used for metrics monitoring, event monitoring, alert management, etc.
  • Prometheus has changed the way of monitoring systems and that is why it has become the Top-Level project of Cloud Native Computing Foundation (CNCF).
  • Prometheus uses a powerful query language i.e. “PromQL”.
  • In Prometheus tabs are on and handles hundreds of services and microservices.
  • Prometheus use multiple modes used for graphing and dashboarding support.

Why we used prometheus?

  • A multi-dimensional data model with time series data identified by metric name and key/value pairs
  • PromQL, a flexible query language to leverage this dimensionality
  • Pushing time series is supported via an intermediary gateway
  • Multiple modes of graphing and dashboarding support

Prometheus Architecture 

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 1

  • As above we can see an architecture of Prometheus monitoring tool.
  • We made a basic design to understand it easily for you people.

Now lets understand the Prometheus components one-by-one

Prometheus Components

1. Prometheus Server

  • Prometheus server is a first component of Prometheus architecture.
  • Prometheus server is a core of Prometheus architecture which is divided into several parts like Storage, PromQL, HTTP server, etc.
  • In Prometheus server data is scraped from the target nodes and then stored in the database.

1.a. Storage

  • Storage in Prometheus server has a local on disk storage.
  • Prometheus has many interfaces that allow integrating with remote storage systems.

1.b. PromQL

  • Prometheus uses its own query language i.e. PromQL which is a very powerful querying language.
  • PromQL allows the user to select and aggregate the data.

2. Service Discovery

  • Next and very important component of Prometheus Server is the Service Discovery.
  • With the help of Service discovery the services are identified which need to be scraped.
  • To Pull metrics, identification of services and finding the targets are compulsory needed.
  • Through Service discovery we monitor the entities and can also locate its targets.

3. Scrape Target

  • Once the services are identified and the targets are ready then we can pull metrics from it and can scrape the target.
  • We can export the data of the end point using node exporters.
  • Once the metrics or other data is pulled, Prometheus stores it in a local storage.

4. Alert Manager

  • Alert Manager handles the alerts which may occurs during the session.
  • Alert manager handles all the alerts which are sent by the Prometheus server.
  • Alert manager is one of the very useful components of the Prometheus tool.
  • If in case any big error or any issue occurs, alert manager manage those alerts and contact with human via E-mail, Text Messages, On-call, or any other chat application service.

5. User Interface

  • User interface is also an important component as it builds a bridge between the user and the system.
  • In Prometheus, user interfaces are note that much user friendly and can be used till graph queries.
  • For good exclusive dashboards Prometheus works together with Grafana (visualization tool).
  • Using Grafana over Prometheus to visualize properly we can use custom dashboards.
  • Grafana dashboards display via pie charts, line charts, tables, good data graphs of CPU usage, RAM utilization, network load, etc with indicators.
  • Grafana supports and run with Prometheus by querying language i.e. PromQL.
  • To fetch data from Prometheus and to display the results on Grafana dashboards PromQL is used.

What is Grafana ?

  • Grafana is a free and open source visualization tool mostly used with Prometheus to which monitor metrics.
  • Grafana provides various dashboards, charts, graphs, alerts for the particular data source.
  • Grafana allows us to query, visualize, explore metrics and set alerts for the data source which can be a system, server, nodes, cluster, etc.
  • We can also create our own dynamic dashboard for visualization and monitoring.
  • We can save the dashboard and can even share with our team members which is one of the main advantage of Grafana.

What is WMI Exporter?

  • It is same like Node Exporter but Node Exporter for Linux and WMI Exporter for Windows
  • WMI Exporter is an exporter utilized for windows servers to collects metrics like CPU usage, memory, and Disk usage.
  • It is open-source which can be installed on Windows servers using the .msi installer

Prerequisite: 

  • Good internet connectivity 
  • Security Groups Configured properly
  • Any web Browser

Security Groups Configured on EC2 Instances

  • Port 9090 — Prometheus Server
  • Port 9182—-WMI Exporter
  • Port 3000 — Grafana

#1. Download Prometheus for windows

Now we will download the latest version of Prometheus. We can copy the download link as per our Operating System from Prometheus download page

Using the below command we can download Prometheus, here we are downloading Prometheus 2.32.1 version, you use the above link to download specific version.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 2

download prometheus

We have to install prometheus service but in windows we can not installl prometheus as a service for that here im using NSSM package to install Prometheus service 

Open your command prompt run as administrator 

Paste the directory path like below command:

cd c:\users\Administrator\Downloads\nssm-2.24\nssm-2.24\win64
dir
nssm.exe install prometheus<<and your prometheus application directory path>> \prometheus
Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 3

install prometheus

Now Prometheus is successfully installed in your machine

So let’s check the status in prometheus service on windows.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 4

start prometheus

For now Prometheus is stop after changing in configuration file we will start prometheus

After installation now we are going to install Grafana on Window

#2. Install Grafana on Windows

Now we will download the latest version of Grafana.from official page of Grafana select window operating system and download .msi installer

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 5

install grafana

After download of grafana we will install grafana on window

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 6

grafana

After installation of Grafana go to C:<<Program Files<<GrafanaLabs<<Grafana<< conf<<defaults

In default change the smtp enabled false replace with true you can check the below image

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 7

smtp

To access Grafana Dashboard open your favorite browser, type server IP or Name followed by grafana default port 3000.

http://localhost:3000

Here you can see Login page of Grafana now you will have to login with below Grafana default UserName and Password.

Username – admin
Password – admin
Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 8

login grafana

It is always a good practice to change your login credentials.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 9

enter password

Provide your New Password and click on Change Password

Now here you can see Home Dashboard page of Grafana

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 10

welcome to grafana

#3. Install WMI Exporter on Windows

For Windows hosts, you are going to use the Windows exporter.

You can download the latest version of windows installer from here

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 11

When the download is done, simply click on the MSI file and start running the installer.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 12

wmi

After Installation of WMI Exporter lets check its successfully installed or not

So go to services and search windows exporter.

Make sure windows exporter service is running.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 13

Now that your exporter is running, it should start exposing metrics on

http://localhost:9182/metrics

So let’s check

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 14

#4. Update Prometheus Configuration file

Go to the Prometheus file and open Prometheus.yml file and 

Update config file with below code:

 - job_name: "WMI Exporter"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["Host_ip:9182"]

Now save the file and exit

After changing in config file you need to start prometheus server 

So go the services and start the Prometheus Server

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 15

start prometheus

Hit the URL in your web browser to check weather our target is successfully scraped by Prometheus or not

https://localhost:9090/targets
Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 16

prometheus target

#4. Configure Prometheus as Grafana DataSource

Once you logged into Grafana Now first Navigate to Settings Icon ->> Configuration ->> data sources

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 17

configuration

Now lets click on Add Data sources and select Prometheus

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 18

add data source

Now configure Prometheus data source by providing Prometheus URL

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 19

config

As per your requirement you can do other changes or you can also keep remaining configuration as default.

Now click on Save & test so it will prompt a message Data Source is working.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 20

data source is working

#5.Creating Grafana Dashboard to monitor Windows server

Now lets build a dashboard in Grafana so then it will able to reflect the metrics of the Windows system.

So we will use 14510 to import Grafana.com, Lets come to Grafana Home page and you can see a “+” icon. Click on that and select “Import”

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 21

import

On the next window, simply enter the dashboard ID in the corresponding field 

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 22

import for window

Now provide the name and select the Prometheus Datasource and click on Import.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 23

window exporter

There you are done with the setup. Now your Dashboard is running up!.

Install Prometheus and Grafana on Windows with WMI Exporter [4 Steps] 24

window dashboard

Conclusion:

In this article we have covered How Install Install Prometheus and Grafana on Windows with WMI Exporter, Configure Prometheus as Grafana DataSource.

Related Articles:

  • Install Prometheus and Grafana on Ubuntu 20.04 LTS
  • Kubernetes cluster Monitoring with Prometheus and Grafana.
  • How to Install Nagios Core on CentOS 7

Guys who are working as a DevOps engineer or a Site Reliability Engineer should aware of various techniques to monitor their Windows servers. If you are familiar with such tasks then you can easily solve your windows server down issues.

You may get some random doubts whenever your serves go down like Is it due to the high CPU usage on one of the processes? Is the RAM used too much on my Windows server? or Is the server having some memory issues?

To clarify all these queries today we have come up with a new interesting tutorial ie., Windows Server Monitoring using Prometheus and WMI Exporter.

If you are not having an overview of Prometheus Monitoring, check out this Definitive Guide by clicking on the link and start learning about the monitoring of windows servers with Prometheus and WMI Exporter.

Are you ready to monitor your Windows Servers? If yes, then go through these direct links for quick access to the main concept of this tutorial.

  • Windows Server Monitoring Architecture
  • Installing Prometheus
  • Installing the WMI Exporter
    • a – Downloading the WMI Exporter MSI
    • b – Running the WMI installer
    • c – Observing Windows Server metrics
    • d – Binding Prometheus to the WMI exporter
  • Building an Awesome Grafana Dashboard
    • a – Importing a Grafana dashboard
  • Raising alerts in Grafana on high CPU usage
    • a – Creating a Slack webhook
    • b – Set Slack as a Grafana notification channel
    • c – Building a PromQL query
    • d – Creating a Grafana alert

What is WMI Exporter?

WMI Exporter is an exporter utilized for windows servers to collects metrics like CPU usage, memory, and Disk usage.

It is open-source which can be installed on Windows servers using the .msi installer

Prerequisites

If you want to follow this tutorial, then you require the following stuff:

  • One Linux server set up
  • Prometheus 2.x installed on your server, including the Prometheus Web UI.
  • Check out your Prometheus version by running the Prometheus -version command. The output comprises your Prometheus version as well as build information.

Windows Server Monitoring Architecture

Before installing the WMI exporter, let’s have a quick look at what our final architecture looks like.

As a reminder, Prometheus is constantly scraping targets.

Targets are nodes that are exposing metrics on a given URL, accessible by Prometheus.

Such targets are equipped with “exporters”: exporters are binaries running on a target and responsible for getting and aggregating metrics about the host itself.

If you were to monitor a Linux system, you would run a “Node Exporter“, which would be responsible for gathering metrics about the CPU usage or the disk I/O currently in use.

  • MongoDB Monitoring with Grafana & Prometheus | Mongodb Prometheus Grafana Dashboard
  • How To Install Prometheus with Docker on Ubuntu 18.04
  • Complete Node Exporter Mastery with Prometheus | Monitoring Linux Host Metrics WITH THE NODE EXPORTER

For Windows hosts, you are going to use the WMI exporter.

The WMI exporter will run as a Windows service and it will be responsible for gathering metrics about your system.

In short, here is the final architecture that you are going to build.

windows-arch

Installing Prometheus

The complete Prometheus installation for Linux was already covered in one of our previous articles. Check out our Prometheus tutorials main page or else click on this direct link How To Install Prometheus with Docker on Ubuntu 18.04

Ensure to read it extensively to have your Prometheus instance up and running.

To verify it, head over to http://localhost:9090 (9090 being the default Prometheus port).

You should see a Web Interface similar to this one.

If this is the case, it means that your Prometheus installation was successful.

prometheus-homepage

Great!

Now that your Prometheus is running, let’s install the WMI exporter on your Windows Server.

Installing the WMI Exporter

The WMI exporter is an awesome exporter for Windows Servers.

It will export metrics such as CPU usage, memory, and disk I/O usage.

The WMI exporter can also be used to monitor IIS sites and applications, the network interfaces, the services, and even the local temperature!

If you want a complete look at everything that the WMI exporter offers, have a look at all the collectors available.

In order to install the WMI exporter, head over to the WMI releases page on GitHub.

a – Downloading the WMI Exporter MSI

As of August 2019, the latest version of the WMI exporter is 0.8.1.

wmi-exporter-v0.8.1

On the releases page, download the MSI file corresponding to your CPU architecture.

In my case, I am going to download the wmi_exporter-0.8.1-amd64.msi file.

b – Running the WMI installer

When the download is done, simply click on the MSI file and start running the installer.

This is what you should see on your screen.

wmi-exporter-msi

Windows should now start configuring your WMI exporter.

You should be prompted with a firewall exception. Make sure to accept it for the WMI exporter to run properly.

The MSI installation should exit without any confirmation box. However, the WMI exporter should now run as a Windows service on your host.

To verify it, head over to the Services panel of Windows (by typing Services in the Windows search menu).

In the Services panel, search for the “WMI exporter” entry in the list. Make sure that your service is running properly.

wmi-exporter-service

c – Observing Windows Server metrics

Now that your exporter is running, it should start exposing metrics on

Open your web browser and navigate to the WMI exporter URL. This is what you should see in your web browser.

Some metrics are very general and exported by all the exporters, but some of the metrics are very specific to your Windows host (like the wmi_cpu_core_frequency_mhz metric for example)

prom-metrics

Great!

Now, Windows Server monitoring is active using the WMI exporter.

If you remember correctly, Prometheus scrapes targets.

As a consequence, we have to configure our Windows Server as a Prometheus target.

This is done in the Prometheus configuration file.

d – Binding Prometheus to the WMI exporter

As you probably saw from your web browser request, the WMI exporter exports a lot of metrics.

As a consequence, there is a chance that the scrape request times out when trying to get the metrics.

This is why we are going to set a high scrape timeout in our configuration file.

If you want to keep a low scrape timeout, make sure to configure the WMI exporter to export fewer metrics (by specifying just a few collectors for example).

Head over to your configuration file (mine is located at /etc/prometheus/prometheus.yml) and edit the following changes to your file.

scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Careful, the scrape timeout has to be lower than the scrape interval.
    scrape_interval: 6s
    scrape_timeout: 5s
    static_configs:
            - targets: ['localhost:9090', 'localhost:9216']

Save your file, and restart your Prometheus service.

$ sudo systemctl restart prometheus
$ sudo systemctl status prometheus

Head back to the Prometheus UI, and select the “Targets” tab to make sure that Prometheus is correctly connected to the WMI exporter.

wmi-target

If you are getting the following error, “context deadline exceeded”, make sure that the scrape timeout is set in your configuration file.

Great! Our Windows Server monitoring is almost ready.

Now it is time for us to start building an awesome Grafana dashboard to monitor our Windows Server.

Building an Awesome Grafana Dashboard

Complete MySQL dashboard with Grafana & Prometheus and MongoDB Monitoring with Grafana & Prometheus are some of our previous guides on Prometheus & Grafana installation. Make sure to configure your Grafana properly before moving to the next section.

If you are looking to install Grafana on Windows, here is another guide for it.

Prometheus should be configured as a Grafana target and accessible through your reverse proxy.

a – Importing a Grafana dashboard

In Grafana, you can either create your own dashboards or you can use pre-existing ones that contributors already crafted for you.

In our case, we are going to use the Windows Node dashboard, accessible via the 2129 ID.

Head over to the main page of Grafana (located at http://localhost:3000 by default), and click on the Import option in the left menu.

In the next window, simply insert the dashboard ID in the corresponding text field.

import-dash-1

From there, Grafana should automatically detect your dashboard as the Windows Node dashboard. This is what you should see.

windows-node-dashboard

Select your Prometheus datasource in the “Prometheus” dropdown, and click on “Import” for the dashboard to be imported.

final-dashboard-2-1

Awesome!

An entire dashboard displaying Windows metrics was created for us in just one click.

As you can see, the dashboard is pretty exhaustive.

You can monitor the current CPU load, but also the number of threads created by the system, and even the number of system exceptions dispatched.

cpu-load

On the second line, you have access to metrics related to network monitoring. You can for example have a look at the number of packets sent versus the number of packets received by your network card.

It can be useful to track anomalies on your network, in case of TCP flood attacks on your servers for example.

network-1

On the third line, you have metrics related to the disk I/O usage on your computer.

Those metrics can be very useful when you are trying to debug applications (for example ASP.NET applications). Using those metrics, you can see if your application consumes too much memory or too much disk.

disk-io-1

Finally, one of the greatest panels has to be memory monitoring. RAM has a very big influence on the overall system performance.

Consequently, it has to be monitored properly, and this is exactly what the fourth line of the dashboard does.

memory-1

That’s an awesome dashboard, but what if we want to be alerted whenever the CPU usage is too high for example?

Wouldn’t it be useful for our DevOps teams to know about it in order to see what’s causing the outage on the machine?

This is what we are going to do in the next section.

Raising alerts in Grafana on high CPU usage

As discussed in the previous section, you want alerts to be raised when the CPU usage is too high.

Grafana is equipped with an alerting system, meaning that whenever a panel raises an alert it will propagate the alert to “notification channels“.

Notification channels are Slack, your internal mailing system of PagerDuty for example.

In this case, we are going to use Slack as it is a pretty common team productivity tool used in companies.

a – Creating a Slack webhook

For those who are not familiar with Slack, you can create webhooks that essentially address for external sources to reach Slack.

As a consequence, Grafana will post the alert to the Webhook address, and it will be displayed in your Slack channel.

To create a Slack webhook, head over to your Slack apps page.

slack-apps-1

Click on the name of your app (“devconnected” here). On the left menu, click on “Incoming Webhooks”.

On the next page, simply click on “Add New Webhook to Workspace“.

slack-apps-3

On the next screen, choose where you want your alert messages to be sent. In this case, I will choose the main channel of my Slack account.

slack-apps-4

Click on “Allow”. From there, your Slack Webhook URL should be created.

webhook-URL

b – Set Slack as a Grafana notification channel

Copy the Webhook URL and head over to the Notifications Channels window of Grafana. This option is located in the left menu.

Click on the option, and you should be redirected to the following window.

add-channel

Click on “Add channel”. You should be redirected to the notification channel configuration page.

Copy the following configuration, and change the webhook URL with the one you were provided with in the last step.

slack-config

When your configuration is done, simply click on “Send Test” to send a test notification to your Slack channel.

test-notif

Great! Your notification channel is working properly.

Let’s create a PromQL query to monitor our CPU usage.

c – Building a PromQL query

If you are not familiar with PromQL, there is a section dedicated to this language in my Prometheus monitoring tutorial.

When taking a look at our CPU usage panel, this is the PromQL query used to display the CPU graph.

promQL-1

First, the query splits the results by the mode (idle, user, interrupt, DPC, privileged). Then, the query computes the average CPU usage for a five minutes period, for every single mode.

In the end, the modes are displayed with aggregated sums.

In my case, my CPU has 8 cores, so the overall usage sums up to 8 in the graph.

If I want to be notified when my CPU usage peaks at 50%, you essentially want to trigger an alert when the idle state goes below 4 (as 4 cores are going to be fully used).

To monitor our CPU usage, we are going to use this query

sum by (mode) (rate(wmi_cpu_time_total{instance=~"localhost:9182", mode="idle"}[5m]))

I am not using a template variable here for the instance as they are not supported by Grafana for the moment.

This query is very similar to the one already implemented in the panel, but it specifies that we specifically want to target the “idle” mode of our CPU.

Replace the existing query with the query we just wrote.

This is what you should now have in your dashboard.

cpu-usage-2

Now that your query is all set, let’s build an alert for it.

d – Creating a Grafana alert

In order to create a Grafana alert, click on the bell icon located right under the query panel.

In the rule panel, you are going to configure the following alert.

Every 10 seconds, Grafana will check if the average CPU usage for the last 10 seconds was below 4 (i.e using more than 50% of our CPU).

If it is the case, an alert will be sent to Slack, otherwise, nothing happens.

rule-1

Finally, right below this rule panel, you are going to configure the Slack notification channel.

notifications-rule

Now let’s try to bump the CPU usage on our instance.

alertalert

As the CPU usage goes below the 4 thresholds, it should set the panel state to “Alerting” (or “Pending” if you specified a “For” option that is too long).

From there, you should receive an alert in Slack.

slack-alert

As you can see, there is even an indication of the CPU usage (73% in this case).

Great! Now our DevOps is aware that there is an issue on this server and they can investigate what’s happening exactly.

Conclusion

As you can see, monitoring Windows servers can easily be done using Prometheus and Grafana.

With this tutorial, you had a quick overview of what’s possible with the WMI exporter. So what’s next?

From there, you can create your own visualizations, your own dashboards, and your own alerts.

Our monitoring section contains a lot of examples of what’s possible and you can definitely take some inspiration from some of the dashboards.

Until then, have fun, as always.

Уровень сложностиПростой

Время на прочтение3 мин

Количество просмотров9.9K

Авторы: Никита Зубарев — DevOps Team Leader компании Hostkey, Айрат Сягитов — специалист отдела DevOps компании Hostkey 

Ранее мы рассказали о том, как выполняется мониторинг Linux-систем. Теперь рассмотрим, как настроить Windows Server.

В одной из прошлых статей мы говорили об интеграции FreeIPA с Active Directory. В процессе разработки решения, описанного в этой статье, у нас возникла потребность снимать метрики с серверов Windows-инфраструктуры. В данной статье мы рассмотрим, как можно наладить мониторинг для серверов с ОС Windows, используя существующую систему, построенную на связке Prometheus + Grafana + Alertmanager. Собирать будем общие системные метрики: cpu, ram, hdd. 

Экспортер WMI также можно использовать для мониторинга сайтов и приложений IIS, сетевых интерфейсов, служб и даже локальной температуры.

Установка Windows Exporter для мониторинга служб Windows

Для установки Windows Exporter необходимо выполнить несколько действий:

  1. Скачать последнюю версию Windows Exporter с GitHub, выбрав архив .zip или .tar.gz.

  2. Создать папку с именем «Prometheus» на диске C или в другом месте. 

  3. Распаковать скачанный архив Windows Exporter. В нем находится файл windows_exporter.exe.

  4. Скопировать windows_exporter.exe в папку “Prometheus”.

Затем необходимо создать конфигурационный файл YAML для Windows Exporter. Он позволит указать службы, которые необходимо поставить на мониторинг.

В нашем примере это сервис LicenseManager.

Windows Exporter можно запустить двумя способами: вручную и в качестве службы Windows.

1. Для запуска вручную необходимо:

  • Открыть командную строку от имени администратора.

  • Перейти в папку с windows_exporter.exe, например: cd C:\Prometheus.

  • Запустить Windows Exporter с указанием конфигурационного файла с помощью команды: .\windows_exporter.exe —config.windowsconfig=»kms.yml».

  • Теперь Windows Exporter будет работать в режиме мониторинга в текущей сессии.

2. Для настройки как службы Windows необходимо:

  • Открыть командную строку от имени администратора.

  • Создать службу Windows Exporter командой:

 sc create WindowsExporter binPath= "C:\Prometheus\windows_exporter.exe --config.windowsconfig=C:\Prometheus\kms.yml" start= auto.
  • Запустить службу командой sc start WindowsExporter:

A:\Windows\system32>sc create WindowsExporter binpath= "C:\Prometheus\windows_exporter.exe --config.windowsconfig=C:\Prometheus\windows_exporter.yml"=auto
[SC] CreateService: success

A:\Windows\system32>sc start WindowsExporter

Подробную информацию о средстве экспорта WMI можно посмотреть на GitHub.

После установки необходимого экспортера следует перейти в панель «Службы Windows» (достаточно просто ввести «Службы» в меню поиска Windows) и найти в списке запись WMI exporter. Далее необходимо проверить, что сервис работает правильно.

Если экспортер запущен, он должен начать предоставлять метрики на http://localhost:9182/metrics, по аналогии с Node Exporter. Остается подключить сбор метрик в Prometheus, добавить дашборд и настроить алертинг:

Добавить в prometheus.yml:

  - job_name: 'Windows_Infra'
    static_configs:
      - targets: ['”localhost”:9182'] 

Добавить Grafana dashboard, который отслеживает отображение информационной панели, подключает и оптимизирует вывод подробной сводки ресурсов. В результате получаем визуальную панель по каждому хосту:

Осталось описать rule_files, добавив необходимые метрики:

groups:
- name: Windows_Infra
  rules:
  - alert: InstanceDown
    expr: up{job="Windows_Infra"} == 0
    for: 5m
    labels:
      severity: page
    annotations:
      summary: "Instance {{ .instance }} down"
      description: "{{ .instance }} of job {{ .job }} has been down for more than 5 minutes."

  - alert: DiskSpaceUsage
    expr: 100.0 - 100 * (windows_logical_disk_free_bytes{job="Windows_Infra"} / windows_logical_disk_size_bytes{job="Windows_Infra"}) > 90
    for: 10m
    labels:
      severity: high
    annotations:
      summary: "Disk Space Usage (instance {{ $labels.instance }})"
      description: "Disk Space on Drive is used more than 90%\n  VALUE = {{ $value }}\n  LABELS: {{ $labels }}"

Аналогичным образом добавляем другие необходимые параметры. При настроенном Alertmanager сообщения нотификаций автоматически будут приходить в подключенные системы.

Как видите, мониторинг серверов Windows можно легко выполнить с помощью Prometheus и Grafana. Это решение значительно упрощает процесс управления большим парком машин и позволяет оперативно решать проблемы, возникающие при администрировании серверного оборудования в нашей компании.В следующих статьях рассмотрим задачу подключения служб Windows.


Арендуйте выделенные и виртуальные серверы с моментальным деплоем в надежных дата-центрах класса TIER III в Москве и Нидерландах. Принимаем оплату за услуги HOSTKEY в Нидерландах в рублях на счет российской компании. Оплата с помощью банковских карт, в том числе и картой МИР, банковского перевода и электронных денег.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как установить neovim на windows
  • Imac установка windows на внешний диск
  • Windows 10 драйверы устройства не найдены проверьте что на установочном носителе
  • Dolby vision player windows 10
  • Intel 82574l driver windows 2008