Knowledge about Linux SNMP and RRD database updates

Source: Internet
Author: User
Tags rrd rrdtool snmp snmpget snmpwalk mrtg

After a long time studying Linux SNMP, you may encounter a Linux SNMP problem. Here we will introduce how to solve the Linux SNMP problem RRD database update instance.

In Quick Start 1), we have introduced the update command: it uses one or more parameters in the format ::. if you know that you can use N to represent the current time, you will be happy. Alternatively, you can use the time function in Perl to specify the time: perl-e 'print time, "\ n" 'Shell: how to run a program on different operating systems at a fixed interval of date + % s.

However, the pseudo code can be used for representation:-Get the value and put it in variable "$ speed"-rrdtool update speed. rrd N: $ speed. Run the above script every five minutes. Run the above example when you want to know what the image looks like. You can put them in a script. Run this script to view the graph we just created.

Knowledge about Linux SNMP

I can imagine that only a few people can read real data from their cars every 5 minutes. Others have to Clear Counters of other types. You can measure the number of pages printed by the printer, the number of coffee cups made by the coffee maker, and the current used for calculation.

An incremental counter can be monitored and drawn into an image using the methods you have learned. Later we will be able to monitor values like thermometers. Most people interested in RRDtool use a counter that tracks the data volume transmitted by network devices. In this way, we will do this next step. We will start by explaining how to collect data.

Some may say that some tools can help you collect data. They are right! However, I feel that these tools are not essential. When you can determine why something went wrong, you need to know how they work. The tool used in this example is short mentioned earlier in this document. It is called Linux SNMP. It is used to communicate with connected devices. The tool used below is Linux SNMPget. The following describes how it works:

For Linux SNMPget device password OID or Linux SNMPget-v [version]-c [password] device OID, replace it with the device name or IP address. For password, you need to replace it with a comunity read string in the Linux SNMP field.

For some devices, the default public can work, but this setting may be disabled, adjusted, or protected for security and confidentiality reasons. Read your device or program documentation. Next, a parameter called OID is used to represent the object identifier.

It seems confusing when I first started learning Linux SNMP. When you see the MIB management information base, it is not that difficult. MIB is an inverted tree used to describe data. It has only one root-knot point and has multiple branches starting from the root node. These branches end with another node, and they continue to go down to the branch.

Therefore, each branch has a name, which forms a path that we can follow down. The branches we are following are named iso, org, dod, internet, mgmt and mib-2. these names can also be recorded in numbers, like 1 3 6 1 2 1. dod. internet. mgmt. mib-2 ( Some programs use leading points .., which is confusing. There is no leading point in an OID. To show the differences between the OID contraction method and the complete OID recording method, it is usually agreed that the leading point is used when the complete OID recording method is used.

Usually, when these programs return data to you, they will omit the missing part. These programs have several default prefixes, which makes things worse. OK, lets continue to the start of our OID: we had From there, we are especially interested in the branch interfaces which has number 2 (e.g., or ).

Now, let's continue with the preliminary study of OID: we have an OID of, which we are particularly interested in) interface branch. Its number is 2 For example: or ).

First, we need to have several Linux SNMP programs. First, check whether your OS platform has compiled software packages. This is the most convenient way. If not, you have to download the source code and compile it. Source code and programs are everywhere on the Internet. You can use any method you like and search engines to find relevant information.

Suppose you already have these programs. First, try to collect data from most systems. Remember: For the trees that interest us, the above section has a simple name. Here I will provide an example available on the Fedora Core 3 operating system. If your operating system is unavailable, check the Linux SNMP manual and make corresponding adjustments to make it run.

Linux SNMPget-v2c-c public myrouter system. sysDescr.0 the device should respond to its own description, which may be empty. You can continue only after you get a response from a device. You may need to use different passwords or devices.

Linux SNMPget-v2c-c public myrouter interfaces. ifNumber.0 you 'd better get a number. In this case, you can continue and try another program named Linux SNMPwalk. Linux SNMPwalk-v2c-c public myrouter interfaces. ifTable. ifEntry. ifDescr if the command returns a series of interfaces, this is correct. The following is an example of the result returned by the command:

  1. [user@host /home/alex]$ Linux SNMPwalk -v2c -c public cisco  
  2. interfaces.ifTable.ifEntry.ifDescr.1 = "BRI0: B-Channel 1" 
  3. interfaces.ifTable.ifEntry.ifDescr.2 = "BRI0: B-Channel 2" 
  4. interfaces.ifTable.ifEntry.ifDescr.3 = "BRI0" Hex: 42 52 49 30  
  5. interfaces.ifTable.ifEntry.ifDescr.4 = "Ethernet0" 
  6. interfaces.ifTable.ifEntry.ifDescr.5 = "Loopback0" 

For cisco devices, I want to monitor the 'ethernet0' interface. From the above output, we can see that the interface number is 4. Run the following command: [user @ host/home/alex] $ Linux SNMPget-v2c-c public cisco

  1. interfaces.ifTable.ifEntry.ifInOctets.4 = 2290729126 
  2. interfaces.ifTable.ifEntry.ifOutOctets.4 = 1256486519 

In this way, I have two OID types that need to be monitored. They use the complete log method this time ):
Both and have interface number 4.

