Automate creation of Performance Monitor Data Collector on an EC2 instance or a WorkSpace

Do you sometimes notice high CPU or memory usage on your EC2 instances or WorkSpaces? Do you know what’s causing it? For how long and how frequently?

It’s easy to find a rogue process in Task Manager and stop it, but is it a part of the pattern?

Enter a century-old tool -> Performance Monitor.

Sometimes, the rogue process is an application or a service which spikes at random times for random intervals. In such cases, we need to set up a Data Collector in the Performance Monitor and use it to track resource usage over a period of time. Logs are then replayed and root cause identified.

However, not everyone is tech-savvy enough to be able to create a Data Collector on their own. With enough persistence, they’d do it, but if we can help them help themselves, all the better.

To avoid errors during the data collection and make life easier on the person affected by the system issues we can provide them with the PowerShell one-liner code which will automate the creation of the full Data Collector. Furthermore, after helping them create a full dump of the system resource usage, and teaching them how to read it, they stand a better chance to find the root cause on their own.

Everybody wins.

When executed from the elevated (Run as Administrator) PowerShell console, this command will download the XML template for Data Collector, create it and set to run automatically:

The new collector will be named “CustomPerformance” and will automatically start collecting data. Two files are created per day, and logs older than 14 days are removed, for safety – if we or they forget that the log collection is running. But we never forget, do we? 🙂

During the time when the Performance Monitor is running, simply use your instance or a WorkSpace as you normally would. This will provide a good sample of a real working conditions.

To access the Performance Log Files, navigate to the folder:
C:\PerfLogs\System\Performance\CustomPerformance\.
The date of the log file is in the sub-folder name.

All performance metrics collected are graphed during the application’s initial startup. To interpret the data, start Performance Monitor (perfmon.msc), remove all the metrics and start from scratch. Select any of the counters listed below the line chart -> Press Ctrl+A to select all -> Press the Delete key or the red X in the toolbar.

To begin adding performance metrics to the graph, select the green plus sign in the toolbar. To examine which processes are consuming CPU resources drill down from Process -> % Processor Time -> -> Add -> OK

Performance monitor will graph the % Processor Time used by all processes running on the instance so that CPU hogging applications can be quickly identified. Additional performance metrics can be layered on top of the current view such as disk write operations per second.

Refer to this webpage for a complete list of counters definitions: https://technet.microsoft.com/en-us/library/cc768048.aspx

Get the code (and any future updates) from GitHub: https://github.com/PowerSix/MyPowerShellSpace

As usual, if the script is updated, the blog post won’t be.
Always check the GitHub repo for the latest version.

Leave a Comment