MRTG 配置过程 -- CentOSdd

来源:百度文库 编辑:神马文学网 时间:2024/04/27 21:37:36
[root@centos45 ~]# rpm -q net-snmp
package net-snmp is not installed
[root@centos45 ~]# yum -y install mrtg
Setting up Install Process
Setting up repositories
update                    100% |=========================|  951 B    00:00
base                      100% |=========================| 1.1 kB    00:00
addons                    100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for mrtg to pack into transaction set.
mrtg-2.10.15-1.i386.rpm   100% |=========================|  57 kB    00:02
---> Package mrtg.i386 0:2.10.15-1 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
mrtg                    i386       2.10.15-1        base              914 k
Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 914 k
Downloading Packages:
(1/1): mrtg-2.10.15-1.i38 100% |=========================| 914 kB    01:55
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: mrtg                         ######################### [1/1]
Installed: mrtg.i386 0:2.10.15-1
Complete!
[root@centos45 ~]# rpm -q net-snmp
package net-snmp is not installed
[root@centos45 ~]# yum -y install net-snmp
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for net-snmp to pack into transaction set.
net-snmp-5.1.2-11.EL4.10. 100% |=========================|  35 kB    00:08
---> Package net-snmp.i386 0:5.1.2-11.EL4.10 set to be updated
--> Running transaction check
--> Processing Dependency: libsensors.so.3 for package: net-snmp
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for lm_sensors to pack into transaction set.
lm_sensors-2.8.7-2.40.3.i 100% |=========================|  23 kB    00:01
---> Package lm_sensors.i386 0:2.8.7-2.40.3 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
net-snmp                i386       5.1.2-11.EL4.10  base              504 k
Installing for dependencies:
lm_sensors              i386       2.8.7-2.40.3     base              426 k
Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 930 k
Downloading Packages:
(1/2): lm_sensors-2.8.7-2 100% |=========================| 426 kB    01:34
(2/2): net-snmp-5.1.2-11. 100% |=========================| 504 kB    02:27
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: lm_sensors                   ######################### [1/2]
Installing: net-snmp                     ######################### [2/2]
Installed: net-snmp.i386 0:5.1.2-11.EL4.10
Dependency Installed: lm_sensors.i386 0:2.8.7-2.40.3
Complete!
[root@centos45 ~]# vi /etc/snmp/snmpd.conf
#       sec.name  source          community
com2sec notConfigUser  default       public
com2sec mynetwork    10.10.7.0/24    trysoft
com2sec mynetwork    127.0.0.1       trysoft
com2sec mynetwork    192.168.2.0/24  trysoft
#       groupName      securityModel securityName
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
group   MYROGroup      v1            mynetwork
group   MYROGroup      v2c           mynetwork
group   MYROGroup      usm           mynetwork
#view    systemview    included   .1.3.6.1.2.1.1
#view    systemview    included   .1.3.6.1.2.1.25.1.1
view    all    included   .1.3.6.1.2.1
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
#       group          context sec.model sec.level prefix read   write  notif
access  notConfigGroup ""      any       noauth    exact  systemview none none
access   MyROGroup     ""      any       noauth    exact  all    none   none
# variables through the snmpd.conf file:
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root (configure /etc/snmp/snmp.local.conf)
# Added for support of bcm5820 cards.
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
[root@centos45 ~]# service snmpd restart
[root@centos45 ~]# chkconfig snmpd on
[root@centos45 ~]# chkconfig --list | grep snmpd
[root@centos45 ~]# vi /etc/mrtg/mrtg.connection
#!/usr/bin/perl
$chkport=length($ARGV[0])==0?"5432":$ARGV[0];
$mrtgline1 = `netstat -na | grep ":$chkport "|awk ‘{print \$5}‘|sort | wc -l|awk ‘{print\$1 - 1}‘`;
$mrtgline2=`netstat -na | grep ":$chkport "|awk ‘{print \$5}‘|cut -d":" -f1|sort| uniq |wc -l | awk ‘{print \$1 - 1}‘`;
$UPtime=`/usr/bin/uptime | awk ‘{print \$3 " " \$4 " " \$5}‘`;
$hostname=`/bin/hostname`;
print($mrtgline1);
print($mrtgline2);
print($UPtime);
print($hostname);
[root@centos45 ~]# vi /etc/mrtg/mrtg.cpu
#!/bin/bash cpuusr=`/usr/bin/sar -u 1 3 | grep Average | awk ‘{print $3}‘` cpusys=`/usr/bin/sar -u 1 3 | grep Average | awk ‘{print $5}‘` UPtime=`/usr/bin/uptime | awk ‘{print $3 " " $4 " " $5}‘` hostname=`/bin/hostname`; echo $cpuusr echo $cpusys echo $UPtime echo $hostname
[root@centos45 ~]# vi /etc/mrtg/mrtg.cpuio
#!/bin/bash
cpuiowait=`/usr/bin/sar -u 1 3 | grep Average | awk ‘{print $6}‘`
cpuidel=`/usr/bin/sar -u 1 3 | grep Average | awk ‘{print $7}‘`
UPtime=`/usr/bin/uptime | awk ‘{print $3 " " $4 " " $5}‘`
hostname=`/bin/hostname`;
echo $cpuiowait
echo $cpuidel
echo $UPtime
echo $hostname
[root@centos45 ~]# vi /etc/mrtg/mrtg.disk
#!/usr/bin/perl $chkmountpt=length($ARGV[0])==0?"/":$ARGV[0]; $dfresult = `df -P -B 1 -T|grep -v "Mounted"|awk ‘{print \$7,\$1,\$6,\$4,\$5,\$2}‘`; @dfarr = split(/\n/, $dfresult); $mrtgline=""; $idx=0; while (length($mrtgline)==0 && $idx< @dfarr) { $dfline=$dfarr[$idx]; ($mountpt, $fs, $capacity, $used, $available, $fstype) = split(/ /,$dfline); if ($mountpt eq $chkmountpt) { $mrtgline = "$used\n$available\n"; } $idx++; } if (length($mrtgline)==0) { $mrtgline = "-1\n-1\n"; } $UPtime=`/usr/bin/uptime | awk ‘{print \$3 " " \$4 " " \$5}‘`; $hostname=`/bin/hostname`; print($mrtgline); print($UPtime); print("$chkmountpt ($fs) Capacity=$capacity on $hostname");
[root@centos45 ~]# vi /etc/mrtg/mrtg.temper
#!/usr/bin/perl $chkmode=length($ARGV[0])==0?"sensors":$ARGV[0]; if ($chkmode eq "sensors") { # M/B Temp: # CPU Temp: $result = `/usr/local/bin/sensors | /bin/grep Temp|awk ‘{print \$3}‘`; $result =~ s/\+//g; print($result); } elsif ($chkmode eq "ups") { # SmartUPS $result = `/bin/cat /var/log/apcupsd.status | /bin/grep ITEMP|awk ‘{print \$3}‘`; print($result."0\n"); } elsif ($chkmode eq "wwwhd") { # SCSI /dev/sda $result = `/usr/sbin/smartctl -a /dev/sda | /bin/grep Temperature | /bin/grep Current|awk ‘{print \$4}‘`; print($result); # SATA /dev/sdb $result = `/usr/sbin/smartctl -a -d ata /dev/sdb | /bin/grep Temperature_Celsius|awk ‘{print \$10}‘`; print($result); } elsif ($chkmode eq "mailhd") { # SATA /dev/sda $result = `/usr/sbin/smartctl -a -d ata /dev/sda | /bin/grep Temperature_Celsius|awk ‘{print \$10}‘`; print($result); # SATA /dev/sdb $result = `/usr/sbin/smartctl -a -d ata /dev/sdb | /bin/grep Temperature_Celsius|awk ‘{print \$10}‘`; print($result); } else { print("-1\n-1\n"); } $UPtime=`/usr/bin/uptime | awk ‘{print \$3 " " \$4 " " \$5}‘`; $hostname=`/bin/hostname`; print($UPtime); print("$hostname");
[root@centos45 ~]# vi /etc/mrtg/mrtg.cfg
HtmlDir: /var/www/mrtg
ImageDir: /var/www/mrtg
LogDir: /var/lib/mrtg
ThreshDir: /var/lib/mrtg
#Target[r1]: 2:public@myrouter.somplace.edu
#MaxBytes[r1]: 1250000
#Title[r1]: Traffic Analysis
#PageTop[r1]:

