Skip to content

Instantly share code, notes, and snippets.

@nzbart
Last active February 8, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nzbart/10947546 to your computer and use it in GitHub Desktop.
Save nzbart/10947546 to your computer and use it in GitHub Desktop.
Starts logging performance metrics on Windows using perfmon logging (logman).
<#
Starts logging performance metrics on Windows using perfmon logging (logman).
A variety of metrics are collected to assist with diagnosing a performance bottleneck.
The metrics are logged to %systemdrive%\PerfLogs\Admin on a clean Windows install.
The script must be run with administrative credentials.
This script is intended for interactive execution. If you want to run it within an automated process, you'll need to check the exit code of logman.exe. The stop / delete steps are expected to fail if the job does not already exist.
I use the .blg file format to capture data because it can capture new processes that start during the capture. Because it is not possible to add new columns to the .csv, new processes that launch during the logging period cannot be added when logging to .csv.
The .blg file can be opened in Windows Performance Monitor (perfmon).
The perfmon .blg file can be converted into a .csv file by the following:
relog <file>.blg -f csv -o <file>.csv
#>
$metrics =
"\PhysicalDisk(*)\Avg. Disk Write Queue Length",
"\PhysicalDisk(*)\Avg. Disk Read Queue Length",
"\PhysicalDisk(*)\Avg. Disk sec/Write",
"\PhysicalDisk(*)\Avg. Disk sec/Read",
"\PhysicalDisk(*)\% Idle Time",
"\PhysicalDisk(*)\Disk Read Bytes/sec",
"\PhysicalDisk(*)\Disk Write Bytes/sec",
"\Memory\Page Faults/sec",
"\Network Interface(*)\Output Queue Length",
"\Process(*)\% Processor Time",
"\Process(*)\Page Faults/sec",
"\System\Processor Queue Length"
#Choose one of these triggers - time span or instantaneous capture
$timeSpan = '-b', '2014-04-18 00:00:00', '-e', '2014-04-18 03:00:00'
$timeSpan = '-rf', '30'
$logName = 'metrics'
logman stop $logName
logman delete $logName
logman create counter $logName -c $metrics -si 05 -max 500 $timeSpan
logman start $logName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment