Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Exploring Performance Counters with F# WMI Type Provider

Exploring Performance Counters with F# WMI Type Provider

This item in japanese

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