MRTG Perl and Shell Scripts | jehiah.cz에는 mrtg 에서 쓸 수 있는 여러종류의 스크립트가 있다. loadavg를 mrtg 에 표현 할 수 있는 방법을 찾다가 알게 되었다. 스크립트 내용은 아래에 한번에 정리해둔다.

mrtg-filesize.sh – 메일 로그가 차지하는 용량을 보여준다.

#!/bin/sh
# Created by Jehiah Czebotar
# http://www.jehiah.com/
#
# This script is licensed under the GPL http://www.gnu.org/copyleft/gpl.html
#
# Date   : January 5, 2003
# File   : mrtg-filesize.sh
# Version: 1.0
#########################
 
###  Sample /etc/mrtg.cfg usage
 
#  Title[server-mail]: Server Mail log size
#  PageTop[server-mail]: Server Mail log size
#  Target[server-mail]: `scripts/mrtg-filesize.sh /var/log/maillog`
#  MaxBytes[server-mail]: 1208032
#  YLegend[server-mail]: Size
#  ShortLegend[server-mail]: Bytes
#  LegendO[server-mail]: Bytes
#  Options[server-mail]: perminute, growright
 
 
l=`ls -l $1 | awk '{print $5}'`
echo $l
echo $l
hostname;
echo "mailsize";

mrtg-loadavg.sh – 서버 로드율 (부하율)을 보여준다.

#!/bin/sh
# Created by Jehiah Czebotar
# http://www.jehiah.com/
#
# This script is licensed under the GPL http://www.gnu.org/copyleft/gpl.html
#
# Date   : January 5, 2003
# File   : mrtg-loadavg.sh
# Version: 1.0
#########################
 
 
#### Sample /etc/mrtg.cfg usage
 
#  Target[server-cpu]: `scripts/mrtg-loadavg.sh`
#  MaxBytes[server-cpu]: 500
#  Title[server-cpu]: server CPU Load (5 minute average)
#  YLegend[server-cpu]: Load*100
#  ShortLegend[server-cpu]: load
#  Legend1[server-cpu]: CPU Load (x 100)
#  Legend2[server-cpu]:
#  LegendI[server-cpu]: 1min load
#  LegendO[server-cpu]: 5min load
#  PageTop[server-cpu]: server 5-minute average CPU Load
#  Options[server-cpu]: gauge,nopercent,integer,growright
 
awk </proc/loadavg '{print (100*$1) "\n" (100*$2) }'
hostname;
echo "loadavg";

mrtg-numconns.sh – TCP커넥션 수를 보여준다.

#!/bin/sh
# Created by Jehiah Czebotar
# http://www.jehiah.com/
#
# This script is licensed under the GPL http://www.gnu.org/copyleft/gpl.html
#
# Date   : January 5, 2003
# File   : mrtg-numconns.sh
# Version: 1.0
#########################
 
### Sample /etc/mrtg/mrtg.cfg usage
#  Title[server-numconns]: Server TCP connections
#  Target[server-numconns]: `scripts/mrtg-numconns.sh`
#  PageTop[server-numconns]: TCP connections
#  MaxBytes[server-numconns]: 1000
#  YLegend[server-numconns]: Connections
#  ShortLegend[server-numconns]: connections
#  LegendO[server-numconns]: Connections
#  Options[server-numconns]: gauge, growright
 
 
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"

mrtg-uptime.pl – 업타임을 보여준다.

#!/usr/bin/perl
# Created by Jehiah Czebotar
# http://www.jehiah.com/
#
# This script is licensed under the GPL http://www.gnu.org/copyleft/gpl.html
#
# Date   : January 5, 2003
# File   : mrtg-uptime.pl
# Version: 1.0
#########################
 
### Sample /etc/mrtg/mrtg.cfg file
 
#  Target[server-uptime]: `scripts/mrtg_uptime.pl`
#  Colours[server-uptime]: LIGHT BLUE#7AAFFF,BLUE#1000FF,DARK GREEN#006000,VIOLET#FF00FF
#  Options[server-uptime]: gauge,noinfo, nopercent, growright, unknaszero
#  MaxBytes[server-uptime]: 200
#  Title[server-uptime]: server uptime
#  YLegend[server-uptime]: Days
#  ShortLegend[server-uptime]: Days
#  Legend1[server-uptime]: Uptime
#  Legend2[server-uptime]:
#  LegendI[server-uptime]:
#  LegendO[server-uptime]: uptime :
#  PageTop[server-uptime]: Uptime in days
 
$uptime = `uptime`;
$uptime =~ /up (.*?) day/;
$up = int($1);
 
print "$up\n";
print "$up\n";
print "\n"; #hostname should be printed on 3rd line
print "uptime\n"; #