Exploring Performance Counters with F# WMI Type Provider

| by Pierre-Luc Maheu Follow 4 Followers on Jun 08, 2016. Estimated reading time: 1 minute |

Windows Management Instrumentation (WMI) is a primary source of data when monitoring Windows systems. Given that the performance counters available vary from machine to machine, a tool is needed to list all counters available. The WMI type provider is one possible option to explore WMI performance counters.

With FSI, WMI can be queried directly from the IDE. The following query outputs memory and garbage collection metrics for IIS worker process instances:

type Local = WmiProvider<"localhost">
let data = Local.GetDataContext()

[for d in data.Win32_PerfFormattedData_NETFramework_NETCLRMemory -> 
    d.Name, d.Gen0heapsize, d.PercentTimeinGC]
    |> Seq.find (fun proc -> proc.Name.Contains("w3wp") )

WMI metrics can be used through a variety of applications: data collectors, Powershell scripts or in .Net code. Off the shelves monitoring tools often provide integration to WMI performance counters. The exact name of the counter and metric are required in order to configure the tool to monitor them. The WMI type provider creates objects with the exact names, meaning they can be copy-pasted directly from the IDE to the monitoring tool or Powershell script.


Some additional configuration may be required when working on a 64 bit operating system. A 32 bits process running on a 64 bit system would be serviced by the 32 bit WMI provider when requesting data. This would lead to missing data as the 32 bit provider will only return data collected from 32 bit processes.

FSI runs by default in 32 bit in Visual Studio. It can be configured to run in 64 bit by selecting the option in Tools/Options/F# Tools as a simple way to connect to the 64 bit WMI provider. Applications targeting .Net 4.5.* also compile to 32 bit by default in Visual Studio. Making the application compile to 64 bit is done by setting the prefer32bits attribute to false in the MsBuild target.

The WMI type provider is a part of FSharp.Management, an open source project available on Github. The project also includes other type providers: file system, registry, Powershell and timezones.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you