sensu-plugins-windows 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -1
  3. data/bin/check-windows-cpu-load.rb +0 -0
  4. data/bin/check-windows-process.rb +0 -0
  5. data/bin/check-windows-processor-queue-length.rb +0 -0
  6. data/bin/check-windows-ram.rb +0 -0
  7. data/bin/check-windows-service.rb +0 -0
  8. data/bin/metric-windows-cpu-load.rb +0 -0
  9. data/bin/metric-windows-disk-usage.rb +0 -0
  10. data/bin/metric-windows-network.rb +0 -0
  11. data/bin/metric-windows-processor-queue-length.rb +0 -0
  12. data/bin/metric-windows-ram-usage.rb +0 -0
  13. data/bin/metric-windows-uptime.rb +0 -0
  14. data/bin/powershell/check-windows-cpu-load.ps1 +13 -3
  15. data/bin/powershell/check-windows-disk-writeable.ps1 +0 -0
  16. data/bin/powershell/check-windows-disk.ps1 +0 -0
  17. data/bin/powershell/check-windows-http.ps1 +0 -0
  18. data/bin/powershell/check-windows-pagefile.ps1 +0 -0
  19. data/bin/powershell/check-windows-process.ps1 +0 -0
  20. data/bin/powershell/check-windows-processor-queue-length.ps1 +0 -0
  21. data/bin/powershell/check-windows-ram.ps1 +0 -0
  22. data/bin/powershell/check-windows-service.ps1 +0 -0
  23. data/bin/powershell/metric-windows-cpu-load.ps1 +34 -5
  24. data/bin/powershell/metric-windows-disk-usage.ps1 +17 -6
  25. data/bin/powershell/metric-windows-disk.ps1 +91 -0
  26. data/bin/powershell/metric-windows-network.ps1 +46 -6
  27. data/bin/powershell/metric-windows-processor-queue-length.ps1 +13 -5
  28. data/bin/powershell/metric-windows-ram-usage.ps1 +18 -3
  29. data/bin/powershell/metric-windows-system.ps1 +56 -0
  30. data/bin/powershell/metric-windows-uptime.ps1 +10 -2
  31. data/bin/powershell/perfhelper.ps1 +106 -0
  32. data/lib/sensu-plugins-windows/version.rb +1 -1
  33. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 377a2b75e1e7bd9d94ad88e3e5e84711df72a21d
4
- data.tar.gz: c6a97eb3efa5a6e9251984e127861453aafbdd99
3
+ metadata.gz: 03475123ef7a2c451c0d301dbf37640cc7a08192
4
+ data.tar.gz: e15a8327c01b9e84d3da8b80267fd9782bf87bbd
5
5
  SHA512:
6
- metadata.gz: db43777f468634d77a6fc2d408bf7e14f44ea5fa3aa95866a57bd6ec7179062d5bf8207a3e4c18f169600ae77098ca9e693f5d7f93cf287452496c30a52a3a68
7
- data.tar.gz: e954695bf78a8d42dcf9c5c27ede9681d97d84c2824bec3ff772ee01ca3f592c2de6ce4a0dde0638570563d28cc5b2734b2c6adf650a8f1d6d32d3b31db27a6b
6
+ metadata.gz: 2b7ac45b11cca7841ff87a72fe8fd4e018dea0539e316a8c48fd404a88beb291f0a9d52b7f23bbac5d4f34d6b3eda88230c120498477060e4bfd02beef2c939c
7
+ data.tar.gz: cf71707f9fc12c924cff1ac5620cd30ae0d76572a6dd25ed53e6794ea4181686839d29414867330799834dc16cce6454e1f26556a1cfbb586cbe1bd041b81e90
data/CHANGELOG.md CHANGED
@@ -4,6 +4,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/).
5
5
 
6
6
  ## [Unreleased]
