Recimo, da imamo na omrežju veliko množico računalnikov. Radi bi nadzorovali, koliko prostora je na diskih, kakšne so temperature procesorjev in hitrosti vrtenja ventilatorjev.

Prva možnost je seveda ta, da zaposlimo kurirčka, ki bo tekal od računalnika do računalnika in prebiral podatke.

Druga možnost je, da uporabimo SNMP.

Vaša naloga je, da omogočite drugim računalnikom branje podatkov o stanju svojega. Poleg tega si morate namestiti vsaj en program za grafično pregledovanje statističnih podatkov o stanju oddaljenih računalnikov.


Ogledali si bomo, kako lahko pregledamo statistiko različnih performančnih metrik s pomočjo protokola SNMP.

Situacijo bomo simulirali tako, da bo vsakdo v učilnici omogočil vsem ostalim dostop do omenjene statistike na svojem računalniku. Za nadzor bomo uporabili široko uporabljano orodje munin, ki omogoča pregledovanje različnih grafov s prikazom statistik preko spletnega vmesnika.

Začnimo z namestitvijo SNMP agentov in orodij za pregledovanje podatkov, dostopnih preko SNMP:

sudo apt-get install snmpd snmp snmp-mibs-downloader

Na starejših različicah Ubuntu snmp-mibs-downloader ne obstaja in ga ni potrebno namestiti.

Nastavitve SNMP agentov lahko spremenimo v konfiguracijski datoteki:

sudo gedit /etc/snmp/snmpd.conf

Za potrebe vaj bomo popravili konfiguracijo tako, da bo računalnik dovolil dostop vsem ostalim računalnikom.

#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161

Dodati bo treba tudi skupino (community) računalnikov, za katere smatramo, da lahko dostopajo do vseh podatkov. Skupino bomo poimenovali studentje:

rocommunity studentje 0.0.0.0/0

Niže v taisti datoteki lahko nastavite tudi to, kje se računalnik nahaja ter e-mail naslov skrbnika. Dodamo lahko tudi dodatne agente - primer je podan v datoteki:

extend    test1   /bin/echo  Hello, world!

Če primera test1 v datoteki ne vidite, ga ni potrebno prepisovati. Po vsaki spremembi konfiguracije strežnik ponovno zaženemo:

sudo /etc/init.d/snmpd restart

Na starejših različicah snmpd v nekaterih primerih že privzeto posluša na vseh vmesnikih. Če ne, je potrebno agentaddress nastaviti v skladu z navodili v:

man snmpd
man snmpd.conf

Če vam agentaddress v /etc/snmp/snmpd.conf še vedno ne deluje, je mogoče, da je snmpd zagnan tako, da je naslov, na katerem naj posluša, naveden že kot argument programu. To lahko preverite tako, da pogledate datoteko:

NEKEDITOR /etc/default/snmpd

Če med argumenti vidite naslov 127.0.0.1, ga pobrišite, sicer se bo snmpd pritožil, če naleti na isti naslov v konfiguracijski datoteki snmpd.conf.

Za pregled podatkov, dostopnih preko SNMP, uporabimo program snmp-walk:

snmpwalk -c public -v 1 neknaslov

Tukaj lahko preizkusite, ali vam deluje dostop do sosedovega računalnika. Za dostop do lastnega uporabite naslov localhost.

Da bi prišli do res vseh podatkov, ki jih računalnik daje na voljo, moramo izbrati drugo skupino (community). Če želimo izpis podatkov od nekega OID naprej, to nastavimo. Če se skupina, ki ima dostop do vseh spremenljivk, imenuje studentje in če bi radi imena lastnosti izpisali v bolj človeškem formatu (-m ALL):

snmpwalk -m ALL -c studentje -v 1 neknaslov nekOID

Za dostop do podatkov o temperaturi računalnika potrebujemo paket lm-sensors. Za nastavljanje hitrosti vrtenja ventilatorja si namestite paket fancontrol:

sudo apt-get install lm-sensors fancontrol

Da bi bili podatki, odčitani s senzorjev, dostopni preko SNMP, boste morali na internetu poiskati primeren MIB. Potem boste morali ugotoviti, kje v hierarhiji mibov se skrivajo vrednosti senzorjev. Verjetno boste iskanje začeli pri OID 1. Pri tem si lahko pomagate z ukazom less:

snmpwalk -v 1 -c studentje neknaslov 1 | less

V less iščemo s tipko "/", za izhod uporabimo "q". Namesto less lahko besede v izpisanem tekstu iščemo tudi z grep ali na poljuben drug način. Da bi prišli do vrednosti za posamezen OID, namesto snmpwalk uporabimo snmpget:

