Monitoring Windows Performance Counters

Last Updated On September 18, 2018
You are here:

Prerequisites

Sonar v0.1.8 or higher

Scenarios

The following monitoring scenarios should be considered:

  • Modernized Windows applications on Docker or Kubernetes.
  • Traditional Windows applications on virtual machine or host.

These scenarios are useful for monitoring life and safety metrics for your applications using telemetry which cannot be collected by Docker or Kubernetes.

Benefits and Liabilities

The following benefits and liabilities should be considered before monitoring performance counters with Sonar:

Benefits

  • Minimal performance impact – reading counters is the most efficient technique for collecting Windows metrics and detecting issues with near zero CPU cost.
  • Portability across Windows platform – the metric collection uses Windows performance data helper (PDH) library that is part of Windows OS, including Nano Server container images.
  • Cloud-native collection – Sonar supports exposing collected metrics to Prometheus or InfluxDb (via UDP).
  • Deployment symmetry – ¬†Sonar agent can be deployed as Windows service on container (including NanoServer with process isolation) or target host.
  • Using either Prometheus Alert Manager or InfluxData TICK stack enables anomaly detection and machine learning for collected metrics.

Liabilities

  • Prometheus or InfluxDb are required for storing metrics collected by Sonar.
  • Sonar deployment in container requires configuring path to list of counters that should be scraped on periodic intervals.
  • Only local performance counters defined in Windows container or host OS can be collected.

Steps

Configure Input Adapter

The below configuration shows how to register performance counter input adapter:

Sonar.config
<connectionStrings>
<add name=”perfmon” providerName=”mspdh” connectionString=”Server=myserver;”/>
</connectionStrings>

Configure Output Adapter

This step is required only collected metrics should be sent to InfluxDb time series database. To complete this step, add adapter configuration definition as shown below:

Sonar.config
<add name=”influxdb” connectionString=”Data Source = udp://10.0.0.177:8092;Initial Catalog=sonar;User Id =; Password =; Application Name = default;Max Pool Size=100;Packet Size=4094;Connection Timeout=10″/>

Define Metrics Query

Below is an example of query to collect all counters associated with Windows process:

Sonar.config
<add name=”Perfmon_Process” type=”raw” filter=”*”resource=”.” namespace=”Process”>
<Tags>
<add name=”name” value = “name”/>
</Tags>
<Values>
<add name=”processor_time” value=”% Processor Time”/>
<add name=”user_time” value=”% User Time”/>
<add name=”handle_count” value=”Handle Count”/>
<add name=”private_bytes” value=”Private Bytes”/>
<add name=”working_set” value=”Working Set”/>
<add name=”thread_count” value=”Thread Count”/>
</Values>
</add>
Note that tag mapping to value “name” is required to gather name of the process or key associated multi-instance counter.
Below is example of definition for single instance counter:
Sonar.config
<add name=”Perfmon_Memory” type=”raw” filter=””
resource=”.”namespace=”Memory”>
<Tags>
<add name=”name” value = “name”/>
</Tags>
<Values>
<add name=”available_bytes” value=”Available Bytes”/>
<add name=”committed_bytes” value=”Committed Bytes”/>
</Values>
</add>
As you can see, the value of filter attribute is empty due the fact that unlike process counter, this one only has single instance.

Create Schedule

The below example configures Sonar to execute the above query every 10 seconds and expose collected metrics to Prometheus:
Sonar.config
<Schedules>
<add name=”s01″query=”Perfmon_Process” input=”perfmon” intervalSeconds=”10″/>
</Schedules>
The below example shows how to use the same schedule to send output to InfluxDb:
Sonar.config
<Schedules>
<add name=”s01″ query=”Perfmon_Process” input=”perfmon” intervalSeconds=”10″ output=”influxdb”/>
</Schedules>
The name of output adapter is defined in connection strings section shown above.

Deploy Sonar

After Sonar is deployed on Nano Server container, Windows virtual machine or host, the above metrics will become available in Prometheus or InfluxDb. The below example shows metrics from performance counters described above from Windows Nano Server container (in-process isolation) in Grafana dashboard:

The bottom graph shows scrape performance in milliseconds for metric collection. In addition, the processor tie chart indicates that Sonar daemon (Sonard) consumes near zero CPU resources.

Tags: