WMI tutorial - data source
To enable your extension to collect metrics and have those metrics ingested into Dynatrace, you must define a data source. In this tutorial we're using the WMI data source. This must be a section called wmi
in your extension.
The purpose of the wmi
section is to define the WMI queries that retrieve your metrics, how often they should run, and how to map their results to metrics and dimensions that Dynatrace can ingest. Groups and subgroups are used to organize data and define shared properties like dimensions and running frequency.
For our extension, we're using 3 WMI Queries. We'll add them to our extension.yaml
and ingest their result as Dynatrace metrics:
-
Extract CPU Usage, User CPU, and Idle CPU for each of the host's processors (split by CPU ID).
1SELECT Name, PercentProcessorTime, PercentIdleTime, PercentUserTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name LIKE '_Total' -
Extract the Total, Sent, and Received Bytes per second for each network adapter running on the host
1SELECT Name, BytesTotalPersec, BytesReceivedPersec, BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkAdapter -
Extract the Total, Sent, and Received Bytes per second for each network interface running on the host
1SELECT Name, BytesTotalPersec, BytesReceivedPersec, BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface
Tips
Metric best practices
Prefix your metric keys with the name of the extension to avoid clashes with other metrics in Dynatrace. For this exercise, we prefix each metric key with custom.demo.host-observability
.
Host dimension
You can identify the host running the extension through the this:device.host
passed as a dimension value.
Static dimensions
You can add dimensions that are fixed strings using the prefix const:
.
Define your data source
Add the wmi
section to your extension.yaml
using the template below.
- Create two groups called
Host
andNetwork
that run every 1 min. Both groups should have a dimension that identifies the host running the extension. Create a subgroup for each WMI query given above and map the columns retrieved to metrics and dimensions.
- Add a dimension called
network.type
that takes the valueAdapter
orInterface
, depending on the WMI query. Package a new version of your extension and upload it.
Configure it to monitor your Windows host. You can do it during extension activation in Dynatrace Hub.
Give it a minute, and then validate metric collection.
For more information on the WMI data source syntax, see WMI data source reference.
1wmi:2 - group: Host3 interval:4 minutes: 15 dimensions:6 - key: host7 value: this:device.host8 subgroups:9 - subgroup: CPU10 query: SELECT Name, PercentProcessorTime, PercentIdleTime, PercentUserTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name LIKE '_Total'11 metrics:12 - key: custom.demo.host-observability.host.cpu.time.processor13 value: column:PercentProcessorTime14 - key: custom.demo.host-observability.host.cpu.time.idle15 value: column:PercentIdleTime16 - key: custom.demo.host-observability.host.cpu.time.user17 value: column:PercentUserTime18 dimensions:19 - key: host.cpu.id20 value: column:Name21 - group: Network22 interval:23 minutes: 124 dimensions:25 - key: host26 value: this:device.host27 subgroups:28 - subgroup: Adapters29 query: SELECT Name, BytesTotalPersec, BytesReceivedPersec, BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkAdapter30 metrics:31 - key: custom.demo.host-observability.network.bytes.persec32 value: column:BytesTotalPersec33 - key: custom.demo.host-observability.network.bytes.received.persec34 value: column:BytesReceivedPersec35 - key: custom.demo.host-observability.network.bytes.sent.persec36 value: column:BytesSentPersec37 dimensions:38 - key: network.type39 value: const:Adapter40 - key: network.name41 value: column:Name42 - subgroup: Interfaces43 query: SELECT Name, BytesTotalPersec, BytesReceivedPersec, BytesSentPersec FROM Win32_PerfFormattedData_Tcpip_NetworkInterface44 metrics:45 - key: custom.demo.host-observability.network.bytes.persec46 value: column:BytesTotalPersec47 - key: custom.demo.host-observability.network.bytes.received.persec48 value: column:BytesReceivedPersec49 - key: custom.demo.host-observability.network.bytes.sent.persec50 value: column:BytesSentPersec51 dimensions:52 - key: network.type53 value: const:Interface54 - key: network.name55 value: column:Name
Results
Your six metrics should show up in the Metrics browser. To find them, filter by text custom.demo
.
Next step: Metric metadata