神刀安全网

Exploring Performance Counters with F# WMI Type Provider

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.

Exploring Performance Counters with F# WMI Type Provider

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

FSI runs by default in 32 bits in Visual Studio. It can be configured to run in 64 bits by selecting the option in Tools/Options/F# Tools as a simple way to connect to the 64 bits WMI provider. Applications targeting .Net 4.5.* also compile to 32 bits by default in Visual Studio. Making the application compile to 64 bits 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.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Exploring Performance Counters with F# WMI Type Provider

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址