Wednesday, February 15, 2006

OpenBSD libstatgrab

Googling without directions get me to this page, and I learn that this is cool tool to do the same thing like top command but with different kind of monitoring functions, I quickly download the source to try out, the developer of the tool even provide OpenBSD unofficial port which is version 0.11 but I decide to compiled the latest source which is 0.12, it get compiled without problem and I decide to run it instantly to see what it actually offers after quickly finish reading it's manual. There are 2 binaries and 2 perl scripts installed once you finish installing it which are

shell>ls -la /usr/local/stow/libstatgrab-0.12/bin
-rwxr-xr-x 1 root wheel 50600 Feb 15 22:07 saidar
-rwxr-xr-x 1 root wheel 52335 Feb 15 22:07 statgrab
-rwxr-xr-x 1 root wheel 7060 Feb 15 22:07 statgrab-make-mrtg-config
-rwxr-xr-x 1 root wheel 2387 Feb 15 22:07 statgrab-make-mrtg-index

Saidar is the tool to view and monitor system statistic, statgrab provides a sysctl-style interface to all the system statistics available through libstatgrab, statgrab-make-mrtg-config allows you to generate MRTG configuration file and statgrab-make-mrtg-index is used to generate an XHTML index page from MRTG configuration files.

To run saidar, just

shell>/usr/local/bin/saidar

It looks cool :)

Considering this is Server01, so I generate the mrtg configuration file Server01 using statgrab-make-mrtg-config.

shell>statgrab-make-mrtg-config \
--workdir /nsm/statgrab-mrtg/Server01 \
--statgrab /usr/local/bin/statgrab > /etc/statgrab-Server01.cfg

Checking the statgrab mrtg config file if there's any error, if it exits without error that means config file is generated correctly. Make sure you have mrtg installed, if not just install from package or port will do.

shell>mrtg --check /etc/statgrab-Server01.cfg

Create the config file in html format that base on the libstatgrab,

shell>statgrab-make-mrtg-index --title Server01 \
/etc/statgrab-Server01.cfg > /nsm/statgrab-mrtg/Server01/Server01.html

Now I just query the Server01 and also create the first mrtg trafic graphs and webpages. When you run mrtg for the first time there will be a lot of complaints about missing log files. Don't worry, this is normal for the first 2 times you start mrtg. If it keeps complaining after this time you might want to look into the problem.

shell>mrtg /etc/statgrab-Server01.cfg

All the mrtg file will be generated under /nsm/statgrab-mrtg/Server01/

Finally I just add the mrtg command to run it every 5 minutes to generate mrtg report.

shell>crontab -e

Put this line in crontab

*/5 * * * * /usr/local/mrtg /etc/statgrab-Server01.cfg --logging /var/log/mrtg-Server01.log

I'm done with it now and here's my MRTG output after sometimes.




Libstatgrab is one nifty monitoring tool, you can feed this data to your web server and browsing through http :]

2 comments:

Anonymous said...

libstatgrab is nice because it provide an abstract interface to retreive information about your system be it gnu/linux or any bsd-variant operating system.

I even subscribed to its project release announcement at freshmeat, and occasionaly use pystatgrab to write trivial script to obtain various statistic about my machine.

C.S.Lee said...

cool mypapit, I haven't installed it's python api which is pystatgrab yet and plan to try it when I have spare time.