nagios 监控fastcgi

简介:
监控脚本

#!/usr/bin/perl -w

# check_fastcgi.pl checks if a php-cgi server (or, theorically, any
# other fastcgi server) is alive.
#
# Copyright (c) 2009 Rodolfo Gonzalez <rodolfo_gonzalez@hotmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.    If not, see <http://www.gnu.org/licenses/>.

# include modules

use strict;
use FCGI::Client;
use IO::Socket::INET;
use Getopt::Long;

# command line parameters with some defaults

my $host = '';                 # server host
my $port = 9999;             # tcp port
my $script = '';             # test script (absolute path starting at / - root directory -)
my $query_string = ''; # query string
my $expected = 'OK';     # expected string
my $timeout = 5;             # timeout in seconds

# check command line options

GetOptions ('H=s' => \$host, 'p=i' => \$port, 's=s' => \$script, 'q=s' => \$query_string, 'e=s' => \$expected, 't=i' => \$timeout);

if (($host eq '') || ($script eq '')) {
     print "Usage: check_php-cgi.pl -H host -s <test script> [-p port] [-q <query string>] [-e <expected string>] [-t <timeout seconds>]\n";
     exit(-1);
}

# run check

my $sock = IO::Socket::INET->new(
        PeerAddr => $host,
        PeerPort => $port,
        Timeout    => $timeout,
        Proto        => 'tcp',
) or &_bad();

my $client = FCGI::Client::Connection->new( sock => $sock ) or &_bad();

my ( $stdout, $stderr ) = $client->request(
        +{
                REQUEST_METHOD    => 'GET',
                PHP_SELF                => $script,
                SCRIPT_FILENAME => $script,
                QUERY_STRING        => $query_string,
        },
        ''
) or &_bad();

if ($stdout =~ /$expected/) {
     &_good();
}
else {
     &_bad();
}

sub _good()
{
     print "OK: fastcgi server is working.";
     exit(0);
}

sub _bad()
{
     print "FastCGI CRITICAL: fastcgi has not responded.";
     exit(2);
}


先使用cpan安装 

strict
FCGI::Client
IO::Socket::INET
Getopt::Long

建立一个/tmp/test.php文件 
echo "ok" ;
?>

测试 脚本 :
./check_fastcgi.pl -H 127.0.0.1 -p 9000 -s /tmp/test.php -e ok
OK: fastcgi server is working

配置:
我对脚本进行了修改。指定了文件的目录。
可根据个人情况进行修改
my $host = '';         # server host
my $port = 9999;       # tcp port
my $script = '';       # test script (absolute path starting at / - root directory -)
my $query_string = ''; # query string
my $expected = 'OK';   # expected string
my $timeout = 5;       # timeout in seconds

commands.cfg
define command{
        command_name    check_fastcgi
        command_line    $USER1$/check_fastcgi 
        }

监控配置:
define service{
        use                             generic-service
        host_name                       126
        service_description             Fastcgi
        check_command                   check_nrpe!check_fastcgi
        notifications_enabled           0
        }


本文转自守住每一天51CTO博客,原文链接:http://blog.51cto.com/liuyu/273563,如需转载请自行联系原作者
相关文章
|
5天前
|
搜索推荐 编译器 Linux
一个可用于企业开发及通用跨平台的Makefile文件
一款适用于企业级开发的通用跨平台Makefile,支持C/C++混合编译、多目标输出(可执行文件、静态/动态库)、Release/Debug版本管理。配置简洁,仅需修改带`MF_CONFIGURE_`前缀的变量,支持脚本化配置与子Makefile管理,具备完善日志、错误提示和跨平台兼容性,附详细文档与示例,便于学习与集成。
309 116
|
20天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
7天前
|
数据采集 人工智能 自然语言处理
Meta SAM3开源:让图像分割,听懂你的话
Meta发布并开源SAM 3,首个支持文本或视觉提示的统一图像视频分割模型,可精准分割“红色条纹伞”等开放词汇概念,覆盖400万独特概念,性能达人类水平75%–80%,推动视觉分割新突破。
505 45
Meta SAM3开源:让图像分割,听懂你的话
|
14天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
697 222
|
2天前
|
Windows
dll错误修复 ,可指定下载dll,regsvr32等
dll错误修复 ,可指定下载dll,regsvr32等
137 95
|
12天前
|
人工智能 移动开发 自然语言处理
2025最新HTML静态网页制作工具推荐:10款免费在线生成器小白也能5分钟上手
晓猛团队精选2025年10款真正免费、无需编程的在线HTML建站工具,涵盖AI生成、拖拽编辑、设计稿转代码等多种类型,均支持浏览器直接使用、快速出图与文件导出,特别适合零基础用户快速搭建个人网站、落地页或企业官网。
1714 158
|
存储 人工智能 监控
从代码生成到自主决策:打造一个Coding驱动的“自我编程”Agent
本文介绍了一种基于LLM的“自我编程”Agent系统,通过代码驱动实现复杂逻辑。该Agent以Python为执行引擎,结合Py4j实现Java与Python交互,支持多工具调用、记忆分层与上下文工程,具备感知、认知、表达、自我评估等能力模块,目标是打造可进化的“1.5线”智能助手。
954 62