注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

涅槃

文档收藏

 
 
 

日志

 
 
 
 

nagios监控nginx连接数将历史数据保存到pnp  

2012-04-23 15:04:44|  分类: 监控_nagios |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

vim check_nginx_status.pl

#!/usr/bin/perl
############################## check_nginx_status ##############
# Version : 1.0
# Date : February 14 2010
# By wangchengtai@gmail.com
###############################################################
#
# help : ./check_nginx_stauts.pl
use LWP::UserAgent;

my $STATE_OK=0;
my $STATE_WARNING=1;
my $STATE_CRITICAL=2;
my $STATE_UNKNOWN=3;
my $STATE_DEPENDENT=4;

my $input=@ARGV;
if ($input!=4)
{
#        print "Four Argus:hostname:port NginxStatus War(values) Cri(values)\n";
        &print_usage;
        exit $STATE_UNKNOWN;
}

sub print_usage {
    print "Usage: $0 <Host:Port> <NginxStatuspage> <Warning> <Critical>\n";
}
my $URL = "http://".$ARGV[0].$ARGV[1];

my $ua = LWP::UserAgent->new(timeout => 30);
my $response = $ua->request(HTTP::Request->new('GET', $URL));

my $requests = undef;
my $total =  undef;
my $reading = undef;
my $writing = undef;
my $waiting = undef;

foreach (split(/\n/, $response->content)) {
  $total = $1 if (/^Active connections:\s+(\d+)/);
  if (/^Reading:\s+(\d+).*Writing:\s+(\d+).*Waiting:\s+(\d+)/) {
    $reading = $1;
    $writing = $2;
    $waiting = $3;
  }
  $requests = $3 if (/^\s+(\d+)\s+(\d+)\s+(\d+)/);
}

if ( $total eq undef && $reading eq undef && $writing eq undef && $waiting eq undef ){
        print "UNKNOWN - Local copy/copies of NginxStatus is empty.\n";
        exit $STATE_UNKNOWN;
}


sub do_output{
        print "ActiveConn:$total; Reading:$reading; Writing:$writing; Waiting:$waiting | ";
}
sub do_perfdata{
        print "'ActiveConn'=$total 'Reading'=$reading 'Writing'=$writing 'Waiting'=$waiting\n";
}

my $war = $ARGV[2];
my $cri = $ARGV[3];
if ( $total >= $war && $total < $cri ){
        print "WARNING - ";
        &do_output;
        &do_perfdata;
        exit $STATE_WARNING;
} elsif ( $total >= $cri ){
        print "CRITICAL - ";
        &do_output;
        &do_perfdata;
        exit $STATE_CRITICAL;
} else {
        print "OK - ";
        &do_output;
        &do_perfdata;
        exit $STATE_OK;
}

  评论这张
 
阅读(1215)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018