Langkau ke kandungan utama

MRTG EASY


Let's Begin

NOTE: This guide suggests using an mrtg config per target, this is rather inefficient as mrtg can do them all in 1 job itself
SU Into root before continuing forward. Start by:
/usr/bin/mkdir /etc/mrtg
/usr/bin/mkdir /etc/cron.mrtg
/usr/bin/mkdir -p /var/www/localhost/htdocs/mrtg
Now let's edit /etc/snmp/snmpd.conf NOTE: Ignore the warning not to edit this file.
File: /etc/snmp/snmpd.conf
com2sec local     127.0.0.1/32    public
com2sec local     10.10.10.0/24   public
 
group MyROGroup v1         local
group MyROGroup v2c        local
group MyROGroup usm        local
 
view all    included  .1                               80
 
access MyROGroup ""      any       noauth    exact  all    none   none
 
syslocation MyLocation
syscontact Me <me@somewhere.org>
Edit /etc/conf.d/snmpd file, and in SNMPD_FLAGS line have:
File: /etc/conf.d/snmpd
-C -c /etc/snmp/snmpd.conf
This makes sure SNMPD uses the above /etc/snmp/snmpd.conf, and _only_ that file.
Now the daemon:
/etc/init.d/snmpd start
/sbin/rc-update add snmpd default
[edit]

Configuration

[edit]

Traffic

/usr/bin/cfgmaker  \
--output=/etc/mrtg/traffic.cfg \
--ifdesc=ip \
--ifref=descr \
--global "WorkDir: /var/www/localhost/htdocs/mrtg" \
--global "Options[_]: bits,growright" \
  public@localhost
[edit]

CPU

Now set up some files:
File: /etc/mrtg/cpu.cfg
WorkDir: /var/www/localhost/htdocs/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@127.0.0.1+ ssCpuRawSystem.0&ssCpuRawSystem.0:public@127.0.0.1+ ssCpuRawNice.0&ssCpuRawNice.0:public@127.0.0.1
RouterUptime[localhost.cpu]: public@127.0.0.1
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: <H1>Active CPU Load %</H1>
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]:  Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent,gauge
[edit]

Memory

File: /etc/mrtg/mem.cfg
LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost
PageTop[localhost.mem]: <H1>Free Memory</H1>
WorkDir: /var/www/localhost/htdocs/mrtg
Options[localhost.mem]: nopercent,growright,gauge,noinfo
Title[localhost.mem]: Free Memory
MaxBytes[localhost.mem]: 1000000
kMG[localhost.mem]: k,M,G,T,P,X
YLegend[localhost.mem]: bytes
ShortLegend[localhost.mem]: bytes
LegendI[localhost.mem]:  Free Memory:
LegendO[localhost.mem]:
Legend1[localhost.mem]: Free memory, not including swap, in bytes
[edit]

Swap

File: /etc/mrtg/swap.cfg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.swap]: memAvailSwap.0&memAvailSwap.0:public@localhost
PageTop[localhost.swap]: <H1>Swap Memory</H1>
WorkDir: /var/www/localhost/htdocs/mrtg
Options[localhost.swap]: nopercent,growright,gauge,noinfo
Title[localhost.swap]: Free Memory
MaxBytes[localhost.swap]: 1000000
kMG[localhost.swap]: k,M,G,T,P,X
YLegend[localhost.swap]: bytes
ShortLegend[localhost.swap]: bytes
LegendI[localhost.swap]:  Free Memory:
LegendO[localhost.swap]:
Legend1[localhost.swap]: Swap memory avail, in bytes
  1. we're almost there
[edit]

Ping

File: /etc/mrtg/ping.cfg
WorkDir: /var/www/localhost/htdocs/mrtg
Title[localhost.ping]: Round Trip Time
PageTop[localhost.ping]: <H1>Round Trip Time</H1>
Target[localhost.ping]: `/etc/mrtg/ping.sh`
MaxBytes[localhost.ping]: 2000
Options[localhost.ping]: growright,unknaszero,nopercent,gauge
LegendI[localhost.ping]: Pkt loss %
LegendO[localhost.ping]: Avg RTT
YLegend[localhost.ping]: RTT (ms)
[edit]

