使用者工具

網站工具


tech:mrtg

MRTG 安裝與應用

- 確認是否已經安裝 mrtg 套件

rpm -q mrtg

[[email protected] ~]$ rpm -q mrtg
mrtg-2.10.15-1

  • 如果沒有安裝, 就執行 yum -y install mrtg 來安裝

- 使用 snmpd 來讓 MRTG 監看網路流量

- 安裝 snmpd

rpm -q net-snmp

[[email protected] ~]# rpm -q net-snmp
net-snmp-5.1.2-11.EL4.7

  • 如果沒有安裝, 就執行 yum -y install net-snmp 來安裝

- 設定 snmpd

vi /etc/snmp/snmpd.conf

com2sec notConfigUser  default       public

group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser

view    systemview    included   .1.3.6.1.2.1.2
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
view    systemview    included   .1.3.6.1.2.1.2.2.1

access  notConfigGroup ""      any       noauth    exact  systemview none none

syslocation Taipei
syscontact Admin <[email protected]>

service snmpd restart
chkconfig snmpd on 
chkconfig --list | grep snmpd

- 使用簡單 script 來讓 MRTG 監看硬碟空間, CPU 負載..

- 設定 mrtg.cfg

  • 假設已經安裝 trysrvtool 在 /opt/trysrvtool/, 就可以在 /opt/trysrvtool/mrtg/ 底下看到相關的 scripts

cd /etc/mrtg
/opt/trysrvtool/mrtg/runcfgmaker.sh
cat localhost.cfg >> mrtg.cfg
vi /etc/mrtg/mrtg.cfg

:
### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
Options[_]: growright, bits
:
:

Target[eth1]: 3:[email protected]
SetEnv[eth1]: MRTG_INT_IP="192.168.11.250" MRTG_INT_DESCR="eth1"
MaxBytes[eth1]: 1250000000
Options[eth1]: growright
Title[eth1]: Traffic Analysis
PageTop[eth1]: <H1>Stats for our eth0:192.168.11.250 Ethernet</H1>
#
#

Target[disk_root]: `/opt/trysrvtool/mrtg/disk.pl`
MaxBytes[disk_root]: 50000000000
Options[disk_root]: gauge, nopercent, growright
YLegend[disk_root]: disk_root
ShortLegend[disk_root]: Bytes
LegendO[disk_root]: disk_root Available;
LegendI[disk_root]: disk_root Used;
Title[disk_root]: disk_root Usage
PageTop[disk_root]: <H1>disk_root usage</H1>

Target[disk_boot]: `/opt/trysrvtool/mrtg/disk.pl /boot`
MaxBytes[disk_boot]: 50000000000
Options[disk_boot]: gauge, nopercent, growright
YLegend[disk_boot]: disk_boot
ShortLegend[disk_boot]: Bytes
LegendO[disk_boot]: disk_boot Available;
LegendI[disk_boot]: disk_boot Used;
Title[disk_boot]: disk_boot Usage
PageTop[disk_boot]: <H1>disk_boot usage</H1>

Target[disk_data]: `/opt/trysrvtool/mrtg/disk.pl /data`
MaxBytes[disk_data]: 200000000000
Options[disk_data]: gauge, nopercent, growright
YLegend[disk_data]: disk_data
ShortLegend[disk_data]: Bytes
LegendO[disk_data]: disk_data Available;
LegendI[disk_data]: disk_data Used;
Title[disk_data]: disk_data Usage
PageTop[disk_data]: <H1>disk_data usage</H1>

Target[disk_backup]: `/opt/trysrvtool/mrtg/disk.pl /backup`
MaxBytes[disk_backup]: 200000000000
Options[disk_backup]: gauge, nopercent, growright
YLegend[disk_backup]: disk_backup
ShortLegend[disk_backup]: Bytes
LegendO[disk_backup]: disk_backup Available;
LegendI[disk_backup]: disk_backup Used;
Title[disk_backup]: disk_backup Usage
PageTop[disk_backup]: <H1>disk_backup usage</H1>

Target[cpuload]: `/opt/trysrvtool/mrtg/cpuload.pl` 
MaxBytes[cpuload]: 100 
Options[cpuload]: gauge, nopercent, growright 
YLegend[cpuload]: CPU loading (%) 
ShortLegend[cpuload]: % 
LegendO[cpuload]: CPU User Loading; 
LegendI[cpuload]: CPU System Loading; 
Title[cpuload]: CPU Loading
PageTop[cpuload]: <H1>CPU loading</H1> 

Target[cpuio]: `/opt/trysrvtool/mrtg/cpuio.pl`
MaxBytes[cpuio]: 100
Options[cpuio]: gauge, nopercent, growright
YLegend[cpuio]: cpuio (%)
ShortLegend[cpuio]: %
LegendO[cpuio]: cpu Idel;
LegendI[cpuio]: cpu IOWait;
Title[cpuio]: cpuio Loading
PageTop[cpuio]: <H1>cpuio loading</H1>

