---
isPrivate: true
title: Collect Custom Windows Performance Counters over WMI
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Integrations > FAQ Integrations > Collect Custom Windows Performance
  Counters over WMI
---

# Collect Custom Windows Performance Counters over WMI

{% callout %}
# Important note for users on the following Datadog sites: us2.ddog-gov.com

{% alert level="info" %}
To find out if this integration is available in your organization, see your [Datadog Integrations](https://app.datadoghq.com/integrations) page or ask your organization administrator.

To initiate an exception request to enable this integration for your organization, email [support@ddog-gov.com](mailto:support@ddog-gov.com).
{% /alert %}

{% /callout %}

Datadog's WMI integration is a versatile approach to collecting relevant metrics from your Windows environments. As long as you're able to query a WMI object for a numerical value, you can configure your dd-agent's WMI check to run the same query and collect its results as a metric. See the [retrieving WMI metrics](https://docs.datadoghq.com/integrations/guide/retrieving-wmi-metrics.md) guide.

But sometimes the default WMI counters aren't sufficient for specific use-cases –in those cases, you can create your own custom WMI counters for the `dd-agent` to query. Here's a simple example of a powershell script that would create a custom WMI counter:

```powershell
$ccdTypeName ='System.Diagnostics.CounterCreationData'
$CounterCollection = New-Object System.Diagnostics.CounterCreationDataCollection
$perfCounterVersion = 2
$perfCounterCategoryName = 'TestCounterCategory'
$CounterCollection.Add((New-Object $ccdTypeName "TestNameType", "TestNameDescription", NumberOfItems32))
[System.Diagnostics.PerformanceCounterCategory]::Create($perfCounterCategoryName, $perfCounterVersion, [Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $CounterCollection);
```

That script will create a new performance counter, which will be available for querying once you re-sync your WMI counters thus:

`winmgmt /resyncperf`

You can verify that the new counter is available by querying it from powershell like so:

```powershell
PS C:\Users\estib> Get-WmiObject -List | where {$_.name -match "TestCounterCategory"} | select Name
```

Which ought to output something like the following:

```text
Name
----
Win32_PerfFormattedData_TestCounterCategory_TestCounterCategory
Win32_PerfRawData_TestCounterCategory_TestCounterCategory
```

You can further identify what numerical properties you have available to query from your custom counter with a query like the following:

```text
PS C:\Users\estib> Get-WmiObject -Query "select * from Win32_PerfFormattedData_TestCounterCategory_TestCounterCategory"
...
TestNameType       : 0
...
```

If then I wanted to collect that "TestNameType" value as a metric called "wmi.testnametype.count", I could add this to my wmi_check.yaml configuration:

```yaml
instances:
  - class: Win32_PerfFormattedData_TestCounterCategory_TestCounterCategory
    metrics:
      - [TestNameType, wmi.testnametype.count, gauge]
```

**Note**: If you are submitting performance counters in languages other than English, set up the ddagentuser account with the en-US language pack.
