mod_status.c revision 98fb535f829e2a95aabd82420931f476661fa8e3
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova/* ====================================================================
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner * The Apache Software License, Version 1.1
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Redistribution and use in source and binary forms, with or without
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * modification, are permitted provided that the following conditions
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * 1. Redistributions of source code must retain the above copyright
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * notice, this list of conditions and the following disclaimer.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 2. Redistributions in binary form must reproduce the above copyright
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * notice, this list of conditions and the following disclaimer in
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * the documentation and/or other materials provided with the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * distribution.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 3. The end-user documentation included with the redistribution,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * if any, must include the following acknowledgment:
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * "This product includes software developed by the
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * Apache Software Foundation (http://www.apache.org/)."
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * Alternately, this acknowledgment may appear in the software itself,
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * if and wherever such third-party acknowledgments normally appear.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * 4. The names "Apache" and "Apache Software Foundation" must
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * not be used to endorse or promote products derived from this
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * software without prior written permission. For written
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * permission, please contact apache@apache.org.
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * 5. Products derived from this software may not be called "Apache",
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * nor may "Apache" appear in their name, without prior written
118add2c5ac398465f6f66adb165852dffe1264dKristina Sojakova * permission of the Apache Software Foundation.
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
118add2c5ac398465f6f66adb165852dffe1264dKristina Sojakova * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * SUCH DAMAGE.
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * ====================================================================
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * This software consists of voluntary contributions made by many
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * individuals on behalf of the Apache Software Foundation. For more
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakova * information on the Apache Software Foundation, please see
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * Portions of this software are based upon public domain software
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * originally written at the National Center for Supercomputing Applications,
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova * University of Illinois, Urbana-Champaign.
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova/* Status Module. Display lots of internal data about how Apache is
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * performing and the state of all children processes.
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * To enable this, add the following lines into any config file:
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * <Location /server-status>
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * SetHandler server-status
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * You may want to protect this location by password or domain so no one
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * else can look at it. Then you can access the statistics with a URL like:
e8dd447a2aa5fbac10668749dfe4142c05ec3d7dKristina Sojakova * /server-status - Returns page using tables
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * /server-status?notable - Returns page for browsers without table support
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * /server-status?refresh - Returns page with 1 second refresh
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * /server-status?refresh=6 - Returns page with refresh every 6 seconds
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * /server-status?auto - Returns page with data for automatic parsing
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * Mark Cox, mark@ukweb.com, November 1995
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 12.11.95 Initial version for www.telescope.org
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 13.3.96 Updated to remove rprintf's [Mark]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * 18.3.96 Added CPU usage, process information, and tidied [Ben Laurie]
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 18.3.96 Make extra Scoreboard variables #definable
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 25.3.96 Make short report have full precision [Ben Laurie suggested]
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 25.3.96 Show uptime better [Mark/Ben Laurie]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * 29.3.96 Better HTML and explanation [Mark/Rob Hartill suggested]
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 09.4.96 Added message for non-STATUS compiled version
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 18.4.96 Added per child and per slot counters [Jim Jagielski]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * 01.5.96 Table format, cleanup, even more spiffy data [Chuck Murcko/Jim J.]
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 18.5.96 Adapted to use new rprintf() routine, incidentally fixing a missing
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * piece in short reports [Ben Laurie]
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 21.5.96 Additional Status codes (DNS and LOGGING only enabled if
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * extended STATUS is enabled) [George Burgyan/Jim J.]
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova * 10.8.98 Allow for extended status info at runtime (no more STATUS)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder#if (NX_CURRENT_COMPILER_RELEASE == 410)
5e35940c3516ccea02caa0450d2b075de0106fa5Kristina Sojakova#endif /* NEXT */
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova#define STATUS_MAGIC_TYPE "application/x-httpd-status"
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroedermodule AP_MODULE_DECLARE_DATA status_module;
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova/* Implement 'ap_run_status_hook'. */
3c0bf20712a0f21aaedc0a9a9c8376bc1e90e799Kristina SojakovaAP_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(int,status_hook,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * command-related code. This is here to prevent use of ExtendedStatus
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova * without status_module included.
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakovastatic const char *set_extended_status(cmd_parms *cmd, void *dummy, int arg)
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
ccaa75089b23c0f043cdbd4001cba4e076ca4fd3Kristina Sojakovastatic const command_rec status_module_cmds[] =
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova AP_INIT_FLAG("ExtendedStatus", set_extended_status, NULL, RSRC_CONF,
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova "\"On\" to enable extended status information, \"Off\" to disable"),
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova/* Format the number of bytes nicely */
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakovastatic void format_byte_out(request_rec *r, apr_off_t bytes)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ap_rprintf(r, "%.1f kB", (float) bytes / KBYTE);
168d206b4e5fd436c98239a1b6629c651f54c8eeKristina Sojakova ap_rprintf(r, "%.1f MB", (float) bytes / MBYTE);
168d206b4e5fd436c98239a1b6629c651f54c8eeKristina Sojakova ap_rprintf(r, "%.1f GB", (float) bytes / GBYTE);
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederstatic void format_kbyte_out(request_rec *r, apr_off_t kbytes)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder ap_rprintf(r, "%d kB", (int) kbytes);
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova ap_rprintf(r, "%.1f MB", (float) kbytes / KBYTE);
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova ap_rprintf(r, "%.1f GB", (float) kbytes / MBYTE);
168d206b4e5fd436c98239a1b6629c651f54c8eeKristina Sojakovastatic void show_time(request_rec *r, apr_interval_time_t tsecs)
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova ap_rprintf(r, " %d day%s", days, days == 1 ? "" : "s");
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova ap_rprintf(r, " %d hour%s", hrs, hrs == 1 ? "" : "s");
d71bb9deea089887b4fd829c5b766e7e4de9f204Kristina Sojakova ap_rprintf(r, " %d minute%s", mins, mins == 1 ? "" : "s");
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova ap_rprintf(r, " %d second%s", secs, secs == 1 ? "" : "s");
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova/* Main handler for x-httpd-status requests */
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakova/* ID values for command table */
abd5fc85dc7e19b1614890182436940e922963a4Kristina Sojakovastatic const struct stat_opt status_options[] = /* see #defines above */
const char *loc;
int j, i, res;
int ready;
int busy;
unsigned long count;
long req_time;
#ifdef HAVE_TIMES
float tick;
int short_report;
int no_table_report;
char *stat_buffer;
return DECLINED;
#ifdef HAVE_TIMES
#ifdef _SC_CLK_TCK
ready = 0;
busy = 0;
count = 0;
bcount = 0;
kbcount = 0;
short_report = 0;
no_table_report = 0;
if (!ap_exists_scoreboard_image()) {
return HTTP_INTERNAL_SERVER_ERROR;
return DECLINED;
if (r->args) {
case STAT_OPT_REFRESH:
loc +
case STAT_OPT_NOTABLE:
case STAT_OPT_AUTO:
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
ready++;
busy++;
if (ap_extended_status) {
#ifdef HAVE_TIMES
if (!short_report) {
DEFAULT_TIME_FORMAT, 0),
(int)ap_my_generation);
if (ap_extended_status) {
if (short_report) {
#ifdef HAVE_TIMES
if (up_time > 0)
if (up_time > 0)
if (count > 0)
#ifdef HAVE_TIMES
if (up_time > 0)
if (up_time > 0) {
/ (float) up_time));
if (count > 0) {
/ (float) count));
if (!short_report)
if (!short_report)
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
&& !short_report)
if (short_report)
if (!ap_extended_status) {
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
if (no_table_report)
#ifdef HAVE_TIMES
for (i = 0; i < server_limit; ++i) {
for (j = 0; j < thread_limit; ++j) {
req_time = 0L;
req_time = (long)
if (req_time < 0L)
req_time = 0L;
if (no_table_report) {
ap_rprintf(r,
ap_rprintf(r,
case SERVER_READY:
case SERVER_STARTING:
case SERVER_BUSY_READ:
case SERVER_BUSY_WRITE:
case SERVER_BUSY_KEEPALIVE:
case SERVER_BUSY_LOG:
case SERVER_BUSY_DNS:
case SERVER_CLOSING:
case SERVER_DEAD:
case SERVER_GRACEFUL:
case SERVER_IDLE_KILL:
#ifdef HAVE_TIMES
#ifdef HAVE_TIMES
(long) req_time);
ap_rprintf(r,
ap_rprintf(r,
ap_rprintf(r,
case SERVER_READY:
case SERVER_STARTING:
case SERVER_BUSY_READ:
case SERVER_BUSY_WRITE:
case SERVER_BUSY_KEEPALIVE:
case SERVER_BUSY_LOG:
case SERVER_BUSY_DNS:
case SERVER_CLOSING:
case SERVER_DEAD:
case SERVER_GRACEFUL:
case SERVER_IDLE_KILL:
ap_rprintf(r,
#ifdef HAVE_TIMES
#ifdef HAVE_TIMES
(long)req_time);
ap_rprintf(r,
ap_rprintf(r,
if (!no_table_report) {
#ifdef HAVE_TIMES
if (!short_report) {
int flags =
if (!short_report) {
server_rec *s)
return OK;