Custom Script Monitor: CPU Hardware Temperature Monitor

Greetings!

I wanted to share this custom script monitor in case it is useful to others. It helps fill a highly needed temperature monitoring feature that I’ve been wanting to leverage through ITSM for a while. Scripts that pull temperature data from Windows performance monitoring are notoriously unreliable and inaccurate. This uses Open Hardware Monitor which is much more accurate and compatible with more hardware.

This is an early version I put together quickly but if there is interest I can share any future versions that include more features/abilities. Anyone can use and/or edit this to their liking.

Thanks!

Get-OpenHardwareMonitorTemps
Version: 0.3

SYNOPSIS
Powershell Script that polls and retrieves current temperature sensor values for CPU hardware via openhardwaremonitor

Requirements

  • Powershell v3.0 or higher
  • Windows 10, Server 2016/2019. May work on other versions as long as powershell v3 or higher is installed, however no other OS’s have been tested.
  • Target machine must have internet access
  • Installed Automatically by this script - PSHardwareMonitor Powershell Module: https://www.powershellgallery.com/pa…rdwareMonitor/ (contains openhardwaremonitor files)
  • Primarily designed for use with Windows PC and Server hardware. CPU temp detection not guaranteed for all hardware. Generally, if CPU is intel or AMD it should work

Full Description

One of the more challenging metrics to monitor consistently in PC hardware via RMM systems is hardware temperature. Unless the RMM tool software agent has the feature built-in, usually this requires third-party software, or specific manual setup for each machine/server. This is due to the range of different hardware or vendor specific requirements to access temperature sensors. While windows performance monitoring technically has the ability to report temperature, this is usually not usable as the data windows collects may not be accurate depending on hardware.
To solve this problem and make monitoring of temperature sensors easily possible across most hardware, this script leverages the opensource project Open Hardware Monitor.

Features:

  • ITarian Custom Script Monitor: This version is designed to work with the ITarian RMM system, where the script will be wrapped in and executed through their python procedures and monitors. When an alert temperature threshold value is configured, the script will output alert(1) when triggered or alert(0) if not triggered. If the script is run as a custom script monitor within ITSM, and the alert threshold is triggered, this will raise an alert within ITSM.
  • ITarian Procedure: This script can also be run as a normal procedure manually against a single or multiple endpoints. The output of CPU temperature values will be included in the procedures execution log
Output:

The output included with the ITSM alert trigger email will contain the following runtime data:

  • CPU Detected Temperature (the CPU Package sensor is the value the alert threshold is compared against. This sensor encompasses the highest temp of all CPU components)
  • CPU Make/Model/Name
  • CPU Load %
  • CPU Temperatures for each physical CPU installed and each CPU core.
  • CPU Clock Speeds for each physical CPU installed and each CPU core
  • Optional: A list of each currently running process with details. This can be useful to identify if there is a process that is heavily using system resources and thus could be a contributing cause to increased CPU heat and usage. Details about each process include:
    • Process Name
    • Process Description
    • Process ID
    • Process UNC Path
    • Process Priority
    • CPU Usage Percent Time
    • RAM Used
  • Optional: GPU Make/Model, GPU Temp, and GPU Load. When enabled this only works with dedicated NVidia or AMD GPU's. Will typically not work for integrated GPUs. This can be useful for CAD or design workstations that use dedicated GPUs
Note: output data will also show within the execution log of the custom script monitor

Configurable Variables
These are configuration variables within the script along with a description of what they do and example value. Within ITSM, these variables are configured using ITSM parameters to avoid the need to edit the code directly

  • CPUAlertTemp- The CPU temperature value in Celsius that the script will use to trigger an alert if detected temp value is greater or equal to
    • Example/Default Value: 80
  • RunningProcessReport- $True | $False - Retrieves a list of currently running processes with resource usage details to include in the alert output. NOTE: This is a full detailed list of all processes and will add a lot of text to the alert output
    • Example/Default Value: $False
  • EnabledGPU- $True | $False - Retrieves temperature and load values for dedicated NVIDA or AMD GPU cards if present. Will not work for iGPU's (integrated)
    • Example/Default Value: $False
Planned Features for future versions:
  • Email Report: Configurable HTML formatted report sent via email on alert trigger that contains all output metrics, with HTML sortable tables, pdf/csv/print export options and more
  • GPU Temp Alert Monitoring: Adds ability to configure a GPU alert temp threshold to trigger an alert
  • Power Consumption: Adds CPU power consumption (watts) to output data at runtime
  • FAN Sensors: Add FAN sensor data to output. This may not be possible given limited fan controller and sensor compatibility
