The Nagios plugin monitors multiple tomcat threads

Source: Internet
Author: User
Tags strtok


#include <stdio.h> #include <stdlib.h> #include <string.h> #define OK 0#define WARNING 1#define crit ICAL 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 (stde RR, "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 ");        } 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 (Interf Ace_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) >=4XX && 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;}

Nagios Plug-in monitors multiple tomcat threads

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.