This utility has many overlooked abilities, one of them being the ability to alert on various metric conditions.

What is Perfmon?

The default view upon launching highlights a few different areas and real-time metrics.

iPhone 16e with iPhone 16 Plus and iPhone 16 Pro in hand against grey wall.

you could add additional metrics to this graph, by clicking on the green plus and adding more metrics.

Data Collector Sets

Real-time data is useful, but not what we are ultimately looking for.

How then do we alert on certain conditions, in this case, high CPU usage sustained over time?

An Excel table with a named range.

This is where Data Collector Sets come in.

After expanding Data Collector Sets, right-click onUser Defined New Data Collector Set.

In this case, we need to manually create our configuration.

Article image

In this case, we are setting up aPerformance Counter Alert.

This will monitor a given counter and then we can tell the alert to take certain actions.

Here we are choosingProcessor _Totalby clicking on “Add »” next to the selected instance.

Article image

One problem is that you get all of theProcessor _Totalmetrics.

Ultimately, we just want the

metric.

To remove the others, select each one and press the Remove button.

Article image

Select each metric individually and punch Remove.

Finally, save and terminate the Data Collector Set.

There are two ways to set the alerts, Alert Action and Alert Task.

Article image

Select yourUser Defined High CPU Usagedata collector set, right-tap on the defaultDataCollector01entry and choose Properties.

This way you’re free to collect additional logging as needed.

Here though, we are just going to log an entry.

Article image

To make this work, we need to do two things.

Create the script to run and the scheduled task itself.

Logging Script

Below is a very simple logging script.

Article image

We read in the alert metrics outputted by the Alert Task and send those results to a log file.

Until PowerShell 7 is formally released, the executable may bepwsh-preview.exe.

Configuring Alert Task

Finally, we need to configure the Alert Task on the Data Collector.

Article image

To do this navigate to the properties again ofDataCollector01and enter in the following details.

We quote the task arguments because they come in as strings to PowerShell.

Article image

Article image

Article image

Article image

Article image

Article image