nagios插件之监控多个tomcat线程数
来源:互联网 发布:java ee eclipse 编辑:程序博客网 时间:2024/06/05 06:43
vi check_multi_tomcat_threads.c
#include <stdio.h>#include <stdlib.h>#include <string.h>#define OK 0#define WARNING 1#define CRITICAL 2#define UNKNOWN 3#define LEN 1000#define MIN_LEN 100#define CMD1 "ps -efL | grep apache-tomcat-cuservice |grep -v grep | wc -l"#define CMD2 "ps -efL | grep apache-tomcat-finance |grep -v grep | wc -l"#define CMD3 "ps -efL | grep apache-tomcat-interface |grep -v grep | wc -l"#define CMD4 "ps -efL | grep apache-tomcat-payment |grep -v grep | wc -l"#define CMD5 "ps -efL | grep apache-tomcat-7.0.41 |grep -v grep | wc -l"int i=0;int exitstatus=OK;char *exit_status[4]={"OK","WARNING","CRITICAL","UNKNOWN"};char cuservice_count[MIN_LEN]={0};char finance_count[MIN_LEN]={0};char interface_count[MIN_LEN]={0};char payment_count[MIN_LEN]={0};char tomcat7041_count[MIN_LEN]={0};char status_information[LEN]={0};char performance_data[LEN]={0};char *cmd_array[]={"ps -efL | grep apache-tomcat-cuservice |grep -v grep | wc -l","ps -efL | grep apache-tomcat-finance |grep -v grep | wc -l","ps -efL | grep apache-tomcat-interface |grep -v grep | wc -l","ps -efL | grep apache-tomcat-payment |grep -v grep | wc -l","ps -efL | grep apache-tomcat-7.0.41 |grep -v grep | wc -l"};int parse_cmd(char *cmd_array) {//printf("%s\n",cmd_array); int ret; FILE *fp; char readbuf[MIN_LEN]={0};char cmd_string[MIN_LEN]={0};//strncpy(cmd_string,cmd_array,MIN_LEN);//sprintf(cmd_string,cmd_array,strlen(cmd_array));//printf("cmd_string=%s\n",cmd_string);//int i;//char *p,*str;//memset(readbuf,0,MIN_LEN);fp=popen(cmd_array,"r");//fp=popen(cmd_string,"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");}//printf("readbuf=%s\n",readbuf);//printf("i=%d\n",i);switch (i) {case 0:strncpy(cuservice_count,readbuf,MIN_LEN);//printf("0000000000\n");break;case 1:strncpy(finance_count,readbuf,MIN_LEN);//printf("1111111111\n");break;case 2:strncpy(interface_count,readbuf,MIN_LEN);//printf("2222222222\n");break;case 3:strncpy(payment_count,readbuf,MIN_LEN);//printf("3333333333\n");break;case 4:strncpy(tomcat7041_count,readbuf,MIN_LEN);//printf("4444444444\n");break;default://printf("5555555555\n");break;} // } ret=fclose(fp); if(fp==NULL) { fprintf(stderr,"popen() error.\n"); return -1; }return 0;}int main() { int ret;// clean //memset(cuservice_count,0,MIN_LEN);//memset(finance_count,0,MIN_LEN);//memset(interface_count,0,MIN_LEN);//memset(payment_count,0,MIN_LEN);//memset(tomcat7041_count,0,MIN_LEN);for(i=0;i<5;i++) {ret=parse_cmd(cmd_array[i]);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("cuservice_count=%s\n",cuservice_count);//printf("finance_count=%s\n",finance_count);//printf("interface_count=%s\n",interface_count);//printf("payment_count=%s\n",payment_count);//printf("tomcat7041_count=%s\n",tomcat7041_count);if(atoi(cuservice_count)<400 && atoi(finance_count)<400 && atoi(interface_count)<400 && atoi(payment_count)<400 && atoi(tomcat7041_count)<400) {exitstatus=OK;}else if(atoi(cuservice_count)>=400 && atoi(cuservice_count)<450 || atoi(finance_count)>=400 && atoi(finance_count)<450 || atoi(interface_count)>=400 && atoi(interface_count)<450 || atoi(payment_count)>=400 && atoi(payment_count)<450 || atoi(tomcat7041_count)>=400 && atoi(tomcat7041_count)<450) {exitstatus=WARNING;}else if(atoi(cuservice_count)>=450 || atoi(finance_count)>=450 || atoi(interface_count)>=450 || atoi(payment_count)>=450 || atoi(tomcat7041_count)>=450) {exitstatus=CRITICAL;}sprintf(status_information,"cuservice_count=%s, finance_count=%s, interface_count=%s, payment_count=%s, tomcat7041_count=%s",cuservice_count,finance_count,interface_count,payment_count,tomcat7041_count);sprintf(performance_data,"cuservice_count=%s;400;450;0; finance_count=%s;400;450;0; interface_count=%s;400;450;0; payment_count=%s;400;450;0; tomcat7041_count=%s;400;450;0;",cuservice_count,finance_count,interface_count,payment_count,tomcat7041_count); printf("%s: %s | %s\n",exit_status[exitstatus],status_information,performance_data); return exitstatus;}
0 0
- nagios插件之监控多个tomcat线程数
- nagios插件之监控单个tomcat线程数
- nagios插件之监控mqa线程数
- nagios插件之监控多个tomcat日志
- nagios插件之监控单个tomcat日志
- Nagios 监控 多个tomcat服务
- nagios插件之监控f5的VS会话数
- nagios插件之系统打开文件数监控
- nagios插件之登陆SBC监控电话数
- nagios插件之监控f5pool中cngw主机session数
- nagios插件之监控M1KB语音网关通话数
- nagios插件之监控MQA日志文件
- nagios插件之监控POI搜索情况
- nagios插件之监控web页面登陆
- nagios插件之监控获取driverID
- nagios插件之监控casa业务
- nagios插件之监控if8接口日志
- nagios插件之域名超时监控
- Android之sqlite操作
- Android中View绘制流程以及invalidate()等相关方法分析
- 堆栈顺序存储结构实现3——遍历查看个数元素
- C++运算符重载(12) - 重载数组索引操作符[]
- android 实现手机方向识别
- nagios插件之监控多个tomcat线程数
- LeetCode 215:Kth Largest Element in an Array
- OpenWRT 路由配置技巧
- Android学习之 Scroller的介绍与使用
- Golang学习笔记--log包
- 仿小米MIUI卸载APP的动画(NineOld实现)
- C++异常(1) - 异常介绍
- 计算机网络各层协议
- Hadoop之——有趣问答(一)