[Reprinted] rrdtool Chinese manual-Quick Start (2)

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

Iii. 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. Or you can use the time function in Perl to specify the time:
    Perl: Perl-e 'print time, '\ n "'
    Shell: date + % s
    How to run a program at a fixed interval varies with operating systems. However, the pseudo code can be used for representation:
    -Get the value and put it in variable "$ speed"
    -Rrdtool update speed. rrd n: $ speed

    That's all. 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.

4. SNMP knowledge

    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 SNMP. It is used to communicate with connected devices.

The tool used below is named snmpget. The following describes how it works:

Snmpget device password OID
Or
Snmpget-V [version]-C [Password] device OID
    For device, you must replace it with the device name or IP address. For password, you need to replace it with a Comunity read string in the 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 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.
    Iso.org. DOD. Internet. Mgmt. mib-2 (1.3.6.1.2.1)

    Some programs use leading points, which is confusing. There is no leading point in an oId. In order to display the differences between the oId contraction method and the complete OID recording method, (usually agreed) use the leading point when using the complete OID recording method. 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 1.3.6.1.2.1 from there, we are especially interested in the branch interfaces which has number 2 (e.g., 1.3.6.1.2.1.2 or 1.3.6.2.1.interfaces ).

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

    First, we need several 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 SNMP manual and make corresponding adjustments to make it run.

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.
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 snmpwalk.

Snmpwalk-v2c-C public myrouter interfaces. iftable. ifentry. ifdescr
    If this command returns a series of interfaces, this is correct. The following is an example of the result returned by the command:
[User @ host/home/Alex] $ snmpwalk-v2c-C public Cisco 2.2.1.2
Interfaces. iftable. ifentry. ifdescr.1 = "bri0: B-Channel 1"
Interfaces. iftable. ifentry. ifdescr.2 = "bri0: B-Channel 2"
Interfaces. iftable. ifentry. ifdescr.3 = "bri0" HEX: 42 52 49 30
Interfaces. iftable. ifentry. ifdescr.4 = "ethernet0"
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. I tried to run the following command:
[User @ host/home/Alex] $ snmpget-v2c-C public Cisco 2.2.1.10.4 2.2.1.16.4

Interfaces. iftable. ifentry. ifinoctets.4 = 2290729126
Interfaces. iftable. ifentry. ifoutoctets.4 = 1256486519

    In this way, I have two OID types to monitor. They are (this time using the complete log method ):
    1.3.6.1.2.1.2.2.1.10
    And
    1.3.6.1.2.1.2.2.1.16
    Both OID IDs 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 snmpget does not receive a response, try snmpwalk.

V. rrdtool application instance

    Practical examples
    Let's get started with interesting things. 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. :

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

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

    600 5-minute sample count: 2 days and 2 hours
    600 30-minute samples: 12.5 days
    600 2-hour samples: 50 days
    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 ::

    600 5-minute samples (2 days and 2 hours)
    700 30-minute samples (2 days and 2 hours, plus 12.5 days)
    775 samples for 2 hours (above + 50 days)
    797 samples for one day (for the above + 732 days, the maximum Cycle cycle is 797)

Rrdtool create myrouter. RRD \
DS: input: Counter: 600: U \
DS: Output: Counter: 600: U \
RRA: average: 0.5: 1: 600 \
RRA: average: 0.5: 6: 700 \
RRA: average: 0.5: 24: 775 \
RRA: average: 0.5: 288: 797 \
RRA: Max: 0.5: 1: 600 \
RRA: Max: 0.5: 6: 700 \
RRA: Max: 0.5: 24: 775 \
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. :

While not the end of the universe
Do
Get result
Snmpget router community 2.2.1.10.4
Into variable $ in
Get result
Snmpget router community 2.2.1.16.4
Into variable $ out

Rrdtool update myrouter. rrd n: $ in: $ out

Wait for 5 minutes
Done

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

Rrdtool graph myrouter-day.png -- start-86400 \
Def: inoctets = myrouter. RRD: input: Average \
Def: outoctets = myrouter. RRD: Output: Average \
Area: inoctets #00ff00: "In traffic "\
Line1: outoctets # 0000ff: "Out traffic"

This generates an image with a 1-day streaming value. 24 (hours) x 60 (minutes) x 60 (seconds) in one day ). 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.

Related Article

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: info-contact@alibabacloud.com 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.