Target[memswap]: `/opt/trysrvtool/mrtg/memswap.pl`
MaxBytes[memswap]: 8000000000
Options[memswap]: gauge, nopercent, growright
YLegend[memswap]: Memory (Bytes)
ShortLegend[memswap]: Bytes
LegendO[memswap]: Free Memory;
LegendI[memswap]: Swap Memory;
Title[memswap]: Memory Usage
PageTop[memswap]: <H1>Memory Usage</H1>

Target[sensors]: `/opt/trysrvtool/mrtg/temper.pl sensors`
MaxBytes[sensors]: 100
Options[sensors]: gauge, nopercent, growright
YLegend[sensors]: M/B (C)
ShortLegend[sensors]: C
LegendO[sensors]: M/B Temp ;
LegendI[sensors]: M/B Temp;
Title[sensors]: M/B Temperature
PageTop[sensors]: <H1>M/B temperature</H1>

Target[ups]: `/opt/trysrvtool/mrtg/temper.pl ups`
MaxBytes[ups]: 100
Options[ups]: gauge, nopercent, growright
YLegend[ups]: UPS (C)
ShortLegend[ups]: C
LegendO[ups]: UPS Temp ;
LegendI[ups]: UPS Temp;
Title[ups]: UPS Temperature
PageTop[ups]: <H1>APC UPS temperature</H1>

Target[sata_dev_sda]: `/opt/trysrvtool/mrtg/temper.pl sata /dev/sda`
MaxBytes[sata_dev_sda]: 100
Options[sata_dev_sda]: gauge, nopercent, growright
YLegend[sata_dev_sda]: HD (C)
ShortLegend[sata_dev_sda]: C
LegendO[sata_dev_sda]: data HD Temp ;
LegendI[sata_dev_sda]: data HD Temp;
Title[sata_dev_sda]: Hard Disk Temperature
PageTop[sata_dev_sda]: <H1>Hard Disk temperature</H1>

Target[sata_dev_sdb]: `/opt/trysrvtool/mrtg/temper.pl sata /dev/sdb`
MaxBytes[sata_dev_sdb]: 100
Options[sata_dev_sdb]: gauge, nopercent, growright
YLegend[sata_dev_sdb]: HD (C)
ShortLegend[sata_dev_sdb]: C
LegendO[sata_dev_sdb]: main HD Temp ;
LegendI[sata_dev_sdb]: main HD Temp;
Title[sata_dev_sdb]: Hard Disk Temperature
PageTop[sata_dev_sdb]: <H1>Hard Disk temperature</H1>

