00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "config.h"
00021
00022 #ifdef HAVE_SYS_TYPES_H
00023 #include <sys/types.h>
00024 #endif
00025
00026 #ifdef HAVE_SYS_STAT_H
00027 #include <sys/stat.h>
00028 #endif
00029
00030 #ifdef HAVE_FCNTL_H
00031 #include <fcntl.h>
00032 #endif
00033
00034 #ifdef HAVE_STDLIB_H
00035 #include <stdlib.h>
00036 #endif
00037
00038 #ifdef TIME_WITH_SYS_TIME
00039 #include <time.h>
00040
00041 #ifdef HAVE_SYS_TIME
00042 #include <sys/time.h>
00043 #endif
00044 #else
00045 #include <time.h>
00046 #endif
00047
00048 #ifdef HAVE_SYS_LOADAVG_H
00049 #include <sys/loadavg.h>
00050 #endif
00051
00052 #ifdef HAVE_STRING_H
00053 #include <string.h>
00054 #endif
00055
00056 #include <stdio.h>
00057
00058 #include "monitor.h"
00059 #include "monit_process.h"
00060 #include "process/process.h"
00061
00074
00075
00076
00077 int include_children= TRUE;
00078 char actionnames[][STRLEN]={"ignore", "alert", "restart", "stop"};
00079 char operatornames[][STRLEN]={"greater than", "less than",
00080 "equal to", "not equal to"};
00081 char operatorshortnames[][3]={">", "<", "=", "!="};
00082
00083
00088 int init_process_info(void) {
00089
00090 return (init_process_info_sysdep());
00091
00092 }
00093
00094
00102 int update_process_data(Process_T p, pid_t pid) {
00103
00104 ProcInfo_T pi= p->procinfo;
00105
00106 pi->pid=pid;
00107
00108 if (! get_process_info(pi)) {
00109
00110 return FALSE;
00111
00112 }
00113
00114 return TRUE;
00115 }
00116
00117
00124 int compare_resource(int value, Resource_T q) {
00125
00126 switch ( q->operator ) {
00127
00128 case RESOURCE_OPERATOR_GREATER:
00129 if ( value > q->limit ) {
00130
00131 return TRUE;
00132
00133 } else {
00134
00135 return FALSE;
00136
00137 }
00138
00139 case RESOURCE_OPERATOR_LESS:
00140 if ( value < q->limit ) {
00141
00142 return TRUE;
00143
00144 } else {
00145
00146 return FALSE;
00147
00148 }
00149
00150 case RESOURCE_OPERATOR_EQUAL:
00151 if ( value == q->limit ) {
00152
00153 return TRUE;
00154
00155 } else {
00156
00157 return FALSE;
00158
00159 }
00160
00161 case RESOURCE_OPERATOR_NOTEQUAL:
00162 if ( value != q->limit ) {
00163
00164
00165 return TRUE;
00166
00167 } else {
00168
00169 return FALSE;
00170
00171 }
00172
00173 default:
00174
00175 log("Unknow resource comparison operator.\n");
00176
00177
00178
00179 return FALSE;
00180
00181 }
00182 }
00183
00184
00189 int update_loadavg(void) {
00190
00191 if ( -1 == getloadavg( Run.loadavg, 3) ) {
00192
00193 return FALSE;
00194
00195 }
00196
00197 return TRUE;
00198 }