Making Jobs

[edit]

Traffic

File: /etc/cron.mrtg/traffic
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/traffic.cfg
[edit]

CPU

File: /etc/cron.mrtg/cpu
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/cpu.cfg
[edit]

Memory

File: /etc/cron.mrtg/mem
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/mem.cfg
[edit]

Swap

File: /etc/cron.mrtg/swap
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/swap.cfg
[edit]

Ping

File: /etc/cron.mrtg/ping
#!/bin/sh
/usr/bin/mrtg /etc/mrtg/ping.cfg
[edit]

Ping.sh

File: /etc/mrtg/ping.sh
 #!/bin/sh
 PING="/bin/ping"
 # Google, for example
 ADDR="google.com"
 DATA=`$PING -c10 -s500 $ADDR -q `
 LOSS=`echo $DATA | awk '{print $18 }' | tr -d %`
 echo $LOSS
 if [ $LOSS = 100 ];
 then
               echo 0
 else
        echo $DATA | awk -F/ '{print $5 }'
 fi
/bin/chmod +x /etc/cron.mrtg/*
/bin/chmod +x /etc/mrtg/ping.sh
Run each script 3 times (disregard the warnings)
/etc/cron.mrtg/traffic
/etc/cron.mrtg/cpu
/etc/cron.mrtg/mem
/etc/cron.mrtg/swap
/etc/cron.mrtg/ping
[edit]

Make the Index

/usr/bin/indexmaker --output=/var/www/localhost/htdocs/mrtg/index.html \
--title="Power Under Control :)" \
--sort=name \
--enumerate \
/etc/mrtg/traffic.cfg \
/etc/mrtg/cpu.cfg \
/etc/mrtg/mem.cfg \
/etc/mrtg/swap.cfg \
/etc/mrtg/ping.cfg
[edit]

Make the mrtg.cfg

cfgmaker --global "WorkDir: /var/www/localhost/htdocs/mrtg/" \
--global "Options[_]: growright,bits" \
--ifref=ip \
public@localhost > /etc/mrtg/mrtg.cfg
[edit]

Cronjob

/bin/cat >> /var/spool/cron/crontabs/root
*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null
Now just press [ctrl+d]
or

/usr/bin/crontab -e
[edit]

Additional CronJob Options

In your *.cfg file, add the lines -
RunAsDaemon: Yes
Interval: <Choose your interval, 5 is minimum>
This option works well if you choose not to create a cron job
[edit]

Power Under Control

Open Mozilla or your browser of choice and browse:
/var/www/localhost/htdocs/mrtg/index.html
or use your httpd server
http://localhost/mrtg
[edit]

Advanced Users

For other targets (and other stat), try with other object identifier (OID)
[edit]

Polling

roberto@moira mrtg $ snmpwalk -v 1 -c public localhost mgmt.1.2.2.1.10.2
IF-MIB::ifInOctets.2 = Counter32: 140021440
[edit]

Translating

roberto@moria mrtg $ snmptranslate -IR -Td mgmt.1.2.2.1.10.2
IF-MIB::ifInOctets.2
ifInOctets OBJECT-TYPE
 -- FROM       IF-MIB, RFC1213-MIB
 SYNTAX        Counter32
 MAX-ACCESS    read-only
 STATUS        current
 DESCRIPTION   "The total number of octets received on the interface,
    including framing characters.
 
    Discontinuities in the value of this counter can occur at
    re-initialization of the management system, and at other
    times as indicated by the value of
    ifCounterDiscontinuityTime."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) interfaces(2) ifTable(2) ifEntry(1) ifInOctets(10) 2 }
[edit]

Most Important Files

/usr/share/doc/net-snmp
/usr/share/doc/mrtg-*/contrib
  • man mrtg
  • man snmpd
  • man snmpwalk
  • man crontab
  • man cat