Target[smtp]: `/opt/trysrvtool/mrtg/connection.pl 25`
MaxBytes[smtp]: 500
Options[smtp]: gauge, nopercent, growright
YLegend[smtp]: smtp connect (#)
ShortLegend[smtp]: #
LegendO[smtp]: SMTP User Connecting;
LegendI[smtp]: SMTP User Connected;
Title[smtp]: SMTP Connections
PageTop[smtp]: <H1>SMTP connections</H1>

Target[pop3]: `/opt/trysrvtool/mrtg/connection.pl 110`
MaxBytes[pop3]: 500
Options[pop3]: gauge, nopercent, growright
YLegend[pop3]: pop3 connect (#)
ShortLegend[pop3]: #
LegendO[pop3]: POP3 User Connecting;
LegendI[pop3]: POP3 User Connected;
Title[pop3]: POP3 Connections
PageTop[pop3]: <H1>POP3 connections</H1>

Target[imap]: `/opt/trysrvtool/mrtg/connection.pl 143`
MaxBytes[imap]: 500
Options[imap]: gauge, nopercent, growright
YLegend[imap]: imap connect (#)
ShortLegend[imap]: #
LegendO[imap]: IMAP User Connecting;
LegendI[imap]: IMAP User Connected;
Title[imap]: IMAP Connections
PageTop[imap]: <H1>IMAP connections</H1>

Target[mail_queue]: `/opt/trysrvtool/mrtg/filenum.pl`
MaxBytes[mail_queue]: 50000000000
Options[mail_queue]: gauge, nopercent, growright
YLegend[mail_queue]: mail_queue
ShortLegend[mail_queue]: #
LegendO[mail_queue]: mail_queue1 files;
LegendI[mail_queue]: mail_queue2 files;
Title[mail_queue]: mail_queue files
PageTop[mail_queue]: <H1>mail_queue files</H1>

Target[http]: `/opt/trysrvtool/mrtg/connection.pl 80`
MaxBytes[http]: 500
Options[http]: gauge, nopercent, growright
YLegend[http]: http connect (#)
ShortLegend[http]: #
LegendO[http]: HTTP User Connecting;
LegendI[http]: HTTP User Connected;
Title[http]: HTTP Connections
PageTop[http]: <H1>HTTP connections</H1>

Target[ssh]: `/opt/trysrvtool/mrtg/connection.pl 22`
MaxBytes[ssh]: 500
Options[ssh]: gauge, nopercent, growright
YLegend[ssh]: ssh connect (#)
ShortLegend[ssh]: #
LegendO[ssh]: SSH User Connecting;
LegendI[ssh]: SSH User Connected;
Title[ssh]: SSH Connections
PageTop[ssh]: <H1>SSH connections</H1>

Target[postgres]: `/opt/trysrvtool/mrtg/connection.pl 5432`
MaxBytes[postgres]: 500
Options[postgres]: gauge, nopercent, growright
YLegend[postgres]: psql connect (#)
ShortLegend[postgres]: #
LegendO[postgres]: PostgreSQL User Connecting;
LegendI[postgres]: PostgreSQL User Connected;
Title[postgres]: PostgreSQL Connections
PageTop[postgres]: <H1>PostgreSQL connections</H1>

Target[mysql]: `/opt/trysrvtool/mrtg/connection.pl 3306`
MaxBytes[mysql]: 500
Options[mysql]: gauge, nopercent, growright
YLegend[mysql]: msql connect (#)
ShortLegend[mysql]: #
LegendO[mysql]: MYSQL User Connecting;
LegendI[mysql]: MYSQL User Connected;
Title[mysql]: MYSQL Connections
PageTop[mysql]: <H1>MYSQL connections</H1>

Target[domain]: `/opt/trysrvtool/mrtg/connection.pl 53`
MaxBytes[domain]: 500
Options[domain]: gauge, nopercent, growright
YLegend[domain]: dns connect (#)
ShortLegend[domain]: #
LegendO[domain]: domain User Connecting;
LegendI[domain]: domain User Connected;
Title[domain]: domain Connections
PageTop[domain]: <H1>domain connections</H1>

Target[ntp]: `/opt/trysrvtool/mrtg/connection.pl 123`
MaxBytes[ntp]: 500
Options[ntp]: gauge, nopercent, growright
YLegend[ntp]: ntp connect (#)
ShortLegend[ntp]: #
LegendO[ntp]: NTP User Connecting;
LegendI[ntp]: NTP User Connected;
Title[ntp]: NTP Connections
PageTop[ntp]: <H1>NTP connections</H1>

Target[upsload]: `/opt/trysrvtool/mrtg/apcups.pl`
MaxBytes[upsload]: 100
Options[upsload]: gauge, nopercent, growright
YLegend[upsload]: upsload (%)
ShortLegend[upsload]: %
LegendI[upsload]: ups load;
LegendO[upsload]: bat capacity;
Title[upsload]: UPS Loading
PageTop[upsload]: <H1>APC UPS Loading</H1>

Target[upsvolts]: `/opt/trysrvtool/mrtg/apcups.pl "LINEV    :,OUTPUTV"`
MaxBytes[upsvolts]: 200
Options[upsvolts]: gauge, nopercent, growright
YLegend[upsvolts]: ups volts
ShortLegend[upsvolts]: VAC
LegendI[upsvolts]: Utility Voltage;
LegendO[upsvolts]: Output Voltage;
Title[upsvolts]: UPS Voltage
PageTop[upsvolts]: <H1>APC UPS Voltage</H1>

Target[upsother]: `/opt/trysrvtool/mrtg/apcups.pl "TIMELEFT,BATTV    :"`
MaxBytes[upsother]: 100
Options[upsother]: gauge, nopercent, growright
YLegend[upsother]: ups others
ShortLegend[upsother]: min/vdc
LegendI[upsother]: Time Left;
LegendO[upsother]: Bat Voltage;
Title[upsother]: UPS Others
PageTop[upsother]: <H1>APC UPS Others</H1>

- 啟動 mrtgd

- 確認 /opt/trysrvtool/mrtg 內的 script 要設定可執行

cd /opt/trysrvtool/mrtg
chmod a+x *

  • 測試執行兩次 /opt/trysrvtool/mrtg/runmrtg.sh, 第一次會出現一些 Rateup WARNING:…, 第二次應該就不會出現

/opt/trysrvtool/mrtg/runmrtg.sh
/opt/trysrvtool/mrtg/runmrtg.sh

- 設定每五分鐘執行一次

vi /etc/cron.d/mrtg

*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

service crond restart

- 設定透過 web 可以看到結果

vi /etc/httpd/conf.d/mrtg.conf

Alias /mrtg /var/www/mrtg

<Location /mrtg>
#    Order deny,allow
#    Deny from all
#    Allow from 127.0.0.1
#    Allow from ::1
    # Allow from .example.com
</Location>

service httpd restart

  • 在 /var/www/mrtg/ 底下產生 index.html

/opt/trysrvtool/mrtg/runindex.sh

tech/mrtg.txt · 上一次變更: 2014/04/20 19:36 由 jonathan