0102 | MRTG monitoring script for nginx

Tuesday, July 6th, 2010 Posted in IP Network, Web Server | 1 Comment »

สร้างไฟล์ /root/bin/mrtg-nginx.pl ข้อมูลตามนี้

#!/usr/bin/perl
# $Revision: 2 $
# $Date: 2008-09-12 15:11:40 +0300 (Fri, 12 Sep 2008) $
 
my %opt = (
# http link to nginx stub_status, be sure turn on stub_status in nginx conf
    nginx_status   => 'http://localhost:80/status',
# path for program what may dump web page, normaly lynx -dump
#    lynx            => 'lynx -dump',
    lynx            => 'wget -q -Y off -O -',
);
 
$opt{var} = $ARGV[0] if $ARGV[0];
$opt{nginx_status} = $ARGV[1] if $ARGV[1] and $ARGV[1]=~/^http:\/\/\w+/;
$opt{var} ||= '';
 
my $do = `$opt{lynx} $opt{nginx_status}`;
 
if ($opt{var} eq 'req') {
    $do=~/^Active connections:\s*(\d+)\s*$/ms or warn "Error! Can't find data!\nIN :\n$do";
    $opt{d2} = $opt{d1} = $1;
}
elsif ($opt{var} eq 'con') {
    $do=~/^\s*(\d+)\s+(\d+)\s+(\d+)\s*$/ms or warn "Error! Can't find data!\nIN :\n$do";
    $opt{d2} = $opt{d1} = $3;
}
#elsif { $do=~/^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/; }
else {
    $opt{var} = 'ERROR';
    $opt{d2} = $opt{d1} = 0;
    warn "Error! Please read the help and set (req|con)\n";
}
 
print "$opt{d1}\n";
print "$opt{d2}\n";
#print "$opt{up}\n" if $opt{up};
print "Nginx $opt{var}\n";

เสร็จแล้วสั่ง
chmod a+x /root/bin/mrtg-nginx.pl
ให้รันได้

แล้วเอาไอ้นี่ไปใส่ใน nginx.conf ส่วนของ vhost นะครับ

location /status {
    stub_status on;
    access_log off;
}

แล้วก็… อันนี้เอาไปใส่ใน mrtg.cfg

Target[nginx.newconns]: `/root/bin/mrtg-nginx.pl con`
Title[nginx.newconns]: NGINX Connections
PageTop[nginx.newconns]: <H1>NGINX Connections</H1>
MaxBytes[nginx.newconns]: 10000000000
ShortLegend[nginx.newconns]: c/s
YLegend[nginx.newconns]: Conns / sec
LegendI[nginx.newconns]: In
LegendO[nginx.newconns]:
Legend1[nginx.newconns]: New inbound connections
Legend2[nginx.newconns]:
Options[nginx.newconns]: growright,nopercent
 
Target[nginx.requests]: `/root/bin/mrtg-nginx.pl req`
Title[nginx.requests]: NGINX Requests
PageTop[nginx.requests]: <H1>NGINX Requests</H1>
MaxBytes[nginx.requests]: 10000000000
ShortLegend[nginx.requests]: req
YLegend[nginx.requests]: Req
LegendI[nginx.requests]: In
LegendO[nginx.requests]:
Legend1[nginx.requests]: New inbound connections
Legend2[nginx.requests]:
Options[nginx.requests]: growright,nopercent,gauge

Tags: ,

0082 | MRTG สำหรับจับการทำงานของ squid

Wednesday, November 4th, 2009 Posted in Linux, Web Server | 4 Comments »

แก้ squid.conf นิดหน่อย

acl snmppublic snmp_community public
snmp_port 3401
snmp_access allow snmppublic localhost
snmp_access deny all

แล้วเอาไอ้นี่ใส่ mrtg.cfg

LoadMIBs: /etc/squid/mib.txt
 
Target[cacheServerRequests]: cacheServerRequests&cacheServerRequests:public@localhost:3401
MaxBytes[cacheServerRequests]: 10000000
Title[cacheServerRequests]: Server Requests @ localhost
Options[cacheServerRequests]: growright, nopercent
PageTop[cacheServerRequests]: <h1>Server Requests @ localhost</h1>
YLegend[cacheServerRequests]: requests/sec
ShortLegend[cacheServerRequests]: req/s
LegendI[cacheServerRequests]: Requests&nbsp;
LegendO[cacheServerRequests]:
Legend1[cacheServerRequests]: Requests
Legend2[cacheServerRequests]:
 
Target[cacheProtoClientHttpRequests]: cacheProtoClientHttpRequests&cacheProtoClientHttpRequests:public@localhost:3401
MaxBytes[cacheProtoClientHttpRequests]: 10000000
Title[cacheProtoClientHttpRequests]: Client Http Requests @ localhost
Options[cacheProtoClientHttpRequests]: growright, nopercent
PageTop[cacheProtoClientHttpRequests]: <h1>Client Http Requests @ localhost</h1>
YLegend[cacheProtoClientHttpRequests]: requests/sec
ShortLegend[cacheProtoClientHttpRequests]: req/s
LegendI[cacheProtoClientHttpRequests]: Requests&nbsp;
LegendO[cacheProtoClientHttpRequests]:
Legend1[cacheProtoClientHttpRequests]: Requests
Legend2[cacheProtoClientHttpRequests]:
 
