Instant Monitoring of Windows Performance

Here’s an example similar to my other Blog post Instant Monitoring of Windows Services. Instead, this blog demonstrates monitoring Performance Counters and using alerts to fire off a scheduled task. This scheduled task fires off a PowerShell script which in turn fires off an Azure Function, which in turn fires off an SMS text message and records an entry in a Log Analytics custom log. All this happens sequentially in the space of about 5 seconds.

This blog demonstrates monitoring these 3 basic performance counters:

  • Processor(_Total)\% Processor Time
  • Memory\% Committed Bytes In Use
  • LogicalDisk(C:)\% Free Space
2018-08-26_1037

You could monitor more counters, another blog post later will let you know how you can do this.

Components

Here are the components of this solution, bearing in mind all this is set up fully automatically on each client by using the script below.

  • Performance Counters

    2018-08-26_1139

  • Scheduled Task 2018-08-26_1140
    -ExecutionPolicy Unrestricted -File C:\Windows\System32\PerfmonDrivenTask.ps1 $(Arg0)
  • PowerShell script | Takes the Arguments from the Perfmon Alert and uses this to construct the message to be sent as an SMS and send to the Log Analytics custom log.
    # Message to send and add to the Log Analytics Custom Log
    $Message = ('{1}{0}{2}{0}{3}{0}{4}' -f " ", $Args[0], $Args[1], $Args[2], $env:computername) -replace '/', '-'

Backend Setup (Manual)

The backend is set up once only. As per my other blog, setup the Azure Function, Log Analytics Workspace & Telstra DEV account.

Once you have the Azure Function, Log Analytics Workspace & Telstra DEV account setup, The script at the very bottom sets up everything on the client automatically.

Client Setup (Automated)

Once the backend is set up, the Script further below fully automates the setup of each client. Good thing is, you can run this over and over again, it will only make sure everything is set in place again.

  1. Run PowerShell ISE as administrator if running this on the actual machine
  2. Within the top 33 lines, change the variables to suite your setup:
    1. $LogAnalyticsCustomerID – Obtain workspace ID and key
    2. $LogAnalyticsPrimaryKey – Obtain workspace ID and key
    3. $Telstra_app_key – From https://dev.telstra.com/
    4. $Telstra_app_secret – From https://dev.telstra.com/
    5. $tel_numbers – One or many mobile numbers to send the SMS to
    6. $FunctionUri – Your own Azure Functions URI
  3. To run this remotely, you could run this using Remote PowerShell.
  4. You could set this up using Group Policy

Testing

If you want to test that this is working, it’s pretty easy, use this tool to put strain on the CPU & Memory.

Azure PowerShell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: