Ad Widget

Collapse

network traffic windows, semi automatic perf counter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flexguy
    Junior Member
    • Sep 2008
    • 19

    #1

    network traffic windows, semi automatic perf counter

    should speek for itself:

    'VBS script to "almost" automatically insert PerfCounters in
    'your zabbix_agentd.conf for monitoring network traffic on a windows machine
    '
    'item in zabbix should be:
    'type: active agent
    'key: nic_in (our nic_out)
    'info: float
    'translate Bytes Received/sec & Bytes Sent/sec to your locale
    'edit strFileName to your needs
    '
    Option Explicit

    Dim colAdapters, objAdapter, NicDescription, strFileName, objFS, objTS
    Set colAdapters = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
    For Each objAdapter in colAdapters
    NicDescription = objAdapter.Description
    Next
    strFileName = "C:\zabbix_agentd.conf"
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objTS = objFS.OpenTextFile(strFileName,8)
    objTS.Write vbCrLf
    objTS.Write "PerfCounter=nic_in,"& Chr(34)& "\Network Interface("& NicDescription &")\Bytes Received/sec" & Chr(34) & ",60"
    objTS.Write vbCrLf
    objTS.Write "PerfCounter=nic_out,"& Chr(34)& "\Network Interface("& NicDescription &")\Bytes Sent/sec" & Chr(34) & ",60"
    objTS.Write vbCrLf
    objTS.Close
    WScript.Quit
  • mauibay
    Junior Member
    • Jan 2008
    • 23

    #2
    I'm curious, what is the advantage of adding the perfcounter strings to the agent conf file?

    Comment

    • gospodin.horoshiy
      Senior Member
      • Sep 2008
      • 272

      #3
      Great idea,thanks! But it only works if I change:

      Set colAdapters = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery _
      ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")


      to


      Set colAdapters = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")


      And it only adds single interface. Is there anyway to add all interfaces?
      Zbx 2.0.4 on Debian and MYSQL5 on Ubuntu Server 64bit 8.04,
      200+ Win Agents, 50+ Linux Agents, 150+ Network Devices

      Comment

      • gospodin.horoshiy
        Senior Member
        • Sep 2008
        • 272

        #4
        Here is how I've modified the script,so it adds all NIC you have:

        ALSO:
        'NicDescription(4) is here because of my lack of scripting experience. Calling 'someone to modify it to change digit 4 to number of NICs
        AND:
        I used different class: Win32_PerfFormattedData_TCPIP_NetworkInterface (thanks to mpeide) , because it returns names in format used in perfmon not windows: Example Intel[R] instead of Intel(R)

        ##########SCRIPT START#################

        'VBS script to "almost" automatically insert PerfCounters in
        'your zabbix_agentd.conf for monitoring network traffic on a windows machine
        '
        'item in zabbix should be:
        'type: active agent
        'key: nic_in (our nic_out)
        'info: float
        'translate Bytes Received/sec & Bytes Sent/sec to your locale
        'edit strFileName to your needs
        '
        Option Explicit

        Dim colItems, objItem, NicDescription(4), strFileName, objFS, objTS, i, objRefresher, objWMIService, strComputer


        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
        Set colItems = objRefresher.AddEnum _
        (objWMIService, "Win32_PerfFormattedData_TCPIP_NetworkInterface"). objectSet
        objRefresher.Refresh



        strFileName = "C:\Program Files\Zabbix Agent\zabbix_agentd.conf"
        i=0
        Set objFS = CreateObject("Scripting.FileSystemObject")
        Set objTS = objFS.OpenTextFile(strFileName,8)
        For Each objItem in colItems

        NicDescription(i) = objItem.Name

        objTS.Write vbCrLf
        objTS.Write "PerfCounter=uNetwork.in" &i & ","& Chr(34)& "\Network Interface("& NicDescription(i) &")\Bytes Received/sec" & Chr(34) & ",60"
        objTS.Write vbCrLf
        objTS.Write "PerfCounter=uNetwork.out" &i & ","& Chr(34)& "\Network Interface("& NicDescription(i) &")\Bytes Sent/sec" & Chr(34) & ",60"
        objTS.Write vbCrLf
        i=i+1
        Next

        objTS.Close

        WScript.Quit


        ##########SCRIPT END#################
        Last edited by gospodin.horoshiy; 29-10-2008, 12:44.
        Zbx 2.0.4 on Debian and MYSQL5 on Ubuntu Server 64bit 8.04,
        200+ Win Agents, 50+ Linux Agents, 150+ Network Devices

        Comment

        • flexguy
          Junior Member
          • Sep 2008
          • 19

          #5
          Sorry about that typo in "....el=impersonate...".
          I did too adjust the script to add all IP interfaces (see below). I do have some scripting experience, and my script works perfectly without the refresh stuff. Thanks anyway for the cooperation.


          'VBS script to "almost" automatically insert PerfCounters in
          'your zabbix_agentd.conf for monitoring network traffic on a windows machine
          '
          'item in zabbix should be:
          'type: active agent
          'key: nic0_in (our nic0_out, or nic1_in, or nic1_out or .....)
          'info: float
          'translate Bytes Received/sec & Bytes Sent/sec to your locale
          'edit strFileName to your needs
          '
          Option Explicit

          Dim colAdapters, objAdapter, NicDescription, strFileName, objFS, objTS, count
          Set colAdapters = GetObject("winmgmts:{impersonationLevel=impersonat e}").ExecQuery _
          ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
          strFileName = "C:\zabbix_agentd.conf"
          Set objFS = CreateObject("Scripting.FileSystemObject")
          Set objTS = objFS.OpenTextFile(strFileName,8)
          count = 0

          For Each objAdapter in colAdapters
          NicDescription = objAdapter.Description
          objTS.Write vbCrLf
          objTS.Write "PerfCounter=nic" & count & "_in,"& Chr(34)& "\Network Interface("& NicDescription &")\Bytes Received/sec" & Chr(34) & ",60"
          objTS.Write vbCrLf
          objTS.Write "PerfCounter=nic" & count & "_out,"& Chr(34)& "\Network Interface("& NicDescription &")\Bytes Sent/sec" & Chr(34) & ",60"
          objTS.Write vbCrLf
          count = count + 1
          Next
          objTS.Close
          WScript.Quit

          Comment

          • jroberson
            Senior Member
            • May 2008
            • 124

            #6
            Never mind!! I figured out what to do and what I was doing wrong.

            I used nic0_in as a key BUT I didn't wait long enough



            ======= Ignore the rest of this!!! == I'm dumb ==

            I just tried this and it does correctly place the information in the conf file:
            Code:
            PerfCounter=nic0_in,"\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Received/sec",60
            PerfCounter=nic0_out,"\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Sent/sec",60
            AND Zabbix_agentd.exe does seem to create the "alias" as per this item in the log:
            Code:
            2268:20090312:130129 cfg: para: [PerfCounter] val [nic0_in,"\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Received/sec",60]
              2268:20090312:130129 Accepted configuration parameter: 'PerfCounter' = 'nic0_in,"\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Received/sec",60'
              2268:20090312:130129 In add_perf_counter() [name:nic0_in] [counter:\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Received/sec] [interval:60]
              2268:20090312:130130 PerfCounter nic0_in: "\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Received/sec" successfully added. Interval 60 seconds
              2268:20090312:130130 Alias added. [nic0_in] -> [__UserPerfCounter[nic0_in]]
              2268:20090312:130130 cfg: para: [PerfCounter] val [nic0_out,"\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Sent/sec",60]
              2268:20090312:130130 Accepted configuration parameter: 'PerfCounter' = 'nic0_out,"\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Sent/sec",60'
              2268:20090312:130130 In add_perf_counter() [name:nic0_out] [counter:\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Sent/sec] [interval:60]
              2268:20090312:130130 PerfCounter nic0_out: "\Network Interface(AMD PCNET Family PCI Ethernet Adapter - Packet Scheduler Miniport)\Bytes Sent/sec" successfully added. Interval 60 seconds
              2268:20090312:130130 Alias added. [nic0_out] -> [__UserPerfCounter[nic0_out]]
            BUT I cannot determine the right key to use in the frontend. All that I try comes up as not supported and I have restarted my agent (I realized that I had forgotten to do that first after a few tries ). I can't seem to find it in the documentation and I haven't found any thread that explicitly says what to use. Maybe I just missed it.

            Please, what would I use as the key in the frontend or do I have something else wrong?

            Thanks in advance
            Last edited by jroberson; 13-03-2009, 00:02. Reason: dumbness

            Comment

            • flexguy
              Junior Member
              • Sep 2008
              • 19

              #7
              what key to use

              jrobertson,

              True, after ALL changes to your agent configuration file you have to restart the agent. I did find out the hard way also...

              Did you use the settings described in the first few lines of the script:
              type: zabbix agent (active)
              key: nic0_in
              type of info: float

              some pitfalls as why this won't work:

              - hostname in conf is not exactly the same as the hostname in zabbix server
              - active agent is not enabled on monitored host
              - firewall rules prevent active agent from connecting to server

              I guess the whole thing works in passive mode too (didn't try yet)

              Good luck,

              Comment

              Working...