Cacti – Windows7 – remote Host – Netzwerkkarte Bandwidth Send und Received

Powershell Script zum remote Abfragen der Netzwerkkarte eines Computers und auslesen der Send und Received Werte und der grafischen Darstellung in Cacti.

# Version 1.0 vom 23.03.2015 by Taste-Of-IT.de
# return the nic Bandwith in MB, Send and Recived Bytes/Sec
# call script-name.ps1 <nicname> <hostname> e.g. client01 *Gigabit*
Try{
        $Hostname = $args[0]
        $Nicname = $args[1]
        # total Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface |where {$_.Name -like '*Gigabit*'} |select BytesTotalPersec
        $Bandwidth = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface -ComputerName $Hostname |where {$_.Name -like $Nicname} | Select-Object -ExpandProperty CurrentBandwidth
        $BytesSend = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface -ComputerName $Hostname |where {$_.Name -like $Nicname} | Select-Object -ExpandProperty BytesSentPerSec
        $BytesReceived = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface -ComputerName $Hostname |where {$_.Name -like $Nicname} | Select-Object -ExpandProperty BytesReceivedPersec        
        "Bandwidth:"+($Bandwidth/1000000)+" Send:"+$BytesSend+" Received:"+$BytesReceived
    }
Catch{
        "Bandwidth:0 Send:0 Received:0"
    }

Das Powershell Script liest die Send und  Received Werte der Netzwerkkarte eines Remote Computers aus. Gelingt dies nicht wird statt eines Fehlers, der dann in Cacti aufschlagen würde, jeweils der Wert 0 zurückgegeben (Try / Catch).

Kurzanleitung für den Graphen zur Anzeigen der Send und Received Werte einer Netzwerkkarte in Cacti

  • Login -> console
  • Data Input Methods -> Add ->
    • Name = Win – PS Network Bandwidth Send Received
    • Input Type = Script/Command
    • Input String = powershell c:\ps-scripte\ps-remote-network-stats.ps1 <hostname> <networkname>
    • Create
    • Input Fields -> Add
      • Field[Input] = hostname
      • Friendly Name = Hostname
      • Special Type Code = hostname
    • Input Fields -> Add
      • Field[Input] = networkname
      • Friendly Name = NetworkName
      • Special Type Code =
    • Output Fields -> Add
      • Field = Bandwidth
      • Friendly Name = Bandwidth
      • Create
    • Output Fields -> Add
      • Field = Send
      • Friendly Name = Send
      • Create
    • Output Fields -> Add
      • Field = Received
      • Friendly Name = Received
      • Create
    • Save
  • Data Templates -> Add
    • Data Templates
      • Name = Win – PS Network Bandwidth Send Received
    • Data Source
      • Name = |host_description| Network Bandwidth Send Received
      • Data Input Method = Win – Network Bandwidth Send Received
      • Step = 60
    • Data Source Item
      • Internal Data Source Name = Bandwidth
      • Minimum Value = 0
      • Maximum Value = U
      • Heartbeat = 120
      • Create
      • Output Field = Bandwidth – Bandwidth
      • Save
    • Data Source Item -> New
      • Internal Data Source Name = Send
      • Minimum Value = 0
      • Maximum Value = U
      • Heartbeat = 120
      • Create
      • Output Field = Send – Send
      • Save
    • Data Source Item -> New
      • Internal Data Source Name = Received
      • Minimum Value = 0
      • Maximum Value = U
      • Heartbeat = 120
      • Create
      • Output Field = Received – Received
      • Save
    • Custom Data
      • Hostname = frei lassen
      • NetworkName= Haken für Use Peer-Data Source Value
  • Save
  • Graph Templates -> Add
    • Name = Win – PS Network Bandwidth Send Received
    • Title = |host_description| – |input_networkname| Network Bandwidth Send Received <- |input_networkname| sorgt dafür dass später im Titel des Graphen der individuelle Name des Processes steht
    • Upper Limit = U
    • Lower Limit = 0
    • Base Value = 1024
    • Vertical Label = -byte
    • Create
    • Graph Template Items -> Add (Received – AREA)
      • Data Source = Win – PS Network Bandwidth Send Received – (Received)
      • Color = Gelb
      • Graph Item Type = AREA
      • Consolidate Function = Average
      • CDEF Function =
      • Text Format = Received
      • Create
    • Graph Template Items -> Add (Received – Legend) <-Current, Average und Max werden automatisch erstellt
      • Data Source = Win – PS Network Bandwidth Send Received – (Received)
      • CDEF Function =
      • Text Format = Received
      • Create
    • Graph Template Items -> Add (Send – AREA)
      • Data Source = Win – PS Network Bandwidth Send Received – (Send)
      • Color = Grün
      • Graph Item Type = AREA
      • Consolidate Function = Average
      • CDEF Function =
      • Text Format = Send
      • Create
    • Graph Template Items -> Add (Send – Legend) <-Current, Average und Max werden automatisch erstellt
      • Data Source = Win – PS Network Bandwidth Send Received – (Send)
      • CDEF Function =
      • Text Format = Send
      • Create
    • Graph Template Items -> Add (Bandwidth – Line2)
      • Data Source = Win – PS Network Bandwidth Send Received – (Bandwidth)
      • Color = Schwarz
      • Graph Item Type = Line2
      • Consolidate Function = Average
      • CDEF Function =
      • Text Format = Bandwidth
      • Create
    • Graph Template Items -> Add (Bandwidth – Legend) <-Current, Average und Max werden automatisch erstellt
      • Data Source = Win – PS Network Bandwidth Send Received – (Bandwidth)
      • CDEF Function =
      • Text Format = Bandwidth
      • Create
    • Save
  • Devices -> Add (nur wenn noch kein Host vorhanden ist, ansonsten zum nächsten Punkt)
    • Description = winclient01
    • Hostname = winclient01
    • Host Template = none
    • Downed Device Detection = Ping
    • Ping Method = ICMP Ping
    • Create (ICMP Ping Success (0 ms)
  • Devices -> winclient01 -> Associated Graph Templates
    • Add Graph Templates = Win – PS Network Bandwidth Send Received
    • Add
  • Devices -> winclient01 -> Create Graphs for this Host
    • Graph Template Name – Haken bei Create: Win – PS Network Bandwidth Send Received
    • Create
    • Custom Data -> Networkname= *Gigabit*
    • Create
  • Management -> Graph Management -> obigen Graph vom Host winclient01 dem Default Tree hinzufügen
    • Haken hinter winclient01 – Win – PS Process Memory Usage
    • Place on a Tree (Default Tree)
    • Go
    • Destination Branch: [root]
    • Continue

Done – nun sollte der Graph in den nächsten 2xPoller Time erstellt werden.

Windows7 Cacti Send Received

Windows7 Cacti Send Received

Wichtig ist die Angabe des korrekten Adapternamens, oder wie im Graphen zu sehen schlicht “Gigabit”, wenn nur eine Karte vorhanden ist.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.