Don't be fooled. I just did it once. I spent some data to figure out what these numbers mean. It is helpful to convert these numbers into descriptive text... At least when you talk about MIB and OID, you know what they are. Do not forget the interface number. If it is not a subsidiary interface, it is 0). If Linux SNMPget does not receive a response, try Linux SNMPwalk.

RRDtool application instance

Let's start with interesting examples. First, create a new database. It contains data of two counters: input and output. The data is put into an archive that can be averaged. They use 1, 6, 24, or 288 samples at a time. They are stored in the archive storing the largest number at the same time. I will explain it later. The sample interval is 300 seconds, that is, 5 minutes, which is a good start. :

  1. The "average" of one sample is retained for 5 minutes.
  2. 6 samples are averaged every 30 minutes.
  3. 24 samples are averaged every two hours.
  4. 288 samples are averaged once every day

We try to be compatible with MRTG. MRTG stores the following data ::

  1. 600 5-minute sample count: 2 days and 2 hours
  2. 600 30-minute samples: 12.5 days
  3. 600 2-hour samples: 50 days
  4. 732 number of samples per day: 732 days

These ranges are supplemented, so the total number of data stored in the database is about 797 days. RRDtool stores different data. It does not start to archive each week where the archive is stopped on a daily basis. For these two archives, the latest data will be near now, so we need to save more data than MRTG! We need ::

  1. 600 5-minute samples for 2 days and 2 hours)
  2. 700 30-minute samples for 2 days and 2 hours, plus 12.5 days)
  3. 775 samples of 2 hours above + 50 days)
  4. 797 samples for one day (for the above + 732 days, the maximum Cycle cycle is 797)
  1. rrdtool create myrouter.rrd \  
  2. DS:input:COUNTER:600:U:U \  
  3. DS:output:COUNTER:600:U:U \  
  4. RRA:AVERAGE:0.5:1:600 \  
  5. RRA:AVERAGE:0.5:6:700 \  
  6. RRA:AVERAGE:0.5:24:775 \  
  7. RRA:AVERAGE:0.5:288:797 \  
  8. RRA:MAX:0.5:1:600 \  
  9. RRA:MAX:0.5:6:700 \  
  10. RRA:MAX:0.5:24:775 \  
  11. RRA:MAX:0.5:288:797 

The next step is to collect and save the data. The following is an example. It is written in pseudo code, and you have to adjust it according to the OS so that it can run. :

  1. while not the end of the universe  
  2. do  
  3. get result of  
  4. Linux SNMPget router community  
  5. into variable $in  
  6. get result of  
  7. Linux SNMPget router community  
  8. into variable $out  
  9. rrdtool update myrouter.rrd N:$in:$out  
  10. wait for 5 minutes  
  11. done 

After collecting the data for one day, try to use the following command to create an image ::

  1. rrdtool graph myrouter-day.png --start -86400 \  
  2. DEF:inoctets=myrouter.rrd:input:AVERAGE \  
  3. DEF:outoctets=myrouter.rrd:output:AVERAGE \  
  4. AREA:inoctets#00FF00:"In traffic" \  
  5. LINE1:outoctets#0000FF:"Out traffic" 

This generates an image with a 1-day streaming value. 1 day with 24 hours) x60 minutes) x60 seconds ). We start from the current time-86400 seconds. We use DEF to define the number of input and output bytes as the average value in the myrouter. rrd database, and draw the input traffic zone and output traffic line.

  1. Linux openmosix hardware configuration and installation steps
  2. Handling of Linux VMware installation failure
  3. Linux disk management commands
  4. Check whether the Linux Samba client and server are installed
  5. Open-source implementation of running applications in Linux Hadoop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.