snmpget -v 1 -c studentje -Oqv neknaslov NEKOID 

Za grafično pregledovanje podatkov lahko uporabimo spletno orodje Munin:

sudo apt-get install munin apache2

Munin je zgrajen okrog orodja RRDTOOL. Za pravilno ustvarjanje grafov si lahko ogledate dokumentacijo rrdtool.

Da bi o sistemu lahko zbrali še več podatkov, lahko namestimo še paket collectd:

sudo apt-get install collectd

Konfiguracija se kot običajno nahaja v /etc:

sudo gedit /etc/collectd/collectd.conf

Collectd v povezavi z dodatnimi aplikacijami, prav tako omogoča izris grafov.


Suppose we have a large number of computers on a network. We want to control the available disk space, the temperature of the CPU in each computer and the RPMs of each fan.

To do that, the first option would be to employ a bell-hop who will run from one computer to the next and record the data manually.

The second option would be SNMP.

Your task is to enable other computers to access information regarding your own computer's state. You also have to install at least one program which allows you to monitor statistical data regarding remote computers through a graphical interface.


Let's take a look at how we can monitor the statistics of various performance metrics using the SNMP (simple network management protocol).

We will simulate a realistic situation by having each student in the classroom allow access to the abovementioned metrics on his or her computer. To monitor the statistics, we will use a widely used tool called munin which allows you to monitor various graphs through a web interface.

Let's start by setting up the SNMP agents and tools for inspecting the data available over SNMP:

sudo apt-get install snmpd snmp snmp-mibs-downloader

On older versions of Ubuntu, snmp-mibs-downloader does not exist so you do not have to install it.

The settings for SNMP agents can be changed by editing the config file:

sudo gedit /etc/snmp/snmpd.conf

For todays lecture, we will change the configuration so that the computer will allow all other computers to access it:

#  Listen for connections from the local system only
#agentAddress  udp:127.0.0.1:161
#  Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161

We also have to add a group (community) of computers we deem to be worthy of accessing all data. This group will be called studentje:

rocommunity studentje 0.0.0.0/0

Lower in the same file, one can also set the location of the computer snmpd is running on and the name of the administrator. We can also add additional agents - the example is listed lower in the file:

extend    test1   /bin/echo  Hello, world!

If you don't see the test1 example in the file, you don't have to copy it from here. After each configuration change, restart the server:

sudo /etc/init.d/snmpd restart

On older versions of debian/ubuntu, snmpd listens on all interfaces by default. If this is not the case on your computer, you have to change the agentaddress according to the instructions found in:

man snmpd
man snmpd.conf

If the agentaddress in /etc/snmp/snmpd.conf still doesn't work for you, it is possible that snmpd is already getting the address it's supposed to be listening on as it's command-line argument. You can check this by looking at a file:

SOMEEDITOR /etc/default/snmpd

If you see the address 127.0.0.1, remove it. Otherwise, snmpd will complain if it sees the same address in snmpd.conf.

To inspect the data available over SNMP, one can use snmp-walk:

snmpwalk -c public -v 1 someaddress

At this point you can check whether you can access your computer's address. To access your own, you can use the address localhost.

If you want to access all the data that is being made available by the computer, you have to change a communiti which is some other than the default one. To access the data from some OID onwards, we can set it by specifying the OID. If the community which has access to all the available data is called studentje and if you want to display the data in a more human-friendly format (-m ALL), run:

snmpwalk -m ALL -c studentje -v 1 neknaslov nekOID

To access the data regarding CPU temperature, we need to install the package lm-sensors. To set the speed of the CPU fan, you need to install the package fancontrol:

sudo apt-get install lm-sensors fancontrol

To make the data from the sensors available over SNMP, you have to find the right MIB on the Internet. Then, you have to find out where in the MIB hierarchy the sensor values ale hidden. You will probably start your search at OID 1. You can use the less command to make your life easier:

snmpwalk -v 1 -c studentje neknaslov 1 | less

Use the "/" key for searching, "q" to quit in less. Instead of using less, you can also use the grep command or some other way to search for the relevant words. To access the value for an individual OID, one can use snmpget instead of snmpwalk:

snmpget -v 1 -c studentje -Oqv neknaslov NEKOID 

For graphical monitoring of data, we can use Munin:

sudo apt-get install munin apache2

Munin is build around a tool called RRDTOOL. To learn more about how to properly create graphs, read the rrdtool documentation.

To collect even more data regarding the system, we can install the collectd package:

sudo apt-get install collectd

As usual, the configuration files are located in /etc:

sudo gedit /etc/collectd/collectd.conf

Collectd together with other applications also allows you to create graphs.

Zadnja sprememba: petek, 12. december 2014, 18:35