7
+
8
+ ## [2.2.0] - 2017-09-08
9
+ ### Fixed
10
+ - added multi language support to all the powershell scripts (@Seji64)
11
+ - powershell/metric-windows-network.ps1: handle interfaces with spaces in their name (@Seji64)
12
+
13
+ ### Added
14
+ - `powershell/perfhelper.ps1`: added standard sensu header (@Seji64)
15
+ - added option to enable fdqn in metric path (@Seji64)
16
+ - `powershell/metric-windows-disk.ps1` new metric script for disk IO stats (@Seji64)
17
+
18
+
7
19
  ### [2.1.0] - 2017-08-26
8
20
  ### Added
9
21
  - `powershell/check-windows-pagefile.ps1`: which basically allows checking how much pagefile (aka swap) is in use. (@hulkk)
@@ -103,7 +115,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
103
115
  ### Added
104
116
  - Initial release
105
117
 
106
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.0.0...HEAD
118
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.2.0...HEAD
119
+ [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.1.0...2.2.0
107
120
  [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/2.0.0...2.1.0
108
121
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/1.0.0...2.0.0
109
122
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-Windows/compare/0.1.0...1.0.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -34,10 +34,18 @@ Param(
34
34
  [int]$CRITICAL
35
35
  )
36
36
 
37
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
38
+
37
39
  $ThisProcess = Get-Process -Id $pid
38
40
  $ThisProcess.PriorityClass = "BelowNormal"
39
41
 
40
- $Value = [System.Math]::Round((Get-Counter '\processor(_total)\% processor time' -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
42
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'Processor Information'
43
+ $perfCounterID = Get-PerformanceCounterByID -Name '% Processor Time'
44
+
45
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
46
+ $localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
47
+
48
+ $Value = [System.Math]::Round((Get-Counter "\$localizedCategoryName(_total)\$localizedCounterName" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
41
49
 
42
50
  If ($Value -gt $CRITICAL) {
43
51
  Write-Host CheckWindowsCpuLoad CRITICAL: CPU at $Value%.
@@ -45,8 +53,10 @@ If ($Value -gt $CRITICAL) {
45
53
 
46
54
  If ($Value -gt $WARNING) {
47
55
  Write-Host CheckWindowsCpuLoad WARNING: CPU at $Value%.
48
- Exit 1 }
56
+ Exit 1
57
+ }
49
58
 
50
59
  Else {
51
60
  Write-Host CheckWindowsCpuLoad OK: CPU at $Value%.
52
- Exit 0 }
61
+ Exit 0
62
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -22,14 +22,43 @@
22
22
  # Copyright 2016 sensu-plugins
23
23
  # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
24
  #
25
+
26
+ param(
27
+ [switch]$UseFullyQualifiedHostname
28
+ )
29
+
25
30
  $ThisProcess = Get-Process -Id $pid
26
31
  $ThisProcess.PriorityClass = "BelowNormal"
27
32
 
28
- $Path = hostname
29
- $Path = $Path.ToLower()
33
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
34
+
35
+ if ($UseFullyQualifiedHostname -eq $false) {
36
+ $Path = ($env:computername).ToLower()
37
+ }else {
38
+ $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
39
+ }
40
+
41
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'Processor Information'
42
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
43
+
44
+ $counters = New-Object System.Collections.ArrayList
45
+
46
+ [void]$counters.Add('% Processor Time')
47
+ [void]$counters.Add('% Idle Time')
48
+ [void]$counters.Add('% User Time')
49
+ [void]$counters.Add('% Interrupt Time')
50
+
51
+ foreach ($counter in $counters) {
52
+
53
+ $perfCounterID = Get-PerformanceCounterByID -Name $counter
54
+ $localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
55
+ $value = [System.Math]::Round((Get-Counter "\$localizedCategoryName(_total)\$localizedCounterName" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
30
56
 
31
- $Value = (Get-WmiObject CIM_Processor).LoadPercentage
57
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
32
58
 
33
- $Time = [int][double]::Parse((Get-Date -UFormat %s))
59
+ if ($counter -eq '% Processor Time') { Write-Host "$Path.cpu.percent.total $value $Time" }
60
+ if ($counter -eq '% Idle Time') { Write-Host "$Path.cpu.percent.idle $value $Time" }
61
+ if ($counter -eq '% User Time') { Write-Host "$Path.cpu.percent.user $value $Time" }
62
+ if ($counter -eq '% Interrupt Time') { Write-Host "$Path.cpu.percent.user $value $Time" }
34
63
 
35
- Write-Host "$Path.system.processor_total.%_processor_time $Value $Time"
64
+ }
@@ -22,9 +22,22 @@
22
22
  # Copyright 2016 sensu-plugins
23
23
  # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
24
  #
25
+
26
+ param(
27
+ [switch]$UseFullyQualifiedHostname
28
+ )
29
+
25
30
  $ThisProcess = Get-Process -Id $pid
26
31
  $ThisProcess.PriorityClass = "BelowNormal"
27
32
 
33
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
34
+
35
+ if ($UseFullyQualifiedHostname -eq $false) {
36
+ $Path = ($env:computername).ToLower()
37
+ }else {
38
+ $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
39
+ }
40
+
28
41
  $AllDisks = Get-WMIObject Win32_LogicalDisk -Filter "DriveType = 3" | ? { $_.DeviceID -notmatch "[ab]:"}
29
42
 
30
43
  foreach ($ObjDisk in $AllDisks)
@@ -35,11 +48,9 @@ foreach ($ObjDisk in $AllDisks)
35
48
  $AvailableSpace = [System.Math]::Round(($ObjDisk.Freespace/1MB),2)
36
49
  $UsedPercentage = [System.Math]::Round(((($ObjDisk.Size-$ObjDisk.Freespace)/$ObjDisk.Size)*100),2)
37
50
 
38
- $Path = (hostname).ToLower()
39
-
40
- $Time = [int][double]::Parse((Get-Date -UFormat %s))
51
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
41
52
 
42
- Write-Host "$Path.system.Disk.$DeviceId.UsedMB $UsedSpace $Time"
43
- Write-Host "$Path.system.Disk.$DeviceId.FreeMB $AvailableSpace $Time"
44
- Write-Host "$Path.system.Disk.$DeviceId.UsedPercentage $UsedPercentage $Time"
53
+ Write-Host "$Path.disk.usage.$DeviceId.UsedMB $UsedSpace $Time"
54
+ Write-Host "$Path.disk.usage.$DeviceId.FreeMB $AvailableSpace $Time"
55
+ Write-Host "$Path.disk.usage.$DeviceId.UsedPercentage $UsedPercentage $Time"
45
56
  }
@@ -0,0 +1,91 @@
1
+ #
2
+ # metric-windows-disk.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This plugin collects and outputs all Disk/HDD Statistic in a Graphite acceptable format.
6
+ #
7
+ # OUTPUT:
8
+ # metric data
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # Powershell
15
+ #
16
+ # USAGE:
17
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\metric-windows-disk.ps1
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Copyright 2016 sensu-plugins
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
+ #
25
+
26
+ param(
27
+ [switch]$UseFullyQualifiedHostname
28
+ )
29
+
30
+ $counters = New-Object System.Collections.ArrayList
31
+ $instances = @{}
32
+
33
+ $ThisProcess = Get-Process -Id $pid
34
+ $ThisProcess.PriorityClass = "BelowNormal"
35
+
36
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
37
+
38
+ if ($UseFullyQualifiedHostname -eq $false) {
39
+ $Path = ($env:computername).ToLower()
40
+ }else {
41
+ $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
42
+ }
43
+
44
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'PhysicalDisk'
45
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
46
+
47
+ [void]$counters.Add('Avg. Disk Bytes/Read')
48
+ [void]$counters.Add('Avg. Disk Bytes/Write')
49
+ [void]$counters.Add('Avg. Disk sec/Read')
50
+ [void]$counters.Add('Avg. Disk sec/Write')
51
+ [void]$counters.Add('Current Disk Queue Length')
52
+
53
+ foreach ($ObjDisk in (Get-Counter -Counter "\$localizedCategoryName(*)\*").CounterSamples) {
54
+
55
+ if ($instances.ContainsKey($ObjDisk.InstanceName) -eq $false) {
56
+
57
+ if ($ObjDisk.InstanceName.ToLower() -ne '_total') {
58
+ $disk = $ObjDisk.InstanceName
59
+ $disk = $disk.Remove(0,1)
60
+ $disk = $disk.Replace(":","")
61
+ $disk = $disk.Trim()
62
+ $instances.Add($ObjDisk.InstanceName,$disk.toUpper())
63
+ }
64
+
65
+ }
66
+
67
+ }
68
+
69
+ foreach ($diskkey in $instances.Keys) {
70
+
71
+ $diskname = $instances.$diskkey
72
+
73
+ foreach ($counter in $counters) {
74
+
75
+ $perfCounterID = Get-PerformanceCounterByID -Name $counter
76
+ $localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
77
+ $value = [System.Math]::Round((Get-Counter "\$localizedCategoryName($diskkey)\$localizedCounterName" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
78
+
79
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
80
+
81
+ if ($counter -eq 'Avg. Disk Bytes/Read') { Write-Host "$Path.disk.iostat.$diskname.read_bytes $value $Time" }
82
+ if ($counter -eq 'Avg. Disk Bytes/Write') { Write-Host "$Path.disk.iostat.$diskname.write_bytes $value $Time" }
83
+ if ($counter -eq 'Avg. Disk sec/Read') { Write-Host "$Path.disk.iostat.$diskname.read_await $value $Time" }
84
+ if ($counter -eq 'Avg. Disk sec/Write') { Write-Host "$Path.disk.iostat.$diskname.write_await $value $Time" }
85
+ if ($counter -eq 'Current Disk Queue Length') { Write-Host "$Path.disk.iostat.$diskname.queue_lenght $value $Time" }
86
+
87
+ }
88
+
89
+ }
90
+
91
+
@@ -22,14 +22,54 @@
22
22
  # Copyright 2016 sensu-plugins
23
23
  # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
24
  #
25
+
26
+ param(
27
+ [string[]]$Interfaces,
28
+ [switch]$UseFullyQualifiedHostname
29
+ )
30
+
25
31
  $ThisProcess = Get-Process -Id $pid
26
32
  $ThisProcess.PriorityClass = "BelowNormal"
27
33
 
28
- foreach ($ObjNet in (Get-Counter -Counter "\Network Interface(*)\*").CounterSamples)
29
- {
30
- $Path = ($ObjNet.Path).Trim("\\") -replace "\\","." -replace " ","_" -replace "[(]","." -replace "[)]","" -replace "[\{\}]","" -replace "[\[\]]",""
31
- $Value = [System.Math]::Round(($ObjNet.CookedValue),0)
32
- $Time = [int][double]::Parse((Get-Date -UFormat %s))
34
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
35
+
36
+ if ($UseFullyQualifiedHostname -eq $false) {
37
+ $Hostname = ($env:computername).ToLower()
38
+ }else {
39
+ $Hostname = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
40
+ }
41
+
42
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'Network Interface'
43
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
33
44
 
34
- Write-Host "$Path $Value $Time"
45
+ for($i = 0; $i -lt $Interfaces.Count; $i+=1) {
46
+ $tmp = $Interfaces[$i]
47
+ $Interfaces[$i] = $tmp.Replace("_"," ")
35
48
  }
49
+
50
+ foreach ($ObjNet in (Get-Counter -Counter "\$localizedCategoryName(*)\*").CounterSamples)
51
+ {
52
+
53
+ if ($Interfaces.Contains($ObjNet.InstanceName)) {
54
+
55
+ $Measurement = ($ObjNet.Path).Trim("\\") -replace "\\","." -replace " ","_" -replace "[(]","." -replace "[)]","" -replace "[\{\}]","" -replace "[\[\]]",""
56
+
57
+ $Measurement = $Measurement.Remove(0,$Measurement.IndexOf("."))
58
+ $Path = $Hostname+$Measurement
59
+
60
+ $Path = $Path.Replace("/s","_per_second")
61
+ $Path = $Path.Replace(":","")
62
+ $Path = $Path.Replace(",","")
63
+ $Path = $Path.Replace("�","ae")
64
+ $Path = $Path.Replace("�","oe")
65
+ $Path = $Path.Replace("�","ue")
66
+ $Path = $Path.Replace("�","ss")
67
+
68
+ $Value = [System.Math]::Round(($ObjNet.CookedValue),0)
69
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
70
+
71
+ Write-Host "$Path $Value $Time"
72
+
73
+ }
74
+
75
+ }
@@ -22,14 +22,22 @@
22
22
  # Copyright 2016 sensu-plugins
23
23
  # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
24
  #
25
+ param(
26
+ [switch]$UseFullyQualifiedHostname
27
+ )
28
+
25
29
  $ThisProcess = Get-Process -Id $pid
26
30
  $ThisProcess.PriorityClass = "BelowNormal"
27
31
 
28
- $Path = hostname
29
- $Path = $Path.ToLower()
32
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
30
33
 
31
- $Value = (Get-WmiObject Win32_PerfFormattedData_PerfOS_System).ProcessorQueueLength
34
+ if ($UseFullyQualifiedHostname -eq $false) {
35
+ $Path = ($env:computername).ToLower()
36
+ }else {
37
+ $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
38
+ }
32
39
 
33
- $Time = [int][double]::Parse((Get-Date -UFormat %s))
40
+ $Value = (Get-WmiObject Win32_PerfFormattedData_PerfOS_System).ProcessorQueueLength
41
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
34
42
 
35
- Write-Host "$Path.system.processor_queue_length $Value $Time"
43
+ Write-Host "$Path.cpu.queue_length $Value $Time"
@@ -22,14 +22,29 @@
22
22
  # Copyright 2016 sensu-plugins
23
23
  # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
24
  #
25
+ param(
26
+ [switch]$UseFullyQualifiedHostname
27
+ )
28
+
25
29
  $ThisProcess = Get-Process -Id $pid
26
30
  $ThisProcess.PriorityClass = "BelowNormal"
27
31
 
32
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
33
+
34
+ if ($UseFullyQualifiedHostname -eq $false) {
35
+ $Path = ($env:computername).ToLower()
36
+ }else {
37
+ $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
38
+ }
39
+
28
40
  $FreeMemory = (Get-WmiObject -Query "SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem").FreePhysicalMemory
29
41
  $TotalMemory = (Get-WmiObject -Query "SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem").TotalVisibleMemorySize
42
+ $UsedMemory = $TotalMemory-$FreeMemory
30
43
 
31
- $Path = (hostname).ToLower()
32
44
  $Value = [System.Math]::Round(((($TotalMemory-$FreeMemory)/$TotalMemory)*100),2)
33
- $Time = [int][double]::Parse((Get-Date -UFormat %s))
45
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
34
46
 
35
- Write-host "$Path.system.ram.RamUsagePercent $Value $Time"
47
+ Write-host "$Path.memory.free $FreeMemory $Time"
48
+ Write-host "$Path.memory.total $TotalMemory $Time"
49
+ Write-host "$Path.memory.used $UsedMemory $Time"
50
+ Write-host "$Path.memory.percent.used $Value $Time"
@@ -0,0 +1,56 @@
1
+ #
2
+ # metric-windows-system.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This plugin collects and outputs some System Perfomance Counters in a Graphite acceptable format.
6
+ #
7
+ # OUTPUT:
8
+ # metric data
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # Powershell
15
+ #
16
+ # USAGE:
17
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\metric-windows-sytem.ps1
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Copyright 2016 sensu-plugins
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
+ #
25
+
26
+ param(
27
+ [switch]$UseFullyQualifiedHostname
28
+ )
29
+
30
+ $ThisProcess = Get-Process -Id $pid
31
+ $ThisProcess.PriorityClass = "BelowNormal"
32
+
33
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
34
+
35
+ if ($UseFullyQualifiedHostname -eq $false) {
36
+ $Path = ($env:computername).ToLower()
37
+ }else {
38
+ $Path = [System.Net.Dns]::GetHostEntry([string]"localhost").HostName.toLower()
39
+ }
40
+
41
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'Processor Information'
42
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
43
+ $perfCounterID = Get-PerformanceCounterByID -Name 'Interrupts/sec'
44
+ $localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
45
+ $count_interrupt = [System.Math]::Round((Get-Counter "\$localizedCategoryName(_total)\$localizedCounterName" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
46
+
47
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'System'
48
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
49
+ $perfCounterID = Get-PerformanceCounterByID -Name 'Context Switches/sec'
50
+ $localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
51
+ $count_context = [System.Math]::Round((Get-Counter "\$localizedCategoryName\$localizedCounterName" -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
52
+
53
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
54
+
55
+ Write-Host "$Path.system.irq_per_second $count_interrupt $Time"
56
+ Write-Host "$Path.system.context_switches_per_second $count_context $Time"
@@ -25,10 +25,18 @@
25
25
  $ThisProcess = Get-Process -Id $pid
26
26
  $ThisProcess.PriorityClass = "BelowNormal"
27
27
 
28
- $Counter = ((Get-Counter "\System\System Up Time").CounterSamples)
28
+ . (Join-Path $PSScriptRoot perfhelper.ps1)
29
+
30
+ $perfCategoryID = Get-PerformanceCounterByID -Name 'System'
31
+ $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID
32
+
33
+ $perfCounterID = Get-PerformanceCounterByID -Name 'System Up Time'
34
+ $localizedCounterName = Get-PerformanceCounterLocalName -ID $perfCounterID
35
+
36
+ $Counter = ((Get-Counter "\$localizedCategoryName\$localizedCounterName").CounterSamples)
29
37
 
30
38
  $Path = ($Counter.Path).Trim("\\") -replace " ","_" -replace "\\","." -replace "[\{\}]","" -replace "[\[\]]",""
31
39
  $Value = [System.Math]::Truncate($Counter.CookedValue)
32
- $Time = [int][double]::Parse((Get-Date -UFormat %s))
40
+ $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)
33
41
 
34
42
  Write-Host "$Path $Value $Time"
@@ -0,0 +1,106 @@
1
+ #
2
+ # perfhelper.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This is file provides useful functions for powershell based metric checks
6
+ #
7
+ # OUTPUT:
8
+ # metric data
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # Powershell
15
+ #
16
+ # USAGE:
17
+ # To use these functions dot source this file.
18
+ # Example: . (Join-Path $PSScriptRoot perfhelper.ps1)
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2016 sensu-plugins
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
25
+ #
26
+ #
27
+ # Taken from: http://www.powershellmagazine.com/2013/07/19/querying-performance-counters-from-powershell/
28
+ # THX!
29
+ #
30
+
31
+
32
+ function Get-PerformanceCounterByID
33
+ {
34
+ param
35
+ (
36
+ [Parameter(Mandatory=$true)]
37
+ $Name
38
+ )
39
+
40
+ $hashfile = (Join-Path $PSScriptRoot perfhash.hsh)
41
+
42
+ if ([System.IO.File]::Exists($hashfile)) {
43
+
44
+ $perfHash = Import-Clixml -Path $hashfile
45
+ }
46
+
47
+ if ($perfHash -eq $null)
48
+ {
49
+
50
+ $key = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
51
+ $counters = (Get-ItemProperty -Path $key -Name Counter).Counter
52
+ $perfHash = @{}
53
+ $all = $counters.Count
54
+
55
+ for($i = 0; $i -lt $all; $i+=2)
56
+ {
57
+ $perfHash.$($counters[$i+1]) = $counters[$i]
58
+ }
59
+
60
+ Export-Clixml -InputObject $perfHash -Path $hashfile
61
+
62
+ }
63
+
64
+ $perfHash.$Name
65
+ }
66
+
67
+ $signature = @'
68
+ [DllImport("pdh.dll", SetLastError = true, CharSet = CharSet.Unicode)]
69
+ static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, StringBuilder szNameBuffer, ref uint pcchNameBufferSize);
70
+ '@;
71
+
72
+ Function Get-PerformanceCounterLocalName
73
+ {
74
+ param
75
+ (
76
+ [UInt32]
77
+ $ID,
78
+
79
+ $ComputerName = $env:COMPUTERNAME
80
+ )
81
+
82
+ $code = '[DllImport("pdh.dll", SetLastError=true, CharSet=CharSet.Unicode)] public static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, System.Text.StringBuilder szNameBuffer, ref uint pcchNameBufferSize);'
83
+
84
+ $Buffer = New-Object System.Text.StringBuilder(1024)
85
+ [UInt32]$BufferSize = $Buffer.Capacity
86
+
87
+ $t = Add-Type -MemberDefinition $code -PassThru -Name PerfCounter -Namespace Utility
88
+ $rv = $t::PdhLookupPerfNameByIndex($ComputerName, $id, $Buffer, [Ref]$BufferSize)
89
+
90
+ if ($rv -eq 0)
91
+ {
92
+ $Buffer.ToString().Substring(0, $BufferSize-1)
93
+ }
94
+ else
95
+ {
96
+ Throw 'Get-PerformanceCounterLocalName : Unable to retrieve localized name. Check computer name and performance counter ID.'
97
+ }
98
+ }
99
+
100
+ Function DateTimeToUnixTimestamp([datetime]$DateTime)
101
+ {
102
+ $utcDate = $DateTime.ToUniversalTime()
103
+ # Convert to a Unix time without any rounding
104
+ [uint64]$UnixTime = [double]::Parse((Get-Date -Date $utcDate -UFormat %s))
105
+ return [uint64]$UnixTime
106
+ }
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsWindows
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-windows
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-26 00:00:00.000000000 Z
11
+ date: 2017-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -153,8 +153,8 @@ dependencies:
153
153
  description: Sensu plugins for Windows
154
154
  email: "<sensu-users@googlegroups.com>"
155
155
  executables:
156
- - check-windows-cpu-load.rb
157
156
  - check-windows-disk.rb
157
+ - check-windows-cpu-load.rb
158
158
  - check-windows-process.rb
159
159
  - check-windows-processor-queue-length.rb
160
160
  - check-windows-ram.rb
@@ -194,10 +194,13 @@ files:
194
194
  - bin/powershell/check-windows-service.ps1
195
195
  - bin/powershell/metric-windows-cpu-load.ps1
196
196
  - bin/powershell/metric-windows-disk-usage.ps1
197
+ - bin/powershell/metric-windows-disk.ps1
197
198
  - bin/powershell/metric-windows-network.ps1
198
199
  - bin/powershell/metric-windows-processor-queue-length.ps1
199
200
  - bin/powershell/metric-windows-ram-usage.ps1
201
+ - bin/powershell/metric-windows-system.ps1
200
202
  - bin/powershell/metric-windows-uptime.ps1
203
+ - bin/powershell/perfhelper.ps1
201
204
  - lib/sensu-plugins-windows.rb
202
205
  - lib/sensu-plugins-windows/version.rb
203
206
  homepage: https://github.com/sensu-plugins/sensu-plugins-windows
@@ -226,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
229
  version: '0'
227
230
  requirements: []
228
231
  rubyforge_project:
229
- rubygems_version: 2.4.5
232
+ rubygems_version: 2.6.13
230
233
  signing_key:
231
234
  specification_version: 4
232
235
  summary: Sensu plugins for Windows