Actions
Feature #2432
closedAdding JSON Output support to mod_status (patch)
ASK QUESTIONS IN Forums:
Description
I think a much simpler parseable format for the mod_status text based output should be used. It adds the ability to easily monitor remote lighttpd instances. Currently the 5s average traffic values are missing also.
It would be nice if you can add this to the next release :)
Thank you in advance
I've just replaced mod_status_handle_server_status_text in mod_status.c with the following code:
/* JSON TEXT */ static handler_t mod_status_handle_server_status_text(server *srv, connection *con, void *p_d) { plugin_data *p = p_d; buffer *b; double avg; time_t ts; char buf[32]; size_t j; b = chunkqueue_get_append_buffer(con->write_queue); /* output total number of requests */ buffer_append_string_len(b, CONST_STR_LEN("{\n\tRequests: ")); avg = p->abs_requests; snprintf(buf, sizeof(buf) - 1, "%.0f", avg); buffer_append_string(b, buf); buffer_append_string_len(b, CONST_STR_LEN(",\n")); /* output total traffic out in kbytes */ buffer_append_string_len(b, CONST_STR_LEN("\tTraffic: ")); avg = p->abs_traffic_out / 1024; snprintf(buf, sizeof(buf) - 1, "%.0f", avg); buffer_append_string(b, buf); buffer_append_string_len(b, CONST_STR_LEN(",\n")); /* output uptime */ buffer_append_string_len(b, CONST_STR_LEN("\tUptime: ")); ts = srv->cur_ts - srv->startup_ts; buffer_append_long(b, ts); buffer_append_string_len(b, CONST_STR_LEN(",\n")); /* output busy servers */ buffer_append_string_len(b, CONST_STR_LEN("\tBusyServers: ")); buffer_append_long(b, srv->conns->used); buffer_append_string_len(b, CONST_STR_LEN(",\n")); buffer_append_string_len(b, CONST_STR_LEN("\tIdleServers: ")); buffer_append_long(b, srv->conns->size - srv->conns->used); buffer_append_string_len(b, CONST_STR_LEN(",\n")); /* average request last 5s */ for (j = 0, avg = 0; j < 5; j++) { avg += p->mod_5s_requests[j]; } avg /= 5; buffer_append_string_len(b, CONST_STR_LEN("\tRequestsAVG5s: ")); buffer_append_long(b, avg); buffer_append_string_len(b, CONST_STR_LEN(",\n")); /* average traffic last 5s */ for (j = 0, avg = 0; j < 5; j++) { avg += p->mod_5s_traffic_out[j] / 1024; } avg /= 5; buffer_append_string_len(b, CONST_STR_LEN("\tTrafficAVG5s: ")); sprintf(buf, "%.2f", avg); buffer_append_string(b, buf); buffer_append_string_len(b, CONST_STR_LEN("\n}")); /* set text/plain output */ response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/javascript")); return 0; }
It will produce an output like:
{ Requests: 83, Traffic: 23, Uptime: 254, BusyServers: 6, IdleServers: 122, RequestsAVG5s: 7, TrafficAVG5s: 1.83 }
Files
Added by gstrauss almost 9 years ago
Actions
Also available in: Atom
[mod_status] add JSON output option (fixed #2432)
x-ref:
"Adding JSON Output support to mod_status (patch)"
https://redmine.lighttpd.net/issues/2432