Documentation

Contents
Contents

Collecting the Processor Temperature With uberAgent

The other day a customer asked if uberAgent is collecting the CPU temperature. By default, it is not. But you can easily add the CPU temperature as a metric via uberAgent’s custom script functionality. Here is how.

In a nutshell, uberAgent’s custom script functionality allows you to execute arbitrary scripts whose output is sent to the backend (e.g., Splunk). Go here to get more details on the configuration.

Choose Your Preferred Data Source

The processor temperature is stored in one of these WMI objects, or both:

  1. MSAcpi_ThermalZoneTemperature
  2. Win32_PerfFormattedData_Counters_ThermalZoneInformation

On our test machine, the values differed between the two objects. We compared them with the values other tools like HWInfo provided and found that Win32_PerfFormattedData_Counters_ThermalZoneInformation is the better option for our machine. That could be different for yours, though.

Either way, your machines have to support at least one of these objects. If the machines are equipped with Intel processors, they will likely do. If not, you will get the error Get-WMIObject : Not supported when running a PowerShell command like Get-WMIObject MSAcpi_ThermalZoneTemperature -Namespace "root/wmi".

We wrote two PowerShell scripts, one for each object, which give you the temperature in Celsius, Fahrenheit, and Kelvin. Choose your preferred unit by commenting out the other unnecessary rows.

$temperature = Get-CimInstance -ClassName MSAcpi_ThermalZoneTemperature -Namespace "root/wmi"

$TempKelvin = $temperature.CurrentTemperature / 10
$TempCelsius = $TempKelvin - 273.15

$TempFahrenheit = (9/5) * $TempCelsius + 32

$Output = @{
   # delete rows which are not needed
   'TempCelsius' = [math]::Round($TempCelsius)
   'TempFahrenheit' = [math]::Round($TempFahrenheit)
   'TempKelvin' = [math]::Round($TempKelvin)
}
Write-Output $($Output.Keys.ForEach({"$_=$($Output.$_)"}) -join ' ')
$TempKelvin = (Get-CimInstance -ClassName Win32_PerfFormattedData_Counters_ThermalZoneInformation).Temperature
$TempCelsius = $TempKelvin - 273.15

$TempFahrenheit = (9/5) * $TempCelsius + 32

$Output = @{
# delete rows which are not needed
   'TempCelsius' = [math]::Round($TempCelsius)
   'TempFahrenheit' = [math]::Round($TempFahrenheit)
   'TempKelvin' = [math]::Round($TempKelvin)
}
Write-Output $($Output.Keys.ForEach({"$_=$($Output.$_)"}) -join ' ')

The output of both scripts looks like this: TempCelsius=65 TempFahrenheit=149 TempKelvin=338

Configure uberAgent to Start Querying

Store your preferred script somewhere on the target machines. We went with C:\Program Files\vast limits\uberAgent\Scripts\Get-ProcessorTemperature.ps1.

Next step is to create a new timer in uberAgent’s configuration, like this:

############################################
# Timer 12
############################################
[Timer]
Name = Processor temperature
Comment = Collect processor temperature with a custom script
# Run every 5 minutes
Interval = 300000
# Run the first time 10 minutes after boot to give the machine time to get into a normal working state
Start delay = 600000
Script = powershell.exe -executionpolicy bypass -file "C:\Program Files\vast limits\uberAgent\Scripts\Get-ProcessorTemperature.ps1"
ScriptContext = Session0AsSystem # Run this script with system permissions

Splunk it!

Now you have the processor’s temperature in Splunk and can relate it to the machine’s performance.

Please note that there are more advanced technologies to get the processor temperature, like Intel DTS. But using these with PowerShell would go beyond the scope of a practice guide.