Custom Monitoring MySQL and SNMP with BixData - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by Jed (Contact Author) (Forums) on Mon, 2007-01-29 18:47. ::

Example 3: Collecting SNMP Data

Overview

Basically all SNMP devices have an interface table that gives you basic statistics on bytes sent and received link status (up/down), link speed, etc. You get snmp values from a device by issuing a command like

snmpget -v1 -c public hostname OID

Where hostname is the name of the snmp device and OID is the special SNMP string.

First let's make a script that can query SNMP devices for Interface statistics (bytes in and out). I will be using snmpget from Net-SNMP and python. But you could use perl and other SNMP modules.

You can get the latest script from http://bixdata.com/addons. It is BSD license which means you are free to use and expand it.

At the top of the script there is a list of hosts and Interface IDs that you can replace with your own. To find out what interface IDs your host has, issue the following command:

snmpwalk -v 1 -c public hostname interfaces.ifTable.ifEntry.ifDescr

Here is the section in bixsnmp.py:

hostIntf = { "192.168.1.11" : 19, "192.168.1.12" : 18415 }

As you can see I am getting stats on interface 19 on 192.168.11 and interface 18415 on 192.168.1.12. You can add as many hosts and interfaces as you want. The rest of the script simply executes the snmpget command to get the data and outputs it in this format:

host : 192.168.1.12
interface : 18415
in : 1441849
out : 317351

host : 192.168.1.11
interface : 19
in : 10540
out : 1395103

SNMP Step 1

Download the bixsnmp.py script from http://www.bixdata.com/addons and copy it to bixagent/data/scripts.

SNMP Step 2

Do an snmpwalk on your SNMP devices to determine their interface IDs.

snmpwalk -v 1 -c public hostname interfaces.ifTable.ifEntry.ifDescr

The output will look like this:

IF-MIB::ifDescr.1 = STRING: Switch Port 1
IF-MIB::ifDescr.200 = STRING: Switch Port 200

Here the '.1' and '.200' are the IDs. So edit bixsnmp.py and add those ids:

hostIntf = { "hostname" : 1, "hostname" : 200 }

SNMP Step 3

Next run the script to make sure it works.

cd bixagent/data/scripts
python bixsnmp.py

SNMP Step 4

Add the script to bixagent/data/xml/dp-import.xml.

<Script>
  <namespace>BixSNMP</namespace>
  <path>python data/scripts/bixsnmp.py</path>
  <instance>host</instance>
  <key>interface</key>
  <version>v1</version>
  <Field>
    <name>in</name>
    <type>schema_uint64</type>
  </Field>
  <Field>
    <name>out</name>
    <type>schema_uint64</type>
  </Field>
</Script>

This tells BixData what fields to expect.

SNMP Step 5

In BixDesktop connect to your BixAgent and under real-time graph choose 'Custom'. Navigate to the BixSNMP namespace and add the counters you want to see.


Navigating SNMP data

In/out are cumulative while rate is the rate over the sample period. The following screenshot shows an example of realtime data:


Real-time graph of SNMP data

All other components in BixData such as Service Checks and Notifications will now work with SNMP.

SNMP Step 6

Next we want to create graphs. You can download the graph used in this example and copy it to bixserver/data/reporting/templates/, or you can follow these steps to create a graph.

Connect to your BixServer and then:

  • Go to Reporting, Setup Templates
  • Click the + button and select New Graph
  • Enter a reportName and description
  • Click on the big + button next to streams to browse for streams. You can add as many streams as you want.
  • Click 'Save changes Yes' and you can add the report to your Report Setup


Hopefully this gives you an idea of the flexibility of BixData. As you can see it is an easy tool to use and extend that should be able to adapt to your particular monitoring needs. Once you have a script that produces data, the chore of collecting, storing and visualizing data is taken care of by BixData. You can download some of the scripts from their site http://www.bixdata.com/addons, and since the scripts are BSD license you can make them your own.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.