Advertisement
budiana

Server Log Mrtg

Mar 7th, 2012
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. Server Log Mrtg
  2. http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html
  3.  
  4. mrtg tanpa snmp on Debian Squeeze
  5. mengapa tanpa snmp?
  6. 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
  7. disini kita hanya akan menggunakan script bash dan perl untuk menggantikan snmpwalk
  8.  
  9. data yang di graph : ethernet traffic, memory usage, cpu load, tcp connection dan latency
  10.  
  11. apt-get install gcc make perl apache2 libgd2-noxpm libpng12-0 libpng12-dev
  12.  
  13. cd ..
  14. mkdir -p /usr/local/src
  15. cd /usr/local/src
  16. wget http://nchc.dl.sourceforge.net/project/libpng/libpng15/1.5.9/libpng-1.5.9.tar.gz
  17. gunzip -c libpng-1.5.9.tar.gz | tar xf -
  18. mv libpng-1.5.9 libpng
  19. cd libpng
  20. env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR
  21. make
  22. rm *.so.* *.so
  23. make && make install
  24. cd ..
  25.  
  26. wget http://fossies.org/unix/www/GD-2.46.tar.gz
  27. gunzip -c GD-2.46.tar.gz |tar xf -
  28. mv GD-2.46.tar.gz gd
  29. cd gd
  30. env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" ./configure --disable-shared --without-freetype --without-jpeg
  31. make
  32. cp .libs/* .
  33. make && make install
  34.  
  35. apt-get install -y mrtg
  36.  
  37. answer “yes” saat installer ask “mrtg.cfg only readable/writeable by root”
  38.  
  39. buat file-file loadavg.sh mem.sh ping.pl tcpconn.sh dan eth.pl di /usr/local/bin
  40.  
  41. cd /usr/local/bin
  42.  
  43. nano mem.sh
  44.  
  45. #!/bin/sh
  46.  
  47. # Thierry Nkaoua [email protected]
  48.  
  49. USED=`free -b|grep cache:|cut -d ":" -f2|cut -c1-11`
  50. #FREE=`free -b|grep cache:|cut -d ":" -f2|cut -c12-22`
  51. echo $USED
  52. echo $USED
  53.  
  54. nano eth.pl
  55.  
  56. #!/usr/bin/perl
  57.  
  58. use strict;
  59.  
  60. my $if = $ARGV[0] || mrtg_die();
  61.  
  62. open(F, "</proc/net/dev") || mrtg_die();
  63. my @LINES = <F>;
  64. close(F);
  65.  
  66. foreach (grep(/\s+$if\:/, @LINES)) {
  67. /\s+$if\:(\s*\d*){1}/;
  68. my $recv = $1;
  69. $recv =~ s/\s+//g;
  70.  
  71. /\s+$if\:(\s*\d*){9}/;
  72. my $sent = $1;
  73. $sent =~ s/\s+//g;
  74.  
  75. print "$recv\n$sent\n0\n0\n";
  76. }
  77.  
  78. sub mrtg_die() {
  79. print "0\n0\n0\n0\n";
  80. }
  81.  
  82.  
  83. nano loadavg.sh
  84.  
  85. #!/bin/sh
  86. awk </proc/loadavg '{print (100*$1) "\n" (100*$2) }'
  87. hostname;
  88. echo "loadavg";
  89.  
  90. nano tcpconn.sh
  91.  
  92. #!/bin/sh
  93.  
  94. if [ "$1" = "" ] ; then
  95. O=`/bin/netstat -nt | fgrep ESTABLISHED | wc -l`
  96. label='numconns'
  97. else
  98. O=`/bin/netstat -nt | fgrep ESTABLISHED | fgrep "$1" | wc -l`
  99. label="$1"
  100. fi
  101. echo $O
  102. echo $O
  103. hostname
  104. echo "$label"
  105.  
  106.  
  107. nano ping.pl
  108.  
  109. #!/usr/bin/perl
  110. use strict;
  111. use warnings;
  112. use Net::Ping;
  113. use Time::HiRes;
  114.  
  115. my $host = shift;
  116.  
  117. my $p = Net::Ping->new("icmp");
  118. $p->hires();
  119. my ($ret, $duration, $ip) = $p->ping($host, 5.5);
  120. if ( $ret ) {
  121. printf "%.0f\n", 1000 * $duration;
  122. } else {
  123. print "0\n";
  124. }
  125.  
  126. # Value "in" for mrtg
  127. print "0\n";
  128. # Value "out" for mrtg
  129. print "\n";
  130. # A comment for mrt
  131. print "$host\n";
  132. $p->close();
  133.  
  134.  
  135.  
  136. untuk code dari file-file diatas bisa di ambil dari sini:
  137. http://pastebin.com/R7zNZ5jw
  138. http://pastebin.com/xD5ZctwV
  139. http://pastebin.com/uRCLi3J6
  140. http://pastebin.com/7VF1GZMW
  141. http://pastebin.com/8h99Kuhf
  142.  
  143.  
  144. buat executable semua file
  145. chmod +x *
  146.  
  147. buat/edit file /etc/mrtg.cfg
  148.  
  149. nano /etc/mrtg.cfg
  150.  
  151. config mrtg :
  152.  
  153. # -------------------------------------------
  154. # OLCNET mrtg.cfg 17072011
  155. # -------------------------------------------
  156.  
  157. # Global Config
  158. # -------------------------------------------
  159.  
  160. WorkDir: /var/www/mrtg
  161. 09 #RunAsDaemon:Yes
  162. 10 Interval:5
  163. 11 WriteExpires: Yes
  164. 12 EnableIPv6: no
  165. 13 Background[_]:#CCCCCC;
  166. 14 Colours[_]:LIGHTBLUE#0099FF,ORANGE#FF6600,BLUE#0000FF,RED#FF0000
  167. 15 Options[_]: nopercent,growright,noinfo,gauge
  168. 16
  169. 17 # eth0
  170. 18 # -------------------------------------------
  171. 19
  172. 20 Title[eth0]: Ethernet Trafic
  173. 21 PageTop[eth0]: <h1>Ethernet Trafic</h1>
  174. 22 Target[eth0]: `/usr/local/bin/eth.pl eth0`
  175. 23 Options[eth0]: bits
  176. 24 MaxBytes[eth0]: 100000000
  177. 25
  178. 26 # Memory
  179. 27 # -------------------------------------------
  180. 28
  181. 29 Title[mem]: Memory Usage
  182. 30 PageTop[mem]: <h1>Memory Usage</h1>
  183. 31 Target[mem]: `/usr/local/bin/mem.sh`
  184. 32 Options[mem]: gauge,noinfo,nopercent,growright,nobanner,noarrow,pngdate
  185. 33 MaxBytes[mem]: 1024000000
  186. 34 YLegend[mem]: Bytes
  187. 35 ShortLegend[mem]: Bytes
  188. 36 LegendO[mem]: Mem Used :
  189. 37 WithPeak[mem]: wmy
  190. 38 Kilo[mem]:1024
  191. 39
  192. 40 # TCP Connection
  193. 41 # -------------------------------------------
  194. 42
  195. 43 Title[server-numconns]: Server TCP connections
  196. 44 Target[server-numconns]: `/usr/local/bin/tcpconn.sh`
  197. 45 PageTop[server-numconns]: <h1>TCP connections</h1>
  198. 46 MaxBytes[server-numconns]: 1000
  199. 47 YLegend[server-numconns]: Connections
  200. 48 ShortLegend[server-numconns]: Connections
  201. 49 LegendO[server-numconns]: Connections
  202. 50 Options[server-numconns]: gauge, growright
  203. 51
  204. 52 ## CPU Load
  205. 53 # -------------------------------------------
  206. 54
  207. 55 Target[server-cpu]: `/usr/local/bin/loadavg.sh`
  208. 56 MaxBytes[server-cpu]: 500
  209. 57 Title[server-cpu]: CPU Load
  210. 58 PageTop[server-cpu]: <h1>CPU Load</h1>
  211. 59 YLegend[server-cpu]: Load*100
  212. 60 ShortLegend[server-cpu]: load
  213. 61 Legend1[server-cpu]: CPU Load (x 100)
  214. 62 Legend2[server-cpu]:
  215. 63 LegendI[server-cpu]: 1min load
  216. 64 LegendO[server-cpu]: 5min load
  217. 65 Options[server-cpu]: gauge,nopercent,integer,growright
  218. 66
  219. 67 # Latency Local
  220. 68 # -------------------------------------------
  221. 69
  222. 70 Target[ping_local]: `/usr/local/bin/ping.pl www.detik.com`
  223. 71 Title[ping_local]: Latency Local
  224. 72 PageTop[ping_local]: <h1>Latency Local</h1>
  225. 73 LegendO[ping_local]:
  226. 74 MaxBytes[ping_local]: 10000
  227. 75 Options[ping_local]: gauge,growright
  228. 76 LegendI[ping_local]: Ping in ms
  229. 77 ShortLegend[ping_local]: ms
  230. 78 YLegend[ping_local]: ms
  231. 79 Factor[ping_local]: 1
  232. 80
  233. 81 # Latency Inter
  234. 82 # -------------------------------------------
  235. 83
  236. 84 Target[ping_inter]: `/usr/local/bin/ping.pl www.yahoo.com`
  237. 85 Title[ping_inter]: Latency Inter<
  238. 86 PageTop[ping_inter]: <h1>Latency Inter</h1>
  239. 87 LegendO[ping_inter]:
  240. 88 MaxBytes[ping_inter]: 10000
  241. 89 Options[ping_inter]: gauge,growright
  242. 90 LegendI[ping_inter]: Ping in ms
  243. 91 ShortLegend[ping_inter]: ms
  244. 92 YLegend[ping_inter]: ms
  245. 93 Factor[ping_inter]: 1
  246.  
  247. buat workdir mrtg
  248. mkdir -p /var/www/mrtg
  249. mkdir -p /var/www/mrtg/image
  250.  
  251. jalankan mrtg
  252. env LANG=C mrtg /etc/mrtg.cfg
  253.  
  254. jalankan command diatas 3x sampai pesan warning hilang
  255.  
  256. edit lagi file /etc/mrtg.cfg
  257. nano /etc/mrtg.cg
  258.  
  259. hilangkan tanda “#” di depan RunAsDaemon:Yes
  260.  
  261. jalankan sekali lagi mrtg untuk aktifkan daemon mrtg
  262. env LANG=C mrtg /etc/mrtg.cfg
  263.  
  264. buat index.html
  265. indexmaker --output=/var/www/mrtg/index.html /etc/mrtg.cfg
  266.  
  267. akses via broser ke http://[ip-address]/mrtg
  268.  
  269. buka webmin, kita akan buat start-up mrtg dari webmin
  270.  
  271. webmin > system > bootup and shutdown > Create a new bootup and shutdown action
  272.  
  273. note
  274.  
  275. * 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
  276. * 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