Target[cacheHttpHits]: cacheHttpHits&cacheHttpHits:public@localhost:3401
MaxBytes[cacheHttpHits]: 10000000
Title[cacheHttpHits]: HTTP Hits @ localhost
Options[cacheHttpHits]: growright, nopercent
PageTop[cacheHttpHits]: <h1>HTTP Hits @ localhost</h1>
YLegend[cacheHttpHits]: hits/sec
ShortLegend[cacheHttpHits]: hits/s
LegendI[cacheHttpHits]: Hits&nbsp;
LegendO[cacheHttpHits]:
Legend1[cacheHttpHits]: Hits
Legend2[cacheHttpHits]:
 
Target[cacheCpuUsage]: cacheCpuUsage&cacheCpuUsage:public@localhost:3401
MaxBytes[cacheCpuUsage]: 100
AbsMax[cacheCpuUsage]: 100
Title[cacheCpuUsage]: CPU Usage @ localhost
Options[cacheCpuUsage]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheCpuUsage]: dwmy
PageTop[cacheCpuUsage]: <h1>CPU Usage @ localhost</h1>
YLegend[cacheCpuUsage]: usage %
ShortLegend[cacheCpuUsage]:%
LegendI[cacheCpuUsage]: CPU Usage&nbsp;
LegendO[cacheCpuUsage]:
Legend1[cacheCpuUsage]: CPU Usage
Legend2[cacheCpuUsage]:
 
Target[cacheSysNumReads]: cacheSysNumReads&cacheSysNumReads:public@localhost:3401
MaxBytes[cacheSysNumReads]: 10000000
Title[cacheSysNumReads]: HTTP I/O number of reads @ localhost
Options[cacheSysNumReads]: growright, nopercent
PageTop[cacheSysNumReads]: <h1>HTTP I/O number of reads @ localhost</h1>
YLegend[cacheSysNumReads]: reads/sec
ShortLegend[cacheSysNumReads]: reads/s
LegendI[cacheSysNumReads]: I/O&nbsp;
LegendO[cacheSysNumReads]:
Legend1[cacheSysNumReads]: I/O
Legend2[cacheSysNumReads]:
 
Target[cacheCurrentFileDescrCnt]: cacheCurrentFileDescrCnt&cacheCurrentFileDescrCnt:public@localhost:3401
MaxBytes[cacheCurrentFileDescrCnt]: 1000000000
Title[cacheCurrentFileDescrCnt]: Used File Descriptors
Options[cacheCurrentFileDescrCnt]: gauge, growright, nopercent
PageTop[cacheCurrentFileDescrCnt]: <h1>Number of used file descriptors @ localhost</h1>
YLegend[cacheCurrentFileDescrCnt]: # of FDs
ShortLegend[cacheCurrentFileDescrCnt]: FDs
LegendI[cacheCurrentFileDescrCnt]: File Descriptors&nbsp;
LegendO[cacheCurrentFileDescrCnt]:
Legend1[cacheCurrentFileDescrCnt]: File Descriptors
Legend2[cacheCurrentFileDescrCnt]:
 
Target[cacheRequestHitRatio]: cacheRequestHitRatio.5&cacheRequestHitRatio.60:public@localhost:3401
MaxBytes[cacheRequestHitRatio]: 100
AbsMax[cacheRequestHitRatio]: 100
Title[cacheRequestHitRatio]: Request Hit Ratio @ localhost
Options[cacheRequestHitRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestHitRatio]: dwmy
PageTop[cacheRequestHitRatio]: <h1>Request Hit Ratio @ localhost</h1>
YLegend[cacheRequestHitRatio]: %
ShortLegend[cacheRequestHitRatio]: %
LegendI[cacheRequestHitRatio]: Median Hit Ratio (5min)&nbsp;
LegendO[cacheRequestHitRatio]: Median Hit Ratio (60min)&nbsp;
Legend1[cacheRequestHitRatio]: Median Hit Ratio
Legend2[cacheRequestHitRatio]: Median Hit Ratio
 
Target[cacheRequestByteRatio]: cacheRequestByteRatio.5&cacheRequestByteRatio.60:public@localhost:3401
MaxBytes[cacheRequestByteRatio]: 100
AbsMax[cacheRequestByteRatio]: 100
Title[cacheRequestByteRatio]: Byte Hit Ratio @ localhost
Options[cacheRequestByteRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestByteRatio]: dwmy
PageTop[cacheRequestByteRatio]: <h1>Byte Hit Ratio @ localhost</h1>
YLegend[cacheRequestByteRatio]: %
ShortLegend[cacheRequestByteRatio]:%
LegendI[cacheRequestByteRatio]: Median Hit Ratio (5min)&nbsp;
LegendO[cacheRequestByteRatio]: Median Hit Ratio (60min)&nbsp;
Legend1[cacheRequestByteRatio]: Median Hit Ratio
Legend2[cacheRequestByteRatio]: Median Hit Ratio

จริงๆ มันมีอีกเพียบเลย แต่ไม่รู้จะใส่ไว้ทำไม รก

Tags: ,