В этой заметке хочу описать один из вариантов использования набора графических утилит RRDtool, для мониторинга системных ресурсов и загруженности на сетевых интерфейсах. Итак, приступим к установке.
Для отрисовки графиков необходимо установить RRDtool:
[root@router /]# cd /usr/ports/databases/rrdtool12
[root@router /usr/ports/databases/rrdtool12]# make config
В окне «Options for rrdtool 1.4.4» выбираем:
[X] MMAP Use mmap in rrd_update
[X] PERL_MODULE Build PERL module
[root@router /usr/ports/databases/rrdtool12]# make install clean
############################################################################
# See /usr/local/share/examples/rrdtool for some demonstration code #
############################################################################
===> Compressing manual pages for rrdtool-1.4.4
===> Running ldconfig
/sbin/ldconfig -m /usr/local/lib
===> Registering installation for rrdtool-1.4.4
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/bin/rrdcached
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type ‘make deinstall’
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
http://www.rrdtool.org/
===> Cleaning for pango-1.28.3
===> Cleaning for rrdtool-1.4.4
[root@srv /usr/ports/databases/rrdtool]#
Для сбора статистики об использовании ресурсов системы я решил, вместо самописных скриптов, использовать демон «Collectd«.
[root@srv /usr/ports]# cd /usr/ports/net-mgmt/collectd
[root@srv /usr/ports/net-mgmt/collectd]# make config
Options for collectd 4.9.3_1
[X] INTERFACE Input: Network interfaces (libstatgrab)
[X] PING Input: Network latency (liboping)
[X] RRDTOOL Output: RRDTool
[root@srv /usr/ports/net-mgmt/collectd]# make install clean
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/lib/collectd/unixsock.so
/usr/local/lib/collectd/email.so
This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/collectdmon
/usr/local/etc/rc.d/collectd
If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type ‘make deinstall’
to deinstall the port if this is a concern.
For more information, and contact details about the security
status of this software, see the following webpage:
http://www.collectd.org/
===> Cleaning for libstatgrab-0.17
===> Cleaning for liboping-0.3.5
===> Cleaning for collectd-4.9.3_1
[root@srv /usr/ports/net-mgmt/collectd]#
Добавим его в /etc/rc.conf для автостарта:
collectd_enable=»YES»
Запускаем:
[root@srv /usr/local/etc/rc.d]# ./collectd start
Starting collectd.
[root@srv /usr/local/etc/rc.d]#
После загрузки увидим в /var/lib/collectd/router.local, где «router.local» моя переменная с hostname, свежесозданные базы *.rrd.
Создадим недостающую директорию в /usr/local/www для Apache:
[root@srv /]#mkdir /usr/local/www/graph
Теперь можно переходить к самому скрипту, который будет генерировать графики:
[root@srv /]#cat /mnt/mon.sh
#!/usr/local/bin/bash
/usr/local/bin/rrdtool graph /usr/local/www/graph/cpu0.png \
-e now \
-s ‘end — 6 hours’ \
-S 60 \
—title «CPU USAGE: Intel Atom230 1.6Ghz» \
—vertical-label «Percents» \
—imgformat PNG \
—slope-mode \
—lower-limit 0 \
—upper-limit 100 \
—rigid \
-E \
-i \
—color SHADEA#FFFFFF \
—color SHADEB#FFFFFF \
—color BACK#CCCCCC \
-w 600 \
-h 150 \
—interlaced \
—font DEFAULT:8:/usr/local/share/rrdtool/fonts/ARIAL8.TTF \
DEF:a=/var/lib/collectd/router.local/cpu-0/cpu-idle.rrd:value:MAX \
DEF:b=/var/lib/collectd/router.local/cpu-0/cpu-system.rrd:value:MAX \
DEF:c=/var/lib/collectd/router.local/cpu-0/cpu-user.rrd:value:MAX \
LINE2:b#2cc320: \
AREA:b#54eb48:System \
LINE2:c#e7ad4a: \
AREA:c#ebd648:User
#LINE1:a#CCCCCC:Idle \
/usr/local/bin/rrdtool graph /usr/local/www/graph/network0.png \
-e now \
-s ‘end — 6 hours’ \
-S 60 \
—title ‘Traffic on ext_if: ng0 (25Mb/s)’ \
—vertical-label ‘Mbyte\s’ \
—imgformat PNG \
—slope-mode \
—lower-limit 0 \
—upper-limit 3500000 \
—rigid \
-E \
-i \
—color SHADEA#FFFFFF \
—color SHADEB#FFFFFF \
—color BACK#CCCCCC \
-w 600 \
-h 150 \
—interlaced \
—font DEFAULT:8:/usr/local/share/rrdtool/fonts/ARIAL8.TTF \
DEF:a=/var/lib/collectd/router.local/interface/if_octets-ng0.rrd:tx:MAX \
DEF:b=/var/lib/collectd/router.local/interface/if_octets-ng0.rrd:rx:MAX \
DEF:c=/var/lib/collectd/router.local/interface/if_errors-ng0.rrd:tx:MAX \
AREA:a#4169E1:Tx \
LINE2:b#2cc320: \
AREA:b#54eb48:Rx \
LINE1:c#FF0000:Errors
/usr/local/bin/rrdtool graph /usr/local/www/graph/network2.png \
-e now \
-s ‘end — 6 hours’ \
-S 60 \
—title ‘Traffic on int_if: rl0 (100Mb/s)’ \
—vertical-label ‘Mbyte\s’ \
—imgformat PNG \
—slope-mode \
—lower-limit 0 \
—upper-limit 12500000 \
—rigid \
-E \
-i \
—color SHADEA#FFFFFF \
—color SHADEB#FFFFFF \
—color BACK#CCCCCC \
-w 600 \
-h 150 \
—interlaced \
—font DEFAULT:8:/usr/local/share/rrdtool/fonts/ARIAL8.TTF \
DEF:a=/var/lib/collectd/router.local/interface/if_octets-rl0.rrd:tx:MAX \
DEF:b=/var/lib/collectd/router.local/interface/if_octets-rl0.rrd:rx:MAX \
DEF:c=/var/lib/collectd/router.local/interface/if_errors-rl0.rrd:tx:MAX \
LINE2:a#0000CD: \
AREA:a#4169E1:Tx-transmit \
LINE2:b#2cc320: \
AREA:b#54eb48:Rx-receive \
LINE1:c#FF0000:Errors
/usr/local/bin/rrdtool graph /usr/local/www/graph/memory.png \
-e now \
-s ‘end — 6 hours’ \
-S 60 \
—title ‘MEMORY USAGE: 1Gb’ \
—vertical-label ‘Mbyte’ \
—imgformat PNG \
—slope-mode \
—lower-limit 0 \
—upper-limit 1048000000 \
—rigid \
-E \
-i \
—color SHADEA#FFFFFF \
—color SHADEB#FFFFFF \
—color BACK#CCCCCC \
-w 600 \
-h 150 \
—interlaced \
—font DEFAULT:8:/usr/local/share/rrdtool/fonts/ARIAL8.TTF \
DEF:a=/var/lib/collectd/router.local/memory/memory-active.rrd:value:MAX \
DEF:b=/var/lib/collectd/router.local/memory/memory-cache.rrd:value:MAX \
DEF:c=/var/lib/collectd/router.local/memory/memory-free.rrd:value:MAX \
DEF:d=/var/lib/collectd/router.local/memory/memory-inactive.rrd:value:MAX \
DEF:e=/var/lib/collectd/router.local/memory/memory-wired.rrd:value:MAX \
LINE1:a#6959CD:active \
AREA:b#00FF00:cache \
LINE2:c#006400: \
AREA:c#00CD66:free \
AREA:d#FF1493:inactive \
LINE2:e#A52A2A: \
AREA:e#FF4500:wired
Добавим его в крон, для выполнения через каждую минуту:
[root@srv /]#cat >> /etc/crontab
*/1 * * * * root /mnt/mon.sh > /dev/null 2>&1
В /usr/local/www/graph, создадим index.php с таким содержимым:
Визуализация системных ресурсов: router.local
Теперь в браузере, увидим красивые графики:
http://router.local/graph/
Источник : http://www.unix.ck.ua/content/risuem-grafiki-s-pomoshchyu-rrdtool-collectd