Stats for our Ethernet


Target[eth0]: 2:public@10.10.7.246
SetEnv[eth0]: MRTG_INT_IP="10.10.7.246" MRTG_INT_DESCR="eth0"
MaxBytes[eth0]: 1250000000
Options[eth0]: growright
Title[eth0]: Traffic Analysis
PageTop[eth0]:

Stats for our eth1:10.10.7.246 Ethernet


Target[eth1]: 3:public@192.168.2.1
SetEnv[eth1]: MRTG_INT_IP="192.168.2.1" MRTG_INT_DESCR="eth1"
MaxBytes[eth1]: 1250000000
Options[eth1]: growright
Title[eth1]: Traffic Analysis
PageTop[eth1]:

Stats for our eth0:192.168.2.1 Ethernet


Target[disk_root]: `/etc/mrtg/mrtg.disk`
MaxBytes[disk_root]: 40000000000
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]:

mail.ichiayi.com disk_root usage



    
System:mail.ichiayi.com

Target[disk_data]: `/etc/mrtg/mrtg.disk /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]:

mail.ichiayi.com disk_data usage



    
System:mail.ichiayi.com

Target[cpu]: `/etc/mrtg/mrtg.cpu`
MaxBytes[cpu]: 100
Options[cpu]: gauge, nopercent, growright
YLegend[cpu]: CPU loading (%)
ShortLegend[cpu]: %
LegendO[cpu]: CPU User Loading;
LegendI[cpu]: CPU System Loading;
Title[cpu]: CPU Loading
PageTop[cpu]:

mail.ichiayi.com CPU loading



    
System:mail.ichiayi.com

Target[cpuio]: `/etc/mrtg/mrtg.cpuio`
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]:

mail.ichiayi.com cpuio loading



    
System:mail.ichiayi.com

Target[mailhd]: `/etc/mrtg/mrtg.temper mailhd`
MaxBytes[mailhd]: 200
Options[mailhd]: gauge, nopercent, growright
YLegend[mailhd]: HD (C)
ShortLegend[mailhd]: C
LegendO[mailhd]: main HD Temp ;
LegendI[mailhd]: data HD Temp;
Title[mailhd]: Hard Disk Temperature
PageTop[mailhd]:

mail.ichiayi.com Hard Disk temperature



    
System:mail.ichiayi.com

Target[smtp]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com SMTP connections



    
System:mail.ichiayi.com

Target[pop3]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com POP3 connections



    
System:mail.ichiayi.com

Target[imap]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com IMAP connections



    
System:mail.ichiayi.com

Target[http]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com HTTP connections



    
System:mail.ichiayi.com

Target[ssh]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com SSH connections



    
System:mail.ichiayi.com

Target[postgres]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com PostgreSQL connections



    
System:mail.ichiayi.com

Target[mysql]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com MYSQL connections



    
System:mail.ichiayi.com

Target[domain]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com domain connections



    
System:mail.ichiayi.com

Target[ntp]: `/etc/mrtg/mrtg.connection 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]:

