Sha256: 741e9242412edfc740ba8d81036c0536df2ea3fba420058a077dd53c8ae4d0f6

Contents?: true

Size: 1.99 KB

Versions: 13

Compression:

Stored size: 1.99 KB

Contents

#
#   metric-windows-network.ps1
#
# DESCRIPTION:
#   This plugin collects and outputs all Network Adapater Statistic 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-network.ps1
#
# NOTES:
#
# LICENSE:
#   Copyright 2016 sensu-plugins
#   Released under the same terms as Sensu (the MIT license); see LICENSE for details.
#

param(
    [string[]]$Interfaces,
    [switch]$UseFullyQualifiedHostname
    )

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

. (Join-Path $PSScriptRoot perfhelper.ps1)

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

$perfCategoryID = Get-PerformanceCounterByID -Name 'Network Interface'
$localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID

for($i = 0; $i -lt $Interfaces.Count; $i+=1) {
    $tmp = $Interfaces[$i]
    $Interfaces[$i] = $tmp.Replace("_"," ")
}

foreach ($ObjNet in (Get-Counter -Counter "\$localizedCategoryName(*)\*").CounterSamples) 
{ 

  if ($Interfaces.Contains($ObjNet.InstanceName)) {

     $Measurement = ($ObjNet.Path).Trim("\\") -replace "\\","." -replace " ","_" -replace "[(]","." -replace "[)]","" -replace "[\{\}]","" -replace "[\[\]]",""

	 $Measurement = $Measurement.Remove(0,$Measurement.IndexOf("."))   
	 $Path = $Hostname+$Measurement

     $Path = $Path.Replace("/s","_per_second")
     $Path = $Path.Replace(":","")
     $Path = $Path.Replace(",","")
     $Path = $Path.Replace("ä","ae")
     $Path = $Path.Replace("ö","oe")
     $Path = $Path.Replace("ü","ue")
	 $Path = $Path.Replace("ß","ss")

     $Value = [System.Math]::Round(($ObjNet.CookedValue),0)
     $Time = DateTimeToUnixTimestamp -DateTime (Get-Date)

     Write-Host "$Path $Value $Time"

   }

}

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
sensu-plugins-windows-3.0.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.9.1 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.9.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.8.1 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.8.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.7.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.6.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.5.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.4.1 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.4.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.3.0 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.2.1 bin/powershell/metric-windows-network.ps1
sensu-plugins-windows-2.2.0 bin/powershell/metric-windows-network.ps1