mod_status.c revision 1ca054782cb35b5f67686a41b1df75c269fa617b
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Status Module. Display lots of internal data about how Apache is
* performing and the state of all children processes.
*
* To enable this, add the following lines into any config file:
*
* <Location /server-status>
* SetHandler server-status
* </Location>
*
* You may want to protect this location by password or domain so no one
* else can look at it. Then you can access the statistics with a URL like:
*
*
* /server-status - Returns page using tables
* /server-status?notable - Returns page for browsers without table support
* /server-status?refresh - Returns page with 1 second refresh
* /server-status?refresh=6 - Returns page with refresh every 6 seconds
* /server-status?auto - Returns page with data for automatic parsing
*
* Mark Cox, mark@ukweb.com, November 1995
*
* 12.11.95 Initial version for www.telescope.org
* 13.3.96 Updated to remove rprintf's [Mark]
* 18.3.96 Added CPU usage, process information, and tidied [Ben Laurie]
* 18.3.96 Make extra Scoreboard variables #definable
* 25.3.96 Make short report have full precision [Ben Laurie suggested]
* 09.4.96 Added message for non-STATUS compiled version
* 18.4.96 Added per child and per slot counters [Jim Jagielski]
* 18.5.96 Adapted to use new rprintf() routine, incidentally fixing a missing
* piece in short reports [Ben Laurie]
* 21.5.96 Additional Status codes (DNS and LOGGING only enabled if
* 10.8.98 Allow for extended status info at runtime (no more STATUS)
* [Jim J.]
*/
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "ap_mpm.h"
#include "util_script.h"
#include <time.h>
#include "scoreboard.h"
#include "http_log.h"
#include "mod_status.h"
#include <unistd.h>
#endif
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "apr_strings.h"
#ifdef NEXT
#if (NX_CURRENT_COMPILER_RELEASE == 410)
#ifdef m68k
#define HZ 64
#else
#define HZ 100
#endif
#else
#endif
#endif /* NEXT */
#define STATUS_MAXLINE 64
#define KBYTE 1024
#define MBYTE 1048576L
#define GBYTE 1073741824L
#ifndef DEFAULT_TIME_FORMAT
#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
#endif
#define STATUS_MAGIC_TYPE "application/x-httpd-status"
static int server_limit, thread_limit;
/* Implement 'ap_run_status_hook'. */
(request_rec *r, int flags),
(r, flags),
#ifdef HAVE_TIMES
/* ugh... need to know if we're running with a pthread implementation
* such as linuxthreads that treats individual threads as distinct
* processes; that affects how we add up CPU time in a process
*/
#endif
/*
* command-related code. This is here to prevent use of ExtendedStatus
* without status_module included.
*/
{
return err;
}
return NULL;
}
{
return err;
}
return NULL;
}
static const command_rec status_module_cmds[] =
{
"\"On\" to enable extended status information, \"Off\" to disable"),
"For verbose requests, \"On\" to see the last 63 chars of the request, "
"\"Off\" (default) to see the first 63 in extended status display"),
{NULL}
};
/* Format the number of bytes nicely */
{
else
}
{
else
}
{
tsecs /= 60;
tsecs /= 60;
if (days)
if (hrs)
if (mins)
if (secs)
}
/* Main handler for x-httpd-status requests */
/* ID values for command table */
#define STAT_OPT_END -1
#define STAT_OPT_REFRESH 0
#define STAT_OPT_NOTABLE 1
#define STAT_OPT_AUTO 2
struct stat_opt {
int id;
const char *form_data_str;
const char *hdr_out_str;
};
{
};
static char status_flags[SERVER_NUM_STATUS];
static int status_handler(request_rec *r)
{
const char *loc;
int j, i, res;
int ready;
int busy;
unsigned long count;
long req_time;
#ifdef HAVE_TIMES
float tick;
#endif
int short_report;
int no_table_report;
char *stat_buffer;
return DECLINED;
}
#ifdef HAVE_TIMES
#ifdef _SC_CLK_TCK
#else
#endif
#endif
ready = 0;
busy = 0;
count = 0;
bcount = 0;
kbcount = 0;
short_report = 0;
no_table_report = 0;
nowtime = apr_time_now();
if (!ap_exists_scoreboard_image()) {
"Server status unavailable in inetd mode");
return HTTP_INTERNAL_SERVER_ERROR;
}
if (r->method_number != M_GET)
return DECLINED;
ap_set_content_type(r, "text/html; charset=ISO-8859-1");
/*
* Simple table-driven form data set parser that lets you alter the header
*/
if (r->args) {
i = 0;
switch (status_options[i].id) {
case STAT_OPT_REFRESH: {
long t = 0;
}
break;
}
case STAT_OPT_NOTABLE:
no_table_report = 1;
break;
case STAT_OPT_AUTO:
ap_set_content_type(r, "text/plain; charset=ISO-8859-1");
short_report = 1;
break;
}
}
i++;
}
}
for (i = 0; i < server_limit; ++i) {
#ifdef HAVE_TIMES
#endif
for (j = 0; j < thread_limit; ++j) {
int indx = (i * thread_limit) + j;
if (res == SERVER_READY
ready++;
else if (res != SERVER_DEAD &&
res != SERVER_STARTING &&
res != SERVER_IDLE_KILL)
busy++;
}
* processes? should they be counted or not? GLA
*/
if (ap_extended_status) {
#ifdef HAVE_TIMES
if (times_per_thread) {
}
else {
}
}
#endif /* HAVE_TIMES */
}
}
}
}
#ifdef HAVE_TIMES
#endif
}
/* up_time in seconds */
if (!short_report) {
"<html><head>\n<title>Apache Status</title>\n</head><body>\n",
r);
ap_rputs("<h1>Apache Server Status for ", r);
ap_rvputs(r, "<dl><dt>Server Version: ",
ap_rvputs(r, "<dt>Server Built: ",
ap_rvputs(r, "<dt>Current Time: ",
"</dt>\n", NULL);
ap_rvputs(r, "<dt>Restart Time: ",
ap_ht_time(r->pool,
DEFAULT_TIME_FORMAT, 0),
"</dt>\n", NULL);
ap_rprintf(r, "<dt>Parent Server Generation: %d</dt>\n",
(int)mpm_generation);
ap_rputs("<dt>Server uptime: ", r);
ap_rputs("</dt>\n", r);
}
if (ap_extended_status) {
if (short_report) {
ap_rprintf(r, "Total Accesses: %lu\nTotal kBytes: %"
APR_OFF_T_FMT "\n",
#ifdef HAVE_TIMES
ap_rprintf(r, "CPULoad: %g\n",
#endif
if (up_time > 0) {
ap_rprintf(r, "ReqPerSec: %g\n",
ap_rprintf(r, "BytesPerSec: %g\n",
}
if (count > 0)
ap_rprintf(r, "BytesPerReq: %g\n",
}
else { /* !short_report */
format_kbyte_out(r, kbcount);
ap_rputs("</dt>\n", r);
#ifdef HAVE_TIMES
ap_rprintf(r, "<dt>CPU Usage: u%g s%g cu%g cs%g",
ap_rprintf(r, " - %.3g%% CPU load</dt>\n",
#endif
if (up_time > 0) {
ap_rprintf(r, "<dt>%.3g requests/sec - ",
/ (float) up_time));
ap_rputs("/second - ", r);
}
if (count > 0) {
/ (float) count));
ap_rputs("/request", r);
}
ap_rputs("</dt>\n", r);
} /* short_report */
} /* ap_extended_status */
if (!short_report)
ap_rprintf(r, "<dt>%d requests currently being processed, "
else
/* send the scoreboard 'table' out */
if (!short_report)
ap_rputs("</dl><pre>", r);
else
ap_rputs("Scoreboard: ", r);
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
int indx = (i * thread_limit) + j;
&& !short_report)
ap_rputs("\n", r);
}
}
if (short_report)
ap_rputs("\n", r);
else {
ap_rputs("</pre>\n", r);
ap_rputs("<p>Scoreboard Key:<br />\n", r);
ap_rputs("\"<b><code>_</code></b>\" Waiting for Connection, \n", r);
ap_rputs("\"<b><code>S</code></b>\" Starting up, \n", r);
ap_rputs("\"<b><code>R</code></b>\" Reading Request,<br />\n", r);
ap_rputs("\"<b><code>W</code></b>\" Sending Reply, \n", r);
ap_rputs("\"<b><code>K</code></b>\" Keepalive (read), \n", r);
ap_rputs("\"<b><code>D</code></b>\" DNS Lookup,<br />\n", r);
ap_rputs("\"<b><code>C</code></b>\" Closing connection, \n", r);
ap_rputs("\"<b><code>L</code></b>\" Logging, \n", r);
ap_rputs("\"<b><code>G</code></b>\" Gracefully finishing,<br /> \n", r);
ap_rputs("\"<b><code>I</code></b>\" Idle cleanup of worker, \n", r);
ap_rputs("\"<b><code>.</code></b>\" Open slot with no current process</p>\n", r);
ap_rputs("<p />\n", r);
if (!ap_extended_status) {
int j;
int k = 0;
ap_rputs("PID Key: <br />\n", r);
ap_rputs("<pre>\n", r);
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
int indx = (i * thread_limit) + j;
" in state: %c ", pid_buffer[i],
stat_buffer[indx]);
if (++k >= 3) {
ap_rputs("\n", r);
k = 0;
} else
ap_rputs(",", r);
}
}
}
ap_rputs("\n", r);
ap_rputs("</pre>\n", r);
}
}
if (ap_extended_status && !short_report) {
if (no_table_report)
ap_rputs("<hr /><h2>Server Details</h2>\n\n", r);
else
ap_rputs("\n\n<table border=\"0\"><tr>"
"<th>Srv</th><th>PID</th><th>Acc</th>"
"<th>M</th>"
#ifdef HAVE_TIMES
"<th>CPU\n</th>"
#endif
"<th>SS</th><th>Req</th>"
"<th>Conn</th><th>Child</th><th>Slot</th>"
"<th>Client</th><th>VHost</th>"
"<th>Request</th></tr>\n\n", r);
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
if (ws_record->access_count == 0 &&
continue;
}
if (ws_record->start_time == 0L)
req_time = 0L;
else
req_time = (long)
if (req_time < 0L)
req_time = 0L;
}
else {
}
if (no_table_report) {
ap_rprintf(r,
"<b>Server %d-%d</b> (-): %d|%lu|%lu [",
i, (int)worker_generation,
else
ap_rprintf(r,
"<b>Server %d-%d</b> (%"
APR_PID_T_FMT "): %d|%lu|%lu [",
i, (int) worker_generation,
case SERVER_READY:
ap_rputs("Ready", r);
break;
case SERVER_STARTING:
ap_rputs("Starting", r);
break;
case SERVER_BUSY_READ:
ap_rputs("<b>Read</b>", r);
break;
case SERVER_BUSY_WRITE:
ap_rputs("<b>Write</b>", r);
break;
case SERVER_BUSY_KEEPALIVE:
ap_rputs("<b>Keepalive</b>", r);
break;
case SERVER_BUSY_LOG:
ap_rputs("<b>Logging</b>", r);
break;
case SERVER_BUSY_DNS:
ap_rputs("<b>DNS lookup</b>", r);
break;
case SERVER_CLOSING:
ap_rputs("<b>Closing</b>", r);
break;
case SERVER_DEAD:
ap_rputs("Dead", r);
break;
case SERVER_GRACEFUL:
ap_rputs("Graceful", r);
break;
case SERVER_IDLE_KILL:
ap_rputs("Dying", r);
break;
default:
ap_rputs("?STATE?", r);
break;
}
ap_rprintf(r, "] "
#ifdef HAVE_TIMES
"u%g s%g cu%g cs%g"
#endif
"\n %ld %ld (",
#ifdef HAVE_TIMES
#endif
(long)apr_time_sec(nowtime -
(long) req_time);
ap_rputs("|", r);
format_byte_out(r, my_bytes);
ap_rputs("|", r);
format_byte_out(r, bytes);
ap_rputs(")\n", r);
ap_rprintf(r,
" <i>%s {%s}</i> <b>[%s]</b><br />\n\n",
ap_escape_html(r->pool,
ap_escape_html(r->pool,
ap_escape_html(r->pool,
}
else { /* !no_table_report */
ap_rprintf(r,
"<tr><td><b>%d-%d</b></td><td>-</td><td>%d/%lu/%lu",
i, (int)worker_generation,
else
ap_rprintf(r,
"<tr><td><b>%d-%d</b></td><td>%"
"</td><td>%d/%lu/%lu",
i, (int)worker_generation,
(int)conn_lres,
case SERVER_READY:
ap_rputs("</td><td>_", r);
break;
case SERVER_STARTING:
ap_rputs("</td><td><b>S</b>", r);
break;
case SERVER_BUSY_READ:
ap_rputs("</td><td><b>R</b>", r);
break;
case SERVER_BUSY_WRITE:
ap_rputs("</td><td><b>W</b>", r);
break;
case SERVER_BUSY_KEEPALIVE:
ap_rputs("</td><td><b>K</b>", r);
break;
case SERVER_BUSY_LOG:
ap_rputs("</td><td><b>L</b>", r);
break;
case SERVER_BUSY_DNS:
ap_rputs("</td><td><b>D</b>", r);
break;
case SERVER_CLOSING:
ap_rputs("</td><td><b>C</b>", r);
break;
case SERVER_DEAD:
ap_rputs("</td><td>.", r);
break;
case SERVER_GRACEFUL:
ap_rputs("</td><td>G", r);
break;
case SERVER_IDLE_KILL:
ap_rputs("</td><td>I", r);
break;
default:
ap_rputs("</td><td>?", r);
break;
}
ap_rprintf(r,
"\n</td>"
#ifdef HAVE_TIMES
"<td>%.2f</td>"
#endif
"<td>%ld</td><td>%ld",
#ifdef HAVE_TIMES
#endif
(long)apr_time_sec(nowtime -
(long)req_time);
ap_rprintf(r, "</td><td>%-1.1f</td><td>%-2.2f</td><td>%-2.2f\n",
ap_rprintf(r,
"</td><td>?</td><td nowrap>?</td><td nowrap>..reading.. </td></tr>\n\n");
else
ap_rprintf(r,
"</td><td>%s</td><td nowrap>%s</td><td nowrap>%s</td></tr>\n\n",
ap_escape_html(r->pool,
ap_escape_html(r->pool,
ap_escape_html(r->pool,
} /* no_table_report */
} /* for (j...) */
} /* for (i...) */
if (!no_table_report) {
ap_rputs("</table>\n \
<hr /> \
<table>\n \
<tr><th>Srv</th><td>Child Server number - generation</td></tr>\n \
<tr><th>PID</th><td>OS process ID</td></tr>\n \
<tr><th>Acc</th><td>Number of accesses this connection / this child / this slot</td></tr>\n \
<tr><th>M</th><td>Mode of operation</td></tr>\n"
#ifdef HAVE_TIMES
"<tr><th>CPU</th><td>CPU usage, number of seconds</td></tr>\n"
#endif
"<tr><th>SS</th><td>Seconds since beginning of most recent request</td></tr>\n \
<tr><th>Req</th><td>Milliseconds required to process most recent request</td></tr>\n \
<tr><th>Conn</th><td>Kilobytes transferred this connection</td></tr>\n \
<tr><th>Child</th><td>Megabytes transferred this child</td></tr>\n \
<tr><th>Slot</th><td>Total megabytes transferred this slot</td></tr>\n \
</table>\n", r);
}
} /* if (ap_extended_status && !short_report) */
else {
if (!short_report) {
ap_rputs("<hr />To obtain a full report with current status "
"information you need to use the "
"<code>ExtendedStatus On</code> directive.\n", r);
}
}
{
/* Run extension hooks to insert extra content. */
int flags =
(short_report ? AP_STATUS_SHORT : 0) |
(no_table_report ? AP_STATUS_NOTABLE : 0) |
(ap_extended_status ? AP_STATUS_EXTENDED : 0);
ap_run_status_hook(r, flags);
}
if (!short_report) {
ap_rputs("</body></html>\n", r);
}
return 0;
}
server_rec *s)
{
return OK;
}
#ifdef HAVE_TIMES
{
}
#endif
static void register_hooks(apr_pool_t *p)
{
#ifdef HAVE_TIMES
#endif
}
{
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
status_module_cmds, /* command table */
register_hooks /* register_hooks */
};