Credits PSHardwareMonitor - https://www.powershellgallery.com/packages/PSHardwareMonitor/ Write-Color - https://github.com/EvotecIT/PSWriteColor

NOTES
Author: EZTechhelp

IMPORTANT
Upon first time execution of this script, the script will not return CPU sensor data. Upon second run of the script, it will work as expected. If your using this for monitoring, this should not be an issue as the script will continuously run every x minutes (whatever you configure), with only the very first run not returning data. This has to do with install of the openhardwaremonitor powershell module on first run. This may be fixed in the future but currently it does not hinder usage for monitoring.

How to Install

  • Download the ITSM procedure:
  • Within your ITSM portal, import the procedure under Configuration Templates - Procedures
  • Create a new ITSM Monitor under Configuration Templates - Monitors
    • Enter a name for the monitor (ex: Temperature Monitor)
    • Make sure OS is set to Windows
    • Optional: Enter a description and pick ITSM folder to create in
    • Click Create
  • On General page, configure alert settings that fit your organization
  • On Conditions tab, Click Add Condition - Custom Script
    • Enter a name for the custom script (ex: get-temperature)
    • Configure check period (ex: 15 mins - but configure to your requirements. script is not resource intensive to run but every 5 min might be excessive)
    • Optional: Enable Trigger monitoring alert if custom script failed (personally recommend)
    • Click Add Existing Procedure -find the name of the procedure you imported in Step 2 above, then click Add
    • On the custom script parameters page that comes up, configure CPUAlertTemp, RunningProcessReport, and EnableGPU to meet your requirements. See Configurable Variables above for explanation on meaning and values
    • Click Save
  • Click Save to finish
  • Assign the new Monitor to a profile (or create a new one) that is applied to the machine(s) you wish to monitor
Example ITSM Alert Email
 <ul>Monitor "Temperature Monitor" has been executed on device TESTDEVICE

Event Created at: Fri Feb 26 11:14:36 AM UTC 2021
Device Name: TESTDEVICE
Logged on User: TestUser
Data: Custom Script Monitor : Standard Output: Get CPU Temperatures
!!Detected CPU Temperature higher than alert threshold!!
Please Set the Mesurement Components with Set-HWMeasuremetComponents, Default are CPU:Enabled, GPU:Disabled

##### Detected CPU - alert(1) #####
...Temperature: 80
...Alert threshold: 80
...Current CPU Load: 70.1087

##### CPU Temps: Intel Core i7-9700K #####


CPU Core : CPU Package
Current Temperature : 73
Minimum Observed : 70
Maximum Observed : 73

CPU Core : CPU Core #1
Current Temperature : 64
Minimum Observed : 64
Maximum Observed : 73

CPU Core : CPU Core #2
Current Temperature : 80
Minimum Observed : 64
Maximum Observed : 80

CPU Core : CPU Core #3
Current Temperature : 68
Minimum Observed : 68
Maximum Observed : 71

CPU Core : CPU Core #4
Current Temperature : 67
Minimum Observed : 64
Maximum Observed : 67

CPU Core : CPU Core #5
Current Temperature : 66
Minimum Observed : 64
Maximum Observed : 66

CPU Core : CPU Core #6
Current Temperature : 64
Minimum Observed : 62
Maximum Observed : 64

CPU Core : CPU Core #7
Current Temperature : 68
Minimum Observed : 68
Maximum Observed : 70

CPU Core : CPU Core #8
Current Temperature : 80
Minimum Observed : 73
Maximum Observed : 80


##### CPU Clocks: Intel Core i7-9700K #####

Sensor : Bus Clock
Current Clock : 100.0044

Sensor : CPU Core #1
Current Clock : 4900.217

Sensor : CPU Core #2
Current Clock : 4900.217

Sensor : CPU Core #3
Current Clock : 4900.217

Sensor : CPU Core #4
Current Clock : 4900.217

Sensor : CPU Core #5
Current Clock : 4900.217

Sensor : CPU Core #6
Current Clock : 4900.217

Sensor : CPU Core #7
Current Clock : 4900.217

Sensor : CPU Core #8
Current Clock : 4900.217
- Error Output: 111
 </ul>
 

20210227-Get-OpenHardwareMonitorTemps.json (23.3 KB)

Thank you for sharing, I’m sure that many of us can use this against a few systems as required.
I have one server that seems to ramp up fan speeds at random times, this may just assist to track down a logical reason, may even be the clients turning off air con or leaving doors open and seeing internal temps rising.

mcfproservices