mod_status.c revision 74fd6d9aeadb9022086259c5c1ae00bc0dda9c9a
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/* 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.]
*/
#define CORE_PRIVATE
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "util_script.h"
#include <time.h>
#include "scoreboard.h"
#include "http_log.h"
#include <unistd.h>
#endif
#define APR_WANT_STRFUNC
#include "apr_want.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"
/*
*command-related code. This is here to prevent use of ExtendedStatus
* without status_module included.
*/
{
return err;
}
return NULL;
}
static const command_rec status_module_cmds[] =
{
"\"On\" to enable extended status information, \"Off\" to disable"),
{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 = 0;
int busy = 0;
unsigned long count = 0;
unsigned short conn_lres;
unsigned long bcount = 0;
unsigned long kbcount = 0;
long req_time;
#ifdef HAVE_TIMES
#ifdef _SC_CLK_TCK
#else
#endif
#endif
int short_report = 0;
int no_table_report = 0;
return DECLINED;
}
if (!ap_exists_scoreboard_image()) {
"Server status unavailable in inetd mode");
return HTTP_INTERNAL_SERVER_ERROR;
}
if (r->method_number != M_GET)
return DECLINED;
r->content_type = "text/html";
/*
* 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:
+ 1) > 0)
else
break;
case STAT_OPT_NOTABLE:
no_table_report = 1;
break;
case STAT_OPT_AUTO:
r->content_type = "text/plain";
short_report = 1;
break;
}
}
i++;
}
}
if (r->header_only)
return 0;
/* ap_sync_scoreboard_image(); */
for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
for (j = 0; j < HARD_THREAD_LIMIT; ++j) {
int indx = (i * HARD_THREAD_LIMIT) + j;
if (res == SERVER_READY)
ready++;
else if (res != SERVER_DEAD)
busy++;
if (ap_extended_status) {
#ifdef HAVE_TIMES
#endif /* HAVE_TIMES */
}
}
}
}
}
/* 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, "Server Version: ",
ap_rvputs(r, "Server Built: ",
ap_rvputs(r, "Current Time: ",
ap_rvputs(r, "Restart Time: ",
"<br>\n", NULL);
ap_rputs("Server uptime: ", r);
ap_rputs("<br>\n", r);
}
if (ap_extended_status) {
if (short_report) {
ap_rprintf(r, "Total Accesses: %lu\nTotal kBytes: %lu\n",
#ifdef HAVE_TIMES
/* Allow for OS/2 not having CPU stats */
ap_rprintf(r, "CPULoad: %g\n",
#endif
if (up_time > 0)
ap_rprintf(r, "ReqPerSec: %g\n",
if (up_time > 0)
ap_rprintf(r, "BytesPerSec: %g\n",
if (count > 0)
ap_rprintf(r, "BytesPerReq: %g\n",
}
else { /* !short_report */
format_kbyte_out(r, kbcount);
#ifdef HAVE_TIMES
/* Allow for OS/2 not having CPU stats */
ap_rputs("<br>\n", r);
ap_rprintf(r, "CPU Usage: u%g s%g cu%g cs%g",
ap_rprintf(r, " - %.3g%% CPU load",
#endif
ap_rputs("<br>\n", r);
if (up_time > 0)
ap_rprintf(r, "%.3g requests/sec - ",
if (up_time > 0) {
ap_rputs("/second - ", r);
}
if (count > 0) {
ap_rputs("/request", r);
}
ap_rputs("<br>\n", r);
} /* short_report */
} /* ap_extended_status */
if (!short_report)
ap_rprintf(r, "\n%d requests currently being processed, %d idle servers\n"
else
/* send the scoreboard 'table' out */
if (!short_report)
ap_rputs("<PRE>", r);
else
ap_rputs("Scoreboard: ", r);
for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
for (j = 0; j < HARD_THREAD_LIMIT; ++j) {
int indx = (i * HARD_THREAD_LIMIT) + j;
ap_rputs("\n", r);
}
}
if (short_report)
ap_rputs("\n", r);
else {
ap_rputs("</PRE>\n", r);
ap_rputs("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>L</code></B>\" Logging, \n", r);
ap_rputs("\"<B><code>G</code></B>\" Gracefully finishing, \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 = 0;
int k;
ap_rputs("PID Key: <br>\n", r);
ap_rputs("<PRE>\n", r);
for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
for (k = 0; k < HARD_THREAD_LIMIT; ++k) {
int indx = (i * HARD_THREAD_LIMIT) + j;
stat_buffer[indx]);
if (++j >= 3) {
ap_rputs("\n", r);
j = 0;
} else
ap_rputs(",", r);
}
}
}
ap_rputs("\n", r);
ap_rputs("</PRE>\n", r);
}
}
if (ap_extended_status) {
if (!short_report) {
if (no_table_report)
ap_rputs("<p><hr><h2>Server Details</h2>\n\n", r);
else
#ifndef HAVE_TIMES
/* Allow for OS/2 not having CPU stats */
ap_rputs("<p>\n\n<table border=0><tr><th>Srv<th>PID<th>Acc<th>M\n<th>SS<th>Req<th>Conn<th>Child<th>Slot<th>Client<th>VHost<th>Request</tr>\n\n", r);
#else
ap_rputs("<p>\n\n<table border=0><tr><th>Srv<th>PID<th>Acc<th>M<th>CPU\n<th>SS<th>Req<th>Conn<th>Child<th>Slot<th>Client<th>VHost<th>Request</tr>\n\n", r);
#endif
}
for (i = 0; i < HARD_SERVER_LIMIT; ++i) {
for (j = 0; j < HARD_THREAD_LIMIT; ++j) {
}
#if defined(NO_GETTIMEOFDAY)
#ifdef HAVE_TIMES
#endif /* HAVE_TIMES */
req_time = 0L;
#ifdef HAVE_TIMES
else {
}
#endif /* HAVE_TIMES */
#else
if (score_record.start_time == 0L &&
score_record.start_time == 0L)
req_time = 0L;
else
req_time =
#endif
if (req_time < 0L)
req_time = 0L;
if (!short_report) {
if (no_table_report) {
ap_rprintf(r,
"<b>Server %d-%d</b> (-): %d|%lu|%lu [",
else
ap_rprintf(r,
"<b>Server %d-%d</b> (%d): %d|%lu|%lu [",
i, (int) ps_record.generation,
switch (score_record.status) {
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_DEAD:
ap_rputs("Dead", r);
break;
case SERVER_GRACEFUL:
ap_rputs("Graceful", r);
break;
default:
ap_rputs("?STATE?", r);
break;
}
#ifndef HAVE_TIMES
/* Allow for OS/2 not having CPU stats */
ap_rprintf(r, "]\n %.0f %ld (",
#else
ap_rprintf(r, "] u%g s%g cu%g cs%g\n %.0f %ld (",
#endif
#ifdef OPTIMIZE_TIMEOUTS
#else
#endif
(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",
}
else { /* !no_table_report */
ap_rprintf(r,
"<tr><td><b>%d-%d</b><td>-<td>%d/%lu/%lu",
i, (int) ps_record.generation,
else
ap_rprintf(r,
"<tr><td><b>%d-%d</b><td>%d<td>%d/%lu/%lu",
i, (int) ps_record.generation,
switch (score_record.status) {
case SERVER_READY:
ap_rputs("<td>_", r);
break;
case SERVER_STARTING:
ap_rputs("<td><b>S</b>", r);
break;
case SERVER_BUSY_READ:
ap_rputs("<td><b>R</b>", r);
break;
case SERVER_BUSY_WRITE:
ap_rputs("<td><b>W</b>", r);
break;
case SERVER_BUSY_KEEPALIVE:
ap_rputs("<td><b>K</b>", r);
break;
case SERVER_BUSY_LOG:
ap_rputs("<td><b>L</b>", r);
break;
case SERVER_BUSY_DNS:
ap_rputs("<td><b>D</b>", r);
break;
case SERVER_DEAD:
ap_rputs("<td>.", r);
break;
case SERVER_GRACEFUL:
ap_rputs("<td>G", r);
break;
default:
ap_rputs("<td>?", r);
break;
}
#ifndef HAVE_TIMES
/* Allow for OS/2 not having CPU stats */
ap_rprintf(r, "\n<td>%.0f<td>%ld",
#else
ap_rprintf(r, "\n<td>%.2f<td>%.0f<td>%ld",
#endif
#ifdef OPTIMIZE_TIMEOUTS
#else
#endif
(long) req_time);
ap_rprintf(r, "<td>%-1.1f<td>%-2.2f<td>%-2.2f\n",
ap_rprintf(r,
"<td>?<td nowrap>?<td nowrap>..reading.. </tr>\n\n");
else
ap_rprintf(r,
"<td>%s<td nowrap>%s<td nowrap>%s</tr>\n\n",
} /* no_table_report */
} /* !short_report */
} /* if (<active child>) */
} /* for () */
}
if (!(short_report || no_table_report)) {
#ifndef HAVE_TIMES
ap_rputs("</table>\n \
<hr> \
<table>\n \
<tr><th>Srv<td>Child Server number - generation\n \
<tr><th>PID<td>OS process ID\n \
<tr><th>Acc<td>Number of accesses this connection / this child / this slot\n \
<tr><th>M<td>Mode of operation\n \
<tr><th>SS<td>Seconds since beginning of most recent request\n \
<tr><th>Req<td>Milliseconds required to process most recent request\n \
<tr><th>Conn<td>Kilobytes transferred this connection\n \
<tr><th>Child<td>Megabytes transferred this child\n \
<tr><th>Slot<td>Total megabytes transferred this slot\n \
</table>\n", r);
#else
ap_rputs("</table>\n \
<hr> \
<table>\n \
<tr><th>Srv<td>Child Server number - generation\n \
<tr><th>PID<td>OS process ID\n \
<tr><th>Acc<td>Number of accesses this connection / this child / this slot\n \
<tr><th>M<td>Mode of operation\n \
<tr><th>CPU<td>CPU usage, number of seconds\n \
<tr><th>SS<td>Seconds since beginning of most recent request\n \
<tr><th>Req<td>Milliseconds required to process most recent request\n \
<tr><th>Conn<td>Kilobytes transferred this connection\n \
<tr><th>Child<td>Megabytes transferred this child\n \
<tr><th>Slot<td>Total megabytes transferred this slot\n \
</table>\n", r);
#endif
}
} else {
if (!short_report) {
ap_rputs("<hr>To obtain a full report with current status information ", r);
ap_rputs("you need to use the <code>ExtendedStatus On</code> directive. \n", r);
}
}
if (!short_report) {
ap_rputs("</BODY></HTML>\n", r);
}
return 0;
}
{
}
static void register_hooks(apr_pool_t *p)
{
}
{
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 */
};