Sha256: 5bb8a954919ef0a95bdbeda7fb796a325ddd23017aabe694eecfef3270e442ce

Contents?: true

Size: 1.92 KB

Versions: 9

Compression:

Stored size: 1.92 KB

Contents

#
#   metric-windows-cpu-load.ps1
#
# DESCRIPTION:
#   This plugin collects and outputs the CPU Usage in a Graphite acceptable format.
#
# OUTPUT:
#   metric data
#
# PLATFORMS:
#   Windows
#
# DEPENDENCIES:
#   Powershell
#
# USAGE:
#   Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\metric-windows-cpu-load.ps1
#
# NOTES:
#
# LICENSE:
#   Copyright 2016 sensu-plugins
#   Released under the same terms as Sensu (the MIT license); see LICENSE for details.
#

param(
    [switch]$UseFullyQualifiedHostname
    )

$ThisProcess = Get-Process -Id $pid
$ThisProcess.PriorityClass = "BelowNormal"

. (Join-Path $PSScriptRoot perfhelper.ps1)

if ($UseFullyQualifiedHostname -eq $false) {
    $Path = ($env:computername).ToLower()
}else {
    $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
}

$perfCategoryID = Get-PerformanceCounterByID -Name 'Processor Information'
$localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID

$counters =  New-Object System.Collections.ArrayList

[void]$counters.Add('% Processor Time')
[void]$counters.Add('% Idle Time')
[void]$counters.Add('% User Time')
[void]$counters.Add('% Interrupt Time')

foreach ($counter in $counters) {

$perfCounterID = Get-PerformanceCounterByID -Name $counter
$localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
$value = [System.Math]::Round((Get-Counter "\$localizedCategoryName(_total)\$localizedCounterName" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)

$Time = DateTimeToUnixTimestamp -DateTime (Get-Date)

if ($counter -eq '% Processor Time') { Write-Host "$Path.cpu.percent.total $value $Time" }
if ($counter -eq '% Idle Time') { Write-Host "$Path.cpu.percent.idle $value $Time" }
if ($counter -eq '% User Time') { Write-Host "$Path.cpu.percent.user $value $Time" }
if ($counter -eq '% Interrupt Time') { Write-Host "$Path.cpu.percent.user $value $Time" }

}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sensu-plugins-windows-2.8.0 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.7.0 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.6.0 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.5.0 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.4.1 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.4.0 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.3.0 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.2.1 bin/powershell/metric-windows-cpu-load.ps1
sensu-plugins-windows-2.2.0 bin/powershell/metric-windows-cpu-load.ps1