Facilitating the spread of knowledge and innovation in professional software development



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


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.

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

Community comments

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

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


Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.