本帖最后由 monicazhang 于 2016-1-11 17:53 编辑  
 
来自:网络 1: 监控进程运行时间的脚本如下:                    nagios培训  
? 
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 
#!/bin/sh 
STATE_OK=0 
STATE_CRITICAL=2 
STATE_UNKNOWN=3 
if [ $# -eq 1 ];then 
        myprocss=$1 
        starttime=`ps -eo lstart,cmd |grep "${myprocss}"|grep -v grep|grep -v check_process_starttime|grep -v bash|head - 
1|cut -b 1-24` 
        if [[ -n ${starttime} ]];then 
                starttimeseconds=`date +%s -d "${starttime}"`                   nagios实施  
                curenttimeseconds=`date +%s` 
                let difftimeseconds=curenttimeseconds-starttimeseconds 
                if [ $difftimeseconds -gt 300 ];then 
                        echo "CRITICAL,starttime is ${difftimeseconds} seconds.|starttime=${difftimeseconds}" 
                        exit ${STATE_CRITICAL} 
                else 
                        echo "OK,starttime is ${difftimeseconds} seconds.|starttime=${difftimeseconds}" 
                        exit ${STATE_OK} 
                fi 
        else 
                echo "OK,starttime is ok.|starttime=0"            监控软件  
                exit $STATE_OK 
        fi 
else 
        echo "UNKNOWN,starttime is unknown.|starttime=-1" 
        exit $STATE_UNKNOWN 
fi 
 
2: 脚本使用说明 
    脚本只需要传一个参数,就是进程的名字。sh check_process_starttime 'init'         nagios配置  
    脚本是按照nagios插件格式来写的              nagios安装  
 
3: 脚本说明 
    ps -eo lstart获取脚本的启动时间,然后跟当前时间进行对比,如果超过300s,也就是已经运行了5分钟,就进行告警。 
 
4: 脚本待优化说明 
    1: 可以让critical的阀值由参数传递进去。                  开源监控软件  
    2: 得支持多个进程同时探测 
 
 
想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 :476809427  |