View RSS Feed

admin

MRTG monitoring script for nginx

Rate this Entry
โดย เมื่อ 08-14-2010 เวลา 14:33:55 (1253 เปิดอ่าน)
สร้างไฟล์ /root/bin/mrtg-nginx.pl ข้อมูลตามนี้
โค้ด PHP:
#!/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 นะครับ
Code:
location /status {
    stub_status on;
    access_log off;
}
แล้วก็… อันนี้เอาไปใส่ใน mrtg.cfg
โค้ด PHP:
Target[nginx.newconns]: `/root/bin/mrtg-nginx.pl con`
Title[nginx.newconns]: NGINX Connections
PageTop
[nginx.newconns]: [B]NGINX Connections[/B]


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]: [B]NGINX Requests[/B]


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 
ที่มา http://www.icez.net/blog/710/mrtg-mo...ript-for-nginx
ป้ายกำกับ: moniter, mrtg, Nginx เพิ่ม / แก้ไข ป้ายกำกับ
หัวข้อ
How To , Windows , Linux

ความคิดเห็น


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90