{"id":710,"date":"2010-07-06T11:27:20","date_gmt":"2010-07-06T04:27:20","guid":{"rendered":"http:\/\/www.icez.net\/blog\/?p=710"},"modified":"2010-07-06T11:27:20","modified_gmt":"2010-07-06T04:27:20","slug":"mrtg-monitoring-script-for-nginx","status":"publish","type":"post","link":"https:\/\/www.icez.net\/blog\/710\/mrtg-monitoring-script-for-nginx","title":{"rendered":"0102 | MRTG monitoring script for nginx"},"content":{"rendered":"<p>\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e44\u0e1f\u0e25\u0e4c \/root\/bin\/mrtg-nginx.pl \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e21\u0e19\u0e35\u0e49<\/p>\n<pre lang=\"perl\">#!\/usr\/bin\/perl\r\n# $Revision: 2 $\r\n# $Date: 2008-09-12 15:11:40 +0300 (Fri, 12 Sep 2008) $\r\n\r\nmy %opt = (\r\n# http link to nginx stub_status, be sure turn on stub_status in nginx conf\r\n    nginx_status   => 'http:\/\/localhost:80\/status',\r\n# path for program what may dump web page, normaly lynx -dump\r\n#    lynx            => 'lynx -dump',\r\n    lynx            => 'wget -q -Y off -O -',\r\n);\r\n\r\n$opt{var} = $ARGV[0] if $ARGV[0];\r\n$opt{nginx_status} = $ARGV[1] if $ARGV[1] and $ARGV[1]=~\/^http:\\\/\\\/\\w+\/;\r\n$opt{var} ||= '';\r\n\r\nmy $do = `$opt{lynx} $opt{nginx_status}`;\r\n\r\nif ($opt{var} eq 'req') {\r\n    $do=~\/^Active connections:\\s*(\\d+)\\s*$\/ms or warn \"Error! Can't find data!\\nIN :\\n$do\";\r\n    $opt{d2} = $opt{d1} = $1;\r\n}\r\nelsif ($opt{var} eq 'con') {\r\n    $do=~\/^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$\/ms or warn \"Error! Can't find data!\\nIN :\\n$do\";\r\n    $opt{d2} = $opt{d1} = $3;\r\n}\r\n#elsif { $do=~\/^Reading:\\s+(\\d+).*Writing:\\s+(\\d+).*Waiting:\\s+(\\d+)\/; }\r\nelse {\r\n    $opt{var} = 'ERROR';\r\n    $opt{d2} = $opt{d1} = 0;\r\n    warn \"Error! Please read the help and set (req|con)\\n\";\r\n}\r\n\r\nprint \"$opt{d1}\\n\";\r\nprint \"$opt{d2}\\n\";\r\n#print \"$opt{up}\\n\" if $opt{up};\r\nprint \"Nginx $opt{var}\\n\";\r\n<\/pre>\n<p>\u0e40\u0e2a\u0e23\u0e47\u0e08\u0e41\u0e25\u0e49\u0e27\u0e2a\u0e31\u0e48\u0e07<br \/>\nchmod a+x \/root\/bin\/mrtg-nginx.pl<br \/>\n\u0e43\u0e2b\u0e49\u0e23\u0e31\u0e19\u0e44\u0e14\u0e49<\/p>\n<p>\u0e41\u0e25\u0e49\u0e27\u0e40\u0e2d\u0e32\u0e44\u0e2d\u0e49\u0e19\u0e35\u0e48\u0e44\u0e1b\u0e43\u0e2a\u0e48\u0e43\u0e19 nginx.conf \u0e2a\u0e48\u0e27\u0e19\u0e02\u0e2d\u0e07 vhost \u0e19\u0e30\u0e04\u0e23\u0e31\u0e1a<\/p>\n<pre lang=\"php\">location \/status {\r\n    stub_status on;\r\n    access_log off;\r\n}\r\n<\/pre>\n<p>\u0e41\u0e25\u0e49\u0e27\u0e01\u0e47&#8230; \u0e2d\u0e31\u0e19\u0e19\u0e35\u0e49\u0e40\u0e2d\u0e32\u0e44\u0e1b\u0e43\u0e2a\u0e48\u0e43\u0e19 mrtg.cfg<\/p>\n<pre lang=\"php\">\r\nTarget[nginx.newconns]: `\/root\/bin\/mrtg-nginx.pl con`\r\nTitle[nginx.newconns]: NGINX Connections\r\nPageTop[nginx.newconns]: <H1>NGINX Connections<\/H1>\r\nMaxBytes[nginx.newconns]: 10000000000\r\nShortLegend[nginx.newconns]: c\/s\r\nYLegend[nginx.newconns]: Conns \/ sec\r\nLegendI[nginx.newconns]: In\r\nLegendO[nginx.newconns]:\r\nLegend1[nginx.newconns]: New inbound connections\r\nLegend2[nginx.newconns]:\r\nOptions[nginx.newconns]: growright,nopercent\r\n\r\nTarget[nginx.requests]: `\/root\/bin\/mrtg-nginx.pl req`\r\nTitle[nginx.requests]: NGINX Requests\r\nPageTop[nginx.requests]: <H1>NGINX Requests<\/H1>\r\nMaxBytes[nginx.requests]: 10000000000\r\nShortLegend[nginx.requests]: req\r\nYLegend[nginx.requests]: Req\r\nLegendI[nginx.requests]: In\r\nLegendO[nginx.requests]:\r\nLegend1[nginx.requests]: New inbound connections\r\nLegend2[nginx.requests]:\r\nOptions[nginx.requests]: growright,nopercent,gauge\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0e2a\u0e23\u0e49\u0e32\u0e07\u0e44\u0e1f\u0e25\u0e4c \/root\/bin\/mrtg-nginx.pl \u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e15\u0e32\u0e21\u0e19\u0e35\u0e49 #!\/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 => &#8216;http:\/\/localhost:80\/status&#8217;, # path for program what may dump web page, normaly lynx -dump # lynx => &#8216;lynx [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[49,5912],"class_list":["post-710","post","type-post","status-publish","format-standard","hentry","category-network","category-webserver","tag-mrtg","tag-nginx"],"_links":{"self":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":1,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"predecessor-version":[{"id":711,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/710\/revisions\/711"}],"wp:attachment":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}