nagios插件之监控单个tomcat线程数

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define OK       0
#define WARNING  1
#define CRITICAL 2
#define UNKNOWN  3

#define LEN 1023

#define CMD "ps -efL | grep tomcat  | wc -l"

int exitstatus=OK;
char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"};

char status_information[LEN];
char performance_data[LEN];

int parse_cmd() {
        int ret;
        FILE *fp;
        char readbuf[1024];

        int i;
        char *p,*str;

        fp=popen(CMD,"r");
        if(fp==NULL) {
                fprintf(stderr,"popen() error.\n");
                return -1;
        }

       // while(fgets(readbuf,1024,fp)!=NULL) {
		/*
                for(p=strtok(readbuf," ");p;p=strtok(NULL," ")) {
                //      str=p;

                        sprintf(status_information,"active call=%s",p);

                        sprintf(performance_data,"call=%s;;;;",p);

                        break;
                }

                break;
		*/

	//	readbuf[strlen(readbuf)-1]=0;
		ret=fscanf(fp,"%s",readbuf);
		if(ret!=1) {
			fprintf(stderr,"fscanf() error.\n");
		}

		if(atoi(readbuf)<300) {
			exitstatus=OK;	
		}
		else if(atoi(readbuf)>=300 && atoi(readbuf)<=400) {
			exitstatus=WARNING;	
		}
		else if(atoi(readbuf)>=400) {
			exitstatus=CRITICAL;
		}

                sprintf(status_information,"tomcat_threads=%s",readbuf);

                sprintf(performance_data,"tomcat_threads=%s;;;;",readbuf);
       // }

        ret=pclose(fp);
        if(fp==NULL) {
                fprintf(stderr,"pclose() error.\n");
                return -1;
        }
}

int main() {
        int ret;

	ret=parse_cmd();
	if(ret!=0) {
		fprintf(stderr,"parse_cmd() error.\n");
               // exitstatus=CRITICAL;
               // printf("%s: - %s | %s\n",exit_status[exitstatus],status_information,performance_data);
		exit(-1);
	}

        printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data);

        return exitstatus;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值