mail.ichiayi.com NTP connections



    
System:mail.ichiayi.com

[root@centos45 ~]# cd /etc/mrtg
[root@centos45 ~]# chmod 755 mrtg.*
[root@centos45 ~]# vi /etc/cron.d/mrtg
*/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok
[root@centos45 ~]# vi /etc/httpd/conf.d/mrtg.conf
#
# This configuration file maps the mrtg output (generated daily)
# into the URL space.  By default these results are only accessible
# from the local host.
#
Alias /mrtg /var/www/mrtg

Order deny,allow
Deny from all
Allow from 127.0.0.1 10.10.7.245
Allow from ::1
# Allow from .example.com

[root@centos45 ~]# service httpd restart
[root@centos45 mrtg]# ll /var/www/mrtg/*.html
-rw-r--r--  1 root root 56884 Feb 22  2005 /var/www/mrtg/cfgmaker.html
-rw-r--r--  1 root root  7967 Jun 26 13:15 /var/www/mrtg/cpu.html
-rw-r--r--  1 root root  7787 Jun 26 13:15 /var/www/mrtg/cpuio.html
-rw-r--r--  1 root root  8392 Jun 26 13:15 /var/www/mrtg/disk_data.html
-rw-r--r--  1 root root  8395 Jun 26 13:15 /var/www/mrtg/disk_root.html
-rw-r--r--  1 root root  7978 Jun 26 13:15 /var/www/mrtg/domain.html
-rw-r--r--  1 root root  7888 Jun 26 13:15 /var/www/mrtg/eth0.html
-rw-r--r--  1 root root  7848 Jun 26 13:15 /var/www/mrtg/eth1.html
IE在地址输入:http://10.10.7.246/mrtg/cpu.html
..................................../cpuio.html   disk_data.html  disk_root.html eth0.html  eth1.html
参考资料:
http://www.ichiayi.com/wikipage/tech/mrtg