[edit]

Discussion

Original forum discussion can be found here
[edit]

UTF-8

IF your system is using UTF-8, you will get this:
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an environment
       where this is not the case. Try the following command to start: 
 
       env LANG=C /usr/bin/mrtg /etc/mrtg/mem.cfg
-----------------------------------------------------------------------
So, just do as you're told for all files in /etc/cron.mrtg/:
  • /etc/cron.mrtg/traffic.sh
  • /etc/cron.mrtg/cpu.sh
  • /etc/cron.mrtg/mem.sh
  • /etc/cron.mrtg/swap.sh
  • /etc/cron.mrtg/ping.sh
[edit]

See also

Catatan popular daripada blog ini

Setting APACHE Tomcat Dengan Configure mod_jk Connector pada RHEL6.4 cara ringkas.

 Asas - Apakah mod_jk?   Penyambung mod_jk ialah modul Apache httpd yang membolehkan httpd untuk berkomunikasi dengan Apache Tomcat  bagi  seluruh  keadaan  protokol AJP. Modul ini digunakan bersama- s ama dengan komponen Penyambung AJP Tomcat ini.  Mengenai Penyambung   Apache Tomcat menggunakan komponen Penyambung untuk membolehkan komunikasi antara contoh nya  Tomcat dan pihak lain, seperti pelayar, pelayan atau contoh lain Tomcat yang merupakan sebahagian daripada rangkaian yang sama. Sebagai contoh, penyambung HTTP mendengar untuk permintaan lebih protokol HTTP/1.1 pada pelbagai port TCP...

Azure 4 - VNet Peering & Service Chaining

lab title module VNet Peering and Service Chaining Module 05 - Intersite Connectivity Lab: VNet Peering and Service Chaining All tasks in this lab are performed from the Azure portal except for Exercise 2 Task 3, Exercise 3 Task 1, and Exercise 3 Task 2, which include steps performed from a Remote Desktop session to an Azure VM Lab files: Labfiles\Module_05\VNet_Peering_and_Service_Chaining\az-100-04_01_azuredeploy.json Labfiles\Module_05\VNet_Peering_and_Service_Chaining\az-100-04_02_azuredeploy.json Labfiles\Module_05\VNet_Peering_and_Service_Chaining\az-100-04_azuredeploy.parameters.json Scenario Adatum Corporation wants to implement service chaining between Azure virtual networks in its Azure subscription. Objectives After completing this lab, you will be able to: Create Azure virtual networks and deploy Azure VM by using Azure Resource Manager templates. Configure VNet peering. Implement custom routing Validate service chaining ...

Pasang Fedora 21 pada Surface Pro 3

Sila buat recovery untuk pc anda dulu guna USB yang bersaiz > 8 GB. Windows 8 Tak boleh  shrink volume lebih dari 4 partision. Tapi boleh guna cara khas nak    shrink volume. Jika alat Pengurusan Cakera tidak membenarkan berbuat demikian kerana "fail unmovable", anda akan perlu memasang semula Windows - dan menggunakan helah khas.  Gunakan opsyen Pemulihan untuk Pasang semula (tidak memuat semula) Windows.  Jangan meneruskan Ubahsuaian Awal selepas Windows but untuk kali pertama, sebaliknya, secara paksa mematikannya menggunakan butang kuasa, dan hidupkannya semula. Anda mungkin perlu mematikannya dan pada dua atau tiga kali, sehingga but Windows dan dicadangkan anda untuk menggunakan Advanced Startup untuk membaikinya.  Masukkan Command Prompt daripada pilihan Advanced Startup - Troubleshoot - advance options - command prompt - administrator - continue. .  Gunakan DISKPART mengecut partition C dengan saiz yang anda inginkan.  But s...