Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Server Log Mrtg
- http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html
- mrtg tanpa snmp on Debian Squeeze
- mengapa tanpa snmp?
- sekedar untuk mengurangi resources memory dan cpu, jika resources RIG tidak terlalu mewah dan ada fungsi lain yg jauh lebih penting, untuk squid cache misalnya. snmpd (snmp daemon) lumayan perlu resources cpu, terutama saat snmpwalk untuk mengumpulkan data-data yg di request mrtg
- disini kita hanya akan menggunakan script bash dan perl untuk menggantikan snmpwalk
- data yang di graph : ethernet traffic, memory usage, cpu load, tcp connection dan latency
- apt-get install gcc make perl apache2 libgd2-noxpm libpng12-0 libpng12-dev
- cd ..
- mkdir -p /usr/local/src
- cd /usr/local/src
- wget http://nchc.dl.sourceforge.net/project/libpng/libpng15/1.5.9/libpng-1.5.9.tar.gz
- gunzip -c libpng-1.5.9.tar.gz | tar xf -
- mv libpng-1.5.9 libpng
- cd libpng
- env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR
- make
- rm *.so.* *.so
- make && make install
- cd ..
- wget http://fossies.org/unix/www/GD-2.46.tar.gz
- gunzip -c GD-2.46.tar.gz |tar xf -
- mv GD-2.46.tar.gz gd
- cd gd
- env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" ./configure --disable-shared --without-freetype --without-jpeg
- make
- cp .libs/* .
- make && make install
- apt-get install -y mrtg
- answer “yes” saat installer ask “mrtg.cfg only readable/writeable by root”
- buat file-file loadavg.sh mem.sh ping.pl tcpconn.sh dan eth.pl di /usr/local/bin
- cd /usr/local/bin
- nano mem.sh
- #!/bin/sh
- # Thierry Nkaoua [email protected]
- USED=`free -b|grep cache:|cut -d ":" -f2|cut -c1-11`
- #FREE=`free -b|grep cache:|cut -d ":" -f2|cut -c12-22`
- echo $USED
- echo $USED
- nano eth.pl
- #!/usr/bin/perl
- use strict;
- my $if = $ARGV[0] || mrtg_die();
- open(F, "</proc/net/dev") || mrtg_die();
- my @LINES = <F>;
- close(F);
- foreach (grep(/\s+$if\:/, @LINES)) {
- /\s+$if\:(\s*\d*){1}/;
- my $recv = $1;
- $recv =~ s/\s+//g;
- /\s+$if\:(\s*\d*){9}/;
- my $sent = $1;
- $sent =~ s/\s+//g;
- print "$recv\n$sent\n0\n0\n";
- }
- sub mrtg_die() {
- print "0\n0\n0\n0\n";
- }
- nano loadavg.sh
- #!/bin/sh
- awk </proc/loadavg '{print (100*$1) "\n" (100*$2) }'
- hostname;
- echo "loadavg";
- nano tcpconn.sh
- #!/bin/sh
- if [ "$1" = "" ] ; then
- O=`/bin/netstat -nt | fgrep ESTABLISHED | wc -l`
- label='numconns'
- else
- O=`/bin/netstat -nt | fgrep ESTABLISHED | fgrep "$1" | wc -l`
- label="$1"
- fi
- echo $O
- echo $O
- hostname
- echo "$label"
- nano ping.pl
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Net::Ping;
- use Time::HiRes;
- my $host = shift;
- my $p = Net::Ping->new("icmp");
- $p->hires();
- my ($ret, $duration, $ip) = $p->ping($host, 5.5);
- if ( $ret ) {
- printf "%.0f\n", 1000 * $duration;
- } else {
- print "0\n";
- }
- # Value "in" for mrtg
- print "0\n";
- # Value "out" for mrtg
- print "\n";
- # A comment for mrt
- print "$host\n";
- $p->close();
- untuk code dari file-file diatas bisa di ambil dari sini:
- http://pastebin.com/R7zNZ5jw
- http://pastebin.com/xD5ZctwV
- http://pastebin.com/uRCLi3J6
- http://pastebin.com/7VF1GZMW
- http://pastebin.com/8h99Kuhf
- buat executable semua file
- chmod +x *
- buat/edit file /etc/mrtg.cfg
- nano /etc/mrtg.cfg
- config mrtg :
- # -------------------------------------------
- # OLCNET mrtg.cfg 17072011
- # -------------------------------------------
- # Global Config
- # -------------------------------------------
- WorkDir: /var/www/mrtg
- 09 #RunAsDaemon:Yes
- 10 Interval:5
- 11 WriteExpires: Yes
- 12 EnableIPv6: no
- 13 Background[_]:#CCCCCC;
- 14 Colours[_]:LIGHTBLUE#0099FF,ORANGE#FF6600,BLUE#0000FF,RED#FF0000
- 15 Options[_]: nopercent,growright,noinfo,gauge
- 16
- 17 # eth0
- 18 # -------------------------------------------
- 19
- 20 Title[eth0]: Ethernet Trafic
- 21 PageTop[eth0]: <h1>Ethernet Trafic</h1>
- 22 Target[eth0]: `/usr/local/bin/eth.pl eth0`
- 23 Options[eth0]: bits
- 24 MaxBytes[eth0]: 100000000
- 25
- 26 # Memory
- 27 # -------------------------------------------
- 28
- 29 Title[mem]: Memory Usage
- 30 PageTop[mem]: <h1>Memory Usage</h1>
- 31 Target[mem]: `/usr/local/bin/mem.sh`
- 32 Options[mem]: gauge,noinfo,nopercent,growright,nobanner,noarrow,pngdate
- 33 MaxBytes[mem]: 1024000000
- 34 YLegend[mem]: Bytes
- 35 ShortLegend[mem]: Bytes
- 36 LegendO[mem]: Mem Used :
- 37 WithPeak[mem]: wmy
- 38 Kilo[mem]:1024
- 39
- 40 # TCP Connection
- 41 # -------------------------------------------
- 42
- 43 Title[server-numconns]: Server TCP connections
- 44 Target[server-numconns]: `/usr/local/bin/tcpconn.sh`
- 45 PageTop[server-numconns]: <h1>TCP connections</h1>
- 46 MaxBytes[server-numconns]: 1000
- 47 YLegend[server-numconns]: Connections
- 48 ShortLegend[server-numconns]: Connections
- 49 LegendO[server-numconns]: Connections
- 50 Options[server-numconns]: gauge, growright
- 51
- 52 ## CPU Load
- 53 # -------------------------------------------
- 54
- 55 Target[server-cpu]: `/usr/local/bin/loadavg.sh`
- 56 MaxBytes[server-cpu]: 500
- 57 Title[server-cpu]: CPU Load
- 58 PageTop[server-cpu]: <h1>CPU Load</h1>
- 59 YLegend[server-cpu]: Load*100
- 60 ShortLegend[server-cpu]: load
- 61 Legend1[server-cpu]: CPU Load (x 100)
- 62 Legend2[server-cpu]:
- 63 LegendI[server-cpu]: 1min load
- 64 LegendO[server-cpu]: 5min load
- 65 Options[server-cpu]: gauge,nopercent,integer,growright
- 66
- 67 # Latency Local
- 68 # -------------------------------------------
- 69
- 70 Target[ping_local]: `/usr/local/bin/ping.pl www.detik.com`
- 71 Title[ping_local]: Latency Local
- 72 PageTop[ping_local]: <h1>Latency Local</h1>
- 73 LegendO[ping_local]:
- 74 MaxBytes[ping_local]: 10000
- 75 Options[ping_local]: gauge,growright
- 76 LegendI[ping_local]: Ping in ms
- 77 ShortLegend[ping_local]: ms
- 78 YLegend[ping_local]: ms
- 79 Factor[ping_local]: 1
- 80
- 81 # Latency Inter
- 82 # -------------------------------------------
- 83
- 84 Target[ping_inter]: `/usr/local/bin/ping.pl www.yahoo.com`
- 85 Title[ping_inter]: Latency Inter<
- 86 PageTop[ping_inter]: <h1>Latency Inter</h1>
- 87 LegendO[ping_inter]:
- 88 MaxBytes[ping_inter]: 10000
- 89 Options[ping_inter]: gauge,growright
- 90 LegendI[ping_inter]: Ping in ms
- 91 ShortLegend[ping_inter]: ms
- 92 YLegend[ping_inter]: ms
- 93 Factor[ping_inter]: 1
- buat workdir mrtg
- mkdir -p /var/www/mrtg
- mkdir -p /var/www/mrtg/image
- jalankan mrtg
- env LANG=C mrtg /etc/mrtg.cfg
- jalankan command diatas 3x sampai pesan warning hilang
- edit lagi file /etc/mrtg.cfg
- nano /etc/mrtg.cg
- hilangkan tanda “#” di depan RunAsDaemon:Yes
- jalankan sekali lagi mrtg untuk aktifkan daemon mrtg
- env LANG=C mrtg /etc/mrtg.cfg
- buat index.html
- indexmaker --output=/var/www/mrtg/index.html /etc/mrtg.cfg
- akses via broser ke http://[ip-address]/mrtg
- buka webmin, kita akan buat start-up mrtg dari webmin
- webmin > system > bootup and shutdown > Create a new bootup and shutdown action
- note
- * Target[eth0]: `/usr/local/bin/eth.pl eth0` > jika ethernet yg aktif bukan eth0, ganti eth0 dengan ethernet card yang aktif. jalankan ifconfig untuk melihat ethernet yang aktif
- * Target[ping_inter]: `/usr/local/bin/ping.pl www.yahoo.com` > silahkan diganti dengan host lain sesuai selera misalnya microsoft.com ato cuma IP-nya tidak perlu pakai hostname. hanya pastikan host yang anda pakai reliable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement