82 |
#define RUN "/_runtime" |
#define RUN "/_runtime" |
83 |
#define VIEWLOG "/_viewlog" |
#define VIEWLOG "/_viewlog" |
84 |
|
|
|
/* Status output formats */ |
|
|
#define XML_STATUS 0 |
|
|
#define TEXT_STATUS 1 |
|
|
|
|
85 |
/* Private prototypes */ |
/* Private prototypes */ |
86 |
static int is_readonly(HttpRequest); |
static int is_readonly(HttpRequest); |
87 |
static void printPixel(HttpResponse); |
static void printPixel(HttpResponse); |
124 |
static void print_service_params_checksum(HttpResponse, Service_T); |
static void print_service_params_checksum(HttpResponse, Service_T); |
125 |
static void print_service_params_process(HttpResponse, Service_T); |
static void print_service_params_process(HttpResponse, Service_T); |
126 |
static void print_status(HttpRequest, HttpResponse); |
static void print_status(HttpRequest, HttpResponse); |
127 |
static void status_system_txt(HttpResponse); |
static void status_system_txt(HttpResponse, short); |
128 |
static void status_service_txt(Service_T, HttpResponse); |
static void status_service_txt(Service_T, HttpResponse, short); |
129 |
static char *get_service_status_html(Service_T); |
static char *get_service_status_html(Service_T); |
130 |
static char *get_service_status_text(Service_T); |
static char *get_service_status_text(Service_T); |
131 |
|
|
2066 |
|
|
2067 |
|
|
2068 |
/* Print status in the given format. Text status is default. */ |
/* Print status in the given format. Text status is default. */ |
2069 |
static void print_status(HttpRequest req, HttpResponse res) { |
static void print_status(HttpRequest req, HttpResponse res) |
2070 |
|
{ |
2071 |
Service_T s; |
Service_T s; |
2072 |
const char *format= get_parameter(req, "format"); |
short level = LEVEL_FULL; |
2073 |
|
const char *stringFormat = get_parameter(req, "format"); |
2074 |
|
const char *stringLevel = get_parameter(req, "level"); |
2075 |
|
|
2076 |
if(format && Util_startsWith(format, "xml")) |
if(stringLevel && Util_startsWith(stringLevel, LEVEL_NAME_SUMMARY)) |
2077 |
{ |
{ |
2078 |
char *D = status_xml(NULL); |
level = LEVEL_SUMMARY; |
2079 |
set_content_type(res, "text/xml"); |
} |
2080 |
|
|
2081 |
|
if(stringFormat && Util_startsWith(stringFormat, "xml")) |
2082 |
|
{ |
2083 |
|
char *D = status_xml(NULL, level); |
2084 |
out_print(res, "%s", D); |
out_print(res, "%s", D); |
2085 |
FREE(D); |
FREE(D); |
2086 |
|
set_content_type(res, "text/xml"); |
2087 |
} |
} |
2088 |
else |
else |
2089 |
{ |
{ |
2090 |
set_content_type(res, "text/plain"); |
char *uptime = Util_getUptime(Util_getProcessUptime(Run.pidfile), " "); |
2091 |
if(Run.doprocess) { |
out_print(res, "The monit daemon %s uptime: %s\n\n", VERSION, uptime); |
2092 |
status_system_txt(res); |
FREE(uptime); |
2093 |
|
|
2094 |
|
if(Run.doprocess) |
2095 |
|
{ |
2096 |
|
status_system_txt(res, level); |
2097 |
} |
} |
2098 |
for(s= servicelist_conf; s; s= s->next_conf) |
for(s= servicelist_conf; s; s= s->next_conf) |
2099 |
{ |
{ |
2100 |
status_service_txt(s, res); |
status_service_txt(s, res, level); |
2101 |
} |
} |
2102 |
|
set_content_type(res, "text/plain"); |
2103 |
} |
} |
2104 |
} |
} |
2105 |
|
|
2106 |
|
|
2107 |
static void status_system_txt(HttpResponse res) { |
static void status_system_txt(HttpResponse res, short level) { |
2108 |
|
char time[STRLEN]; |
2109 |
|
|
2110 |
char *uptime; |
if(level == LEVEL_SUMMARY) |
2111 |
char time[STRLEN]; |
{ |
2112 |
|
char prefix[STRLEN]; |
2113 |
|
|
2114 |
uptime= Util_getUptime(Util_getProcessUptime(Run.pidfile), " "); |
snprintf(prefix, STRLEN, "System '%s'", Run.localhostname); |
2115 |
out_print(res, |
out_print(res, "%-35s [%.2f] [%.2f] [%.2f]\n", |
2116 |
"The monit daemon %s uptime: %s\n\n", VERSION, uptime); |
prefix, |
2117 |
FREE(uptime); |
systeminfo.loadavg[0], |
2118 |
|
systeminfo.loadavg[1], |
2119 |
|
systeminfo.loadavg[2]); |
2120 |
|
} |
2121 |
|
else |
2122 |
|
{ |
2123 |
|
ctime_r(&systeminfo.collected, time); |
2124 |
|
out_print(res, |
2125 |
|
"System '%s'\n" |
2126 |
|
" %-33s [%.2f] [%.2f] [%.2f]\n" |
2127 |
|
" %-33s %.1f%%us %.1f%%sy" |
2128 |
|
#ifdef HAVE_CPU_WAIT |
2129 |
|
" %.1f%%wa" |
2130 |
|
#endif |
2131 |
|
"\n" |
2132 |
|
" %-33s %ld kB [%.1f%%]\n" |
2133 |
|
" %-33s %s\n", |
2134 |
|
Run.localhostname, |
2135 |
|
"load average", |
2136 |
|
systeminfo.loadavg[0], |
2137 |
|
systeminfo.loadavg[1], |
2138 |
|
systeminfo.loadavg[2], |
2139 |
|
"cpu", |
2140 |
|
systeminfo.total_cpu_user_percent/10., |
2141 |
|
systeminfo.total_cpu_syst_percent/10., |
2142 |
|
#ifdef HAVE_CPU_WAIT |
2143 |
|
systeminfo.total_cpu_wait_percent/10., |
2144 |
|
#endif |
2145 |
|
"memory usage", |
2146 |
|
systeminfo.total_mem_kbyte, |
2147 |
|
systeminfo.total_mem_percent/10., |
2148 |
|
"data collected", |
2149 |
|
time); |
2150 |
|
} |
2151 |
|
|
2152 |
ctime_r(&systeminfo.collected, time); |
} |
|
out_print(res, |
|
|
"System '%s'\n" |
|
|
" %-33s [%.2f] [%.2f] [%.2f]\n" |
|
|
" %-33s %.1f%%us %.1f%%sy" |
|
|
#ifdef HAVE_CPU_WAIT |
|
|
" %.1f%%wa" |
|
|
#endif |
|
|
"\n" |
|
|
" %-33s %ld kB [%.1f%%]\n" |
|
|
" %-33s %s", |
|
|
Run.localhostname, |
|
|
"load average", |
|
|
systeminfo.loadavg[0], |
|
|
systeminfo.loadavg[1], |
|
|
systeminfo.loadavg[2], |
|
|
"cpu", |
|
|
systeminfo.total_cpu_user_percent/10., |
|
|
systeminfo.total_cpu_syst_percent/10., |
|
|
#ifdef HAVE_CPU_WAIT |
|
|
systeminfo.total_cpu_wait_percent/10., |
|
|
#endif |
|
|
"memory usage", |
|
|
systeminfo.total_mem_kbyte, |
|
|
systeminfo.total_mem_percent/10., |
|
|
"data collected", |
|
|
time); |
|
2153 |
|
|
|
out_print(res, "\n"); |
|
2154 |
|
|
2155 |
} |
static void status_service_txt(Service_T s, HttpResponse res, short level) { |
2156 |
|
char *status = get_service_status_text(s); |
2157 |
|
|
2158 |
|
if(level == LEVEL_SUMMARY) |
2159 |
|
{ |
2160 |
|
char prefix[STRLEN]; |
2161 |
|
|
2162 |
|
snprintf(prefix, STRLEN, "%s '%s'", servicetypes[s->type], s->name); |
2163 |
|
out_print(res, "%-35s %s\n", prefix, status); |
2164 |
|
} |
2165 |
|
else |
2166 |
|
{ |
2167 |
|
char time[STRLEN]; |
2168 |
|
|
2169 |
static void status_service_txt(Service_T s, HttpResponse res) { |
out_print(res, |
|
char time[STRLEN]; |
|
|
char *status; |
|
|
status= get_service_status_text(s); |
|
|
out_print(res, |
|
2170 |
"%s '%s'\n" |
"%s '%s'\n" |
2171 |
" %-33s %s\n" |
" %-33s %s\n" |
2172 |
" %-33s %s\n", |
" %-33s %s\n", |
2173 |
servicetypes[s->type], s->name, |
servicetypes[s->type], s->name, |
2174 |
"status", status, |
"status", status, |
2175 |
"monitoring status", monitornames[s->monitor]); |
"monitoring status", monitornames[s->monitor]); |
2176 |
FREE(status); |
|
2177 |
if(Util_hasServiceStatus(s)) { |
if(Util_hasServiceStatus(s)) { |
2178 |
if(s->type == TYPE_FILE || s->type == TYPE_DIRECTORY || |
if(s->type == TYPE_FILE || s->type == TYPE_DIRECTORY || |
2179 |
s->type == TYPE_DEVICE) { |
s->type == TYPE_DEVICE) { |
2180 |
out_print(res, |
out_print(res, |
2181 |
" %-33s %o\n" |
" %-33s %o\n" |
2182 |
" %-33s %d\n" |
" %-33s %d\n" |
2183 |
" %-33s %d\n", |
" %-33s %d\n", |
2184 |
"permission", s->inf->st_mode & 07777, |
"permission", s->inf->st_mode & 07777, |
2185 |
"uid", (int)s->inf->st_uid, |
"uid", (int)s->inf->st_uid, |
2186 |
"gid", (int)s->inf->st_gid); |
"gid", (int)s->inf->st_gid); |
2187 |
} |
} |
2188 |
if(s->type == TYPE_FILE || s->type == TYPE_DIRECTORY) { |
if(s->type == TYPE_FILE || s->type == TYPE_DIRECTORY) { |
2189 |
ctime_r(&s->inf->timestamp, time); |
ctime_r(&s->inf->timestamp, time); |
2190 |
out_print(res, |
out_print(res, |
2191 |
" %-33s %s", |
" %-33s %s", |
2192 |
"timestamp", time); |
"timestamp", time); |
2193 |
} |
} |
2194 |
if(s->type == TYPE_FILE) { |
if(s->type == TYPE_FILE) { |
2195 |
out_print(res, |
out_print(res, |
2196 |
" %-33s %lu B\n", |
" %-33s %lu B\n", |
2197 |
"size", (unsigned long) s->inf->st_size); |
"size", (unsigned long) s->inf->st_size); |
2198 |
if(s->checksum) { |
if(s->checksum) { |
2199 |
out_print(res, |
out_print(res, |
2200 |
" %-33s %s(%s)\n", |
" %-33s %s(%s)\n", |
2201 |
"checksum", s->inf->cs_sum, |
"checksum", s->inf->cs_sum, |
2202 |
checksumnames[s->checksum->type]); |
checksumnames[s->checksum->type]); |
2203 |
} |
} |
2204 |
} |
} |
2205 |
if(s->type == TYPE_DEVICE) { |
if(s->type == TYPE_DEVICE) { |
2206 |
out_print(res, |
out_print(res, |
2207 |
" %-33s %ld B\n" |
" %-33s %ld B\n" |
2208 |
" %-33s %ld [%.1f MB]\n" |
" %-33s %ld [%.1f MB]\n" |
2209 |
" %-33s %ld [%.1f MB] [%.1f%%]\n" |
" %-33s %ld [%.1f MB] [%.1f%%]\n" |
2210 |
" %-33s %ld [%.1f MB] [%.1f%%]\n", |
" %-33s %ld [%.1f MB] [%.1f%%]\n", |
2211 |
"block size", |
"block size", |
2212 |
s->inf->f_bsize, |
s->inf->f_bsize, |
2213 |
"blocks total", |
"blocks total", |
2214 |
s->inf->f_blocks, |
s->inf->f_blocks, |
2215 |
((float)s->inf->f_blocks/(float)1048576* |
((float)s->inf->f_blocks/(float)1048576* |
2216 |
(float)s->inf->f_bsize), |
(float)s->inf->f_bsize), |
2217 |
"blocks free for non superuser", |
"blocks free for non superuser", |
2218 |
s->inf->f_blocksfree, |
s->inf->f_blocksfree, |
2219 |
((float)s->inf->f_blocksfree/(float)1048576* |
((float)s->inf->f_blocksfree/(float)1048576* |
2220 |
(float)s->inf->f_bsize), |
(float)s->inf->f_bsize), |
2221 |
((float)100*(float)s->inf->f_blocksfree/ |
((float)100*(float)s->inf->f_blocksfree/ |
2222 |
(float)s->inf->f_blocks), |
(float)s->inf->f_blocks), |
2223 |
"blocks free total", |
"blocks free total", |
2224 |
s->inf->f_blocksfreetotal, |
s->inf->f_blocksfreetotal, |
2225 |
((float)s->inf->f_blocksfreetotal/(float)1048576* |
((float)s->inf->f_blocksfreetotal/(float)1048576* |
2226 |
(float)s->inf->f_bsize), |
(float)s->inf->f_bsize), |
2227 |
((float)100*(float)s->inf->f_blocksfreetotal/ |
((float)100*(float)s->inf->f_blocksfreetotal/ |
2228 |
(float)s->inf->f_blocks)); |
(float)s->inf->f_blocks)); |
2229 |
if(s->inf->f_files > 0) { |
if(s->inf->f_files > 0) { |
2230 |
out_print(res, |
out_print(res, |
2231 |
" %-33s %ld\n" |
" %-33s %ld\n" |
2232 |
" %-33s %ld [%.1f%%]\n", |
" %-33s %ld [%.1f%%]\n", |
2233 |
"inodes total", |
"inodes total", |
2234 |
s->inf->f_files, |
s->inf->f_files, |
2235 |
"inodes free", |
"inodes free", |
2236 |
s->inf->f_filesfree, |
s->inf->f_filesfree, |
2237 |
((float)100*(float)s->inf->f_filesfree/ |
((float)100*(float)s->inf->f_filesfree/ |
2238 |
(float)s->inf->f_files)); |
(float)s->inf->f_files)); |
2239 |
} |
} |
2240 |
} |
} |
2241 |
if(s->type == TYPE_PROCESS) { |
if(s->type == TYPE_PROCESS) { |
2242 |
char *uptime= Util_getUptime(s->inf->uptime, " "); |
char *uptime= Util_getUptime(s->inf->uptime, " "); |
2243 |
out_print(res, |
out_print(res, |
2244 |
" %-33s %d\n" |
" %-33s %d\n" |
2245 |
" %-33s %d\n" |
" %-33s %d\n" |
2246 |
" %-33s %s\n", |
" %-33s %s\n", |
2247 |
"pid", s->inf->pid, |
"pid", s->inf->pid, |
2248 |
"parent pid", s->inf->ppid, |
"parent pid", s->inf->ppid, |
2249 |
"uptime", uptime); |
"uptime", uptime); |
2250 |
FREE(uptime); |
FREE(uptime); |
2251 |
if(Run.doprocess) { |
if(Run.doprocess) { |
2252 |
out_print(res, |
out_print(res, |
2253 |
" %-33s %d\n" |
" %-33s %d\n" |
2254 |
" %-33s %ld\n" |
" %-33s %ld\n" |
2255 |
" %-33s %ld\n" |
" %-33s %ld\n" |
2256 |
" %-33s %.1f%%\n" |
" %-33s %.1f%%\n" |
2257 |
" %-33s %.1f%%\n" |
" %-33s %.1f%%\n" |
2258 |
" %-33s %.1f%%\n" |
" %-33s %.1f%%\n" |
2259 |
" %-33s %.1f%%\n", |
" %-33s %.1f%%\n", |
2263 |
"memory percent", s->inf->mem_percent/10.0, |
"memory percent", s->inf->mem_percent/10.0, |
2264 |
"memory percent total", s->inf->total_mem_percent/10.0, |
"memory percent total", s->inf->total_mem_percent/10.0, |
2265 |
"cpu percent", s->inf->cpu_percent/10.0, |
"cpu percent", s->inf->cpu_percent/10.0, |
2266 |
"cpu percent total", s->inf->total_cpu_percent/10.0); |
"cpu percent total", s->inf->total_cpu_percent/10.0); |
2267 |
|
} |
2268 |
} |
} |
2269 |
} |
if(s->type == TYPE_HOST && s->icmplist) { |
2270 |
if(s->type == TYPE_HOST && s->icmplist) { |
Icmp_T i; |
2271 |
Icmp_T i; |
for(i= s->icmplist; i; i= i->next) { |
2272 |
for(i= s->icmplist; i; i= i->next) { |
out_print(res, |
2273 |
out_print(res, |
" %-33s %.3fs [%s]\n", |
2274 |
" %-33s %.3fs [%s]\n", |
"icmp response time", i->is_available?i->response:-1., |
2275 |
"icmp response time", i->is_available?i->response:-1., |
icmpnames[i->type]); |
2276 |
icmpnames[i->type]); |
} |
2277 |
} |
} |
2278 |
} |
if((s->type == TYPE_HOST || s->type == TYPE_PROCESS) && s-> portlist) { |
2279 |
if((s->type == TYPE_HOST || s->type == TYPE_PROCESS) && s-> portlist) { |
Port_T p; |
2280 |
Port_T p; |
for(p= s->portlist; p; p= p->next) { |
2281 |
for(p= s->portlist; p; p= p->next) { |
if(p->family == AF_INET) { |
2282 |
if(p->family == AF_INET) { |
out_print(res, |
2283 |
out_print(res, |
" %-33s %.3fs to %s:%d%s [%s%s]\n", |
2284 |
" %-33s %.3fs to %s:%d%s [%s%s]\n", |
"port response time", p->is_available?p->response:-1., |
2285 |
"port response time", p->is_available?p->response:-1., |
p->hostname, |
|
p->hostname, |
|
2286 |
p->port, p->request?p->request:"", p->protocol->name, |
p->port, p->request?p->request:"", p->protocol->name, |
2287 |
p->SSL.use_ssl?" via SSL":""); |
p->SSL.use_ssl?" via SSL":""); |
2288 |
} else if(p->family == AF_UNIX) { |
} else if(p->family == AF_UNIX) { |
2289 |
out_print(res, |
out_print(res, |
2290 |
" %-33s %.3fs to %s [%s]\n", |
" %-33s %.3fs to %s [%s]\n", |
2291 |
"unix socket response time", p->is_available?p->response:-1., |
"unix socket response time", p->is_available?p->response:-1., |
2292 |
p->pathname, p->protocol->name); |
p->pathname, p->protocol->name); |
2293 |
} |
} |
2294 |
|
} |
2295 |
} |
} |
2296 |
} |
} |
2297 |
|
ctime_r(&s->collected, time); |
2298 |
|
out_print(res, " %-33s %s\n", "data collected", time); |
2299 |
} |
} |
2300 |
ctime_r(&s->collected, time); |
FREE(status); |
|
out_print(res, " %-33s %s\n", "data collected", time); |
|
2301 |
} |
} |
2302 |
|
|
2303 |
|
|