mod_status.c revision a72ba68ecbbc61e4b513e50d6000245c33f753dc
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* Licensed to the Apache Software Foundation (ASF) under one or more
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * contributor license agreements. See the NOTICE file distributed with
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * this work for additional information regarding copyright ownership.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * The ASF licenses this file to You under the Apache License, Version 2.0
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * (the "License"); you may not use this file except in compliance with
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * the License. You may obtain a copy of the License at
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * http://www.apache.org/licenses/LICENSE-2.0
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * Unless required by applicable law or agreed to in writing, software
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * distributed under the License is distributed on an "AS IS" BASIS,
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * See the License for the specific language governing permissions and
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * limitations under the License.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz/* Status Module. Display lots of internal data about how Apache is
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * performing and the state of all children processes.
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * To enable this, add the following lines into any config file:
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz *
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * <Location /server-status>
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * SetHandler server-status
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * </Location>
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * You may want to protect this location by password or domain so no one
7af4df794a0e0f0cb927bd9371556ad098308983Ewaryst Schulz * else can look at it. Then you can access the statistics with a URL like:
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * http://your_server_name/server-status
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * /server-status - Returns page using tables
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * /server-status?notable - Returns page for browsers without table support
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * /server-status?refresh - Returns page with 1 second refresh
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * /server-status?refresh=6 - Returns page with refresh every 6 seconds
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * /server-status?auto - Returns page with data for automatic parsing
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * Mark Cox, mark@ukweb.com, November 1995
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz *
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 12.11.95 Initial version for www.telescope.org
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 13.3.96 Updated to remove rprintf's [Mark]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 18.3.96 Added CPU usage, process information, and tidied [Ben Laurie]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 18.3.96 Make extra Scoreboard variables #definable
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * 25.3.96 Make short report have full precision [Ben Laurie suggested]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 25.3.96 Show uptime better [Mark/Ben Laurie]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 29.3.96 Better HTML and explanation [Mark/Rob Hartill suggested]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 09.4.96 Added message for non-STATUS compiled version
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 18.4.96 Added per child and per slot counters [Jim Jagielski]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 01.5.96 Table format, cleanup, even more spiffy data [Chuck Murcko/Jim J.]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 18.5.96 Adapted to use new rprintf() routine, incidentally fixing a missing
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * piece in short reports [Ben Laurie]
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * 21.5.96 Additional Status codes (DNS and LOGGING only enabled if
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz * extended STATUS is enabled) [George Burgyan/Jim J.]
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * 10.8.98 Allow for extended status info at runtime (no more STATUS)
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz * [Jim J.]
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define CORE_PRIVATE
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "httpd.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_config.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_core.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_protocol.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_main.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "ap_mpm.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "util_script.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include <time.h>
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "scoreboard.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include "http_log.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include "mod_status.h"
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#if APR_HAVE_UNISTD_H
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#include <unistd.h>
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#endif
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#define APR_WANT_STRFUNC
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz#include "apr_want.h"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz#ifdef NEXT
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz#if (NX_CURRENT_COMPILER_RELEASE == 410)
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#ifdef m68k
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define HZ 64
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#else
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define HZ 100
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#endif
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#else
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#include <machine/param.h>
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif /* NEXT */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define STATUS_MAXLINE 64
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define KBYTE 1024
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define MBYTE 1048576L
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define GBYTE 1073741824L
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#ifndef DEFAULT_TIME_FORMAT
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#define STATUS_MAGIC_TYPE "application/x-httpd-status"
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulzmodule AP_MODULE_DECLARE_DATA status_module;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulzstatic int server_limit, thread_limit;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* Implement 'ap_run_status_hook'. */
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst SchulzAPR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap, STATUS, int, status_hook,
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz (request_rec *r, int flags),
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz (r, flags),
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz OK, DECLINED)
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#ifdef HAVE_TIMES
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz/* ugh... need to know if we're running with a pthread implementation
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz * such as linuxthreads that treats individual threads as distinct
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * processes; that affects how we add up CPU time in a process
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz */
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulzstatic pid_t child_pid;
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz#endif
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz/*
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz * command-related code. This is here to prevent use of ExtendedStatus
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz * without status_module included.
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz */
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulzstatic const char *set_extended_status(cmd_parms *cmd, void *dummy, int arg)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz{
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz if (err != NULL) {
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz return err;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz }
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_extended_status = arg;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz return NULL;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz}
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstatic const command_rec status_module_cmds[] =
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz{
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz AP_INIT_FLAG("ExtendedStatus", set_extended_status, NULL, RSRC_CONF,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz "\"On\" to enable extended status information, \"Off\" to disable"),
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz {NULL}
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz};
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz/* Format the number of bytes nicely */
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstatic void format_byte_out(request_rec *r, apr_off_t bytes)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz{
9316034585ad46e11b1307ec8289f25b7699d74dEwaryst Schulz if (bytes < (5 * KBYTE))
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, "%d B", (int) bytes);
9316034585ad46e11b1307ec8289f25b7699d74dEwaryst Schulz else if (bytes < (MBYTE / 2))
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, "%.1f kB", (float) bytes / KBYTE);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz else if (bytes < (GBYTE / 2))
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, "%.1f MB", (float) bytes / MBYTE);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz else
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, "%.1f GB", (float) bytes / GBYTE);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz}
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstatic void format_kbyte_out(request_rec *r, apr_off_t kbytes)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz{
21c27810fa966e9253073efaf7f36458715d84bbEwaryst Schulz if (kbytes < KBYTE)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, "%d kB", (int) kbytes);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz else if (kbytes < MBYTE)
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz ap_rprintf(r, "%.1f MB", (float) kbytes / KBYTE);
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz else
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, "%.1f GB", (float) kbytes / MBYTE);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz}
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstatic void show_time(request_rec *r, apr_interval_time_t tsecs)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz{
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz int days, hrs, mins, secs;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz secs = (int)(tsecs % 60);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz tsecs /= 60;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz mins = (int)(tsecs % 60);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz tsecs /= 60;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz hrs = (int)(tsecs % 24);
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz days = (int)(tsecs / 24);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz if (days)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, " %d day%s", days, days == 1 ? "" : "s");
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz if (hrs)
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_rprintf(r, " %d hour%s", hrs, hrs == 1 ? "" : "s");
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz if (mins)
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz ap_rprintf(r, " %d minute%s", mins, mins == 1 ? "" : "s");
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz if (secs)
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz ap_rprintf(r, " %d second%s", secs, secs == 1 ? "" : "s");
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz}
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* Main handler for x-httpd-status requests */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz/* ID values for command table */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define STAT_OPT_END -1
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define STAT_OPT_REFRESH 0
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#define STAT_OPT_NOTABLE 1
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz#define STAT_OPT_AUTO 2
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulzstruct stat_opt {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz int id;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz const char *form_data_str;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz const char *hdr_out_str;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz};
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulzstatic const struct stat_opt status_options[] = /* see #defines above */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz{
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz {STAT_OPT_REFRESH, "refresh", "Refresh"},
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz {STAT_OPT_NOTABLE, "notable", NULL},
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz {STAT_OPT_AUTO, "auto", NULL},
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz {STAT_OPT_END, NULL, NULL}
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz};
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulzstatic char status_flags[SERVER_NUM_STATUS];
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulzstatic int status_handler(request_rec *r)
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz{
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz const char *loc;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_time_t nowtime;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_interval_time_t up_time;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int j, i, res;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int ready;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int busy;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned long count;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz unsigned long lres, my_lres, conn_lres;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_off_t bytes, my_bytes, conn_bytes;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz apr_off_t bcount, kbcount;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz long req_time;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#ifdef HAVE_TIMES
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz float tick;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int times_per_thread = getpid() != child_pid;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#endif
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int short_report;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz int no_table_report;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz worker_score *ws_record;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz process_score *ps_record;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz char *stat_buffer;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz pid_t *pid_buffer, worker_pid;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz clock_t tu, ts, tcu, tcs;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz ap_generation_t worker_generation;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz if (strcmp(r->handler, STATUS_MAGIC_TYPE) &&
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz strcmp(r->handler, "server-status")) {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz return DECLINED;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz }
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#ifdef HAVE_TIMES
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#ifdef _SC_CLK_TCK
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz tick = sysconf(_SC_CLK_TCK);
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#else
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz tick = HZ;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#endif
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#endif
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz ready = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz busy = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz count = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz bcount = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz kbcount = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz short_report = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz no_table_report = 0;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz pid_buffer = apr_palloc(r->pool, server_limit * sizeof(pid_t));
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz stat_buffer = apr_palloc(r->pool, server_limit * thread_limit * sizeof(char));
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz nowtime = apr_time_now();
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz tu = ts = tcu = tcs = 0;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz if (!ap_exists_scoreboard_image()) {
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz "Server status unavailable in inetd mode");
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz return HTTP_INTERNAL_SERVER_ERROR;
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz }
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz r->allowed = (AP_METHOD_BIT << M_GET);
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz if (r->method_number != M_GET)
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz return DECLINED;
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz ap_set_content_type(r, "text/html; charset=ISO-8859-1");
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz /*
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz * Simple table-driven form data set parser that lets you alter the header
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz */
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz if (r->args) {
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz i = 0;
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz while (status_options[i].id != STAT_OPT_END) {
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz if ((loc = ap_strstr_c(r->args,
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz status_options[i].form_data_str)) != NULL) {
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz switch (status_options[i].id) {
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz case STAT_OPT_REFRESH:
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz if (*(loc + strlen(status_options[i].form_data_str)) == '='
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz && atol(loc + strlen(status_options[i].form_data_str)
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz + 1) > 0)
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz apr_table_set(r->headers_out,
e9f0cd6ee7be0336cfd071df0451d6282cf55d75Ewaryst Schulz status_options[i].hdr_out_str,
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz loc +
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz strlen(status_options[i].hdr_out_str) +
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz 1);
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz else
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz apr_table_set(r->headers_out,
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz status_options[i].hdr_out_str, "1");
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz break;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz case STAT_OPT_NOTABLE:
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz no_table_report = 1;
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz break;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz case STAT_OPT_AUTO:
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz ap_set_content_type(r, "text/plain; charset=ISO-8859-1");
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz short_report = 1;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz break;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz }
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz }
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz i++;
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz }
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz }
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz for (i = 0; i < server_limit; ++i) {
213ff2bc64713dccda8de3db300ba188bd585866Ewaryst Schulz#ifdef HAVE_TIMES
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz clock_t proc_tu = 0, proc_ts = 0, proc_tcu = 0, proc_tcs = 0;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz clock_t tmp_tu, tmp_ts, tmp_tcu, tmp_tcs;
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz#endif
7594b91154e299c9bcecd2bd62698705b55f99e8Ewaryst Schulz
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz ps_record = ap_get_scoreboard_process(i);
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz for (j = 0; j < thread_limit; ++j) {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz int indx = (i * thread_limit) + j;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz res = ws_record->status;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz stat_buffer[indx] = status_flags[res];
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz if (!ps_record->quiescing
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz && ps_record->pid) {
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz if (res == SERVER_READY
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz && ps_record->generation == ap_my_generation)
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz ready++;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz else if (res != SERVER_DEAD &&
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz res != SERVER_STARTING &&
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz res != SERVER_IDLE_KILL)
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz busy++;
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz }
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz /* XXX what about the counters for quiescing/seg faulted
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz * processes? should they be counted or not? GLA
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz */
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz if (ap_extended_status) {
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz lres = ws_record->access_count;
f31eef72d6536eeb5a51e86d1f367cbb1a1b8e06Ewaryst Schulz bytes = ws_record->bytes_served;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz if (lres != 0 || (res != SERVER_READY && res != SERVER_DEAD)) {
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz#ifdef HAVE_TIMES
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz tmp_tu = ws_record->times.tms_utime;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz tmp_ts = ws_record->times.tms_stime;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz tmp_tcu = ws_record->times.tms_cutime;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz tmp_tcs = ws_record->times.tms_cstime;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz if (times_per_thread) {
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz proc_tu += tmp_tu;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proc_ts += tmp_ts;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz proc_tcu += tmp_tcu;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz proc_tcs += proc_tcs;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz }
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz else {
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz if (tmp_tu > proc_tu ||
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz tmp_ts > proc_ts ||
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz tmp_tcu > proc_tcu ||
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz tmp_tcs > proc_tcs) {
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz proc_tu = tmp_tu;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz proc_ts = tmp_ts;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz proc_tcu = tmp_tcu;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz proc_tcs = proc_tcs;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz }
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz }
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#endif /* HAVE_TIMES */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz count += lres;
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz bcount += bytes;
6091bd7fb65c7def81e5a5d0359ceeed7a88bb7fEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz if (bcount >= KBYTE) {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz kbcount += (bcount >> 10);
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz bcount = bcount & 0x3ff;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz }
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz }
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz }
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz }
a3b8d685ae08bf3f83a6c2930e872183c487c844Ewaryst Schulz#ifdef HAVE_TIMES
f474203c4cef7d85cb078f15ce5c2cea71e9a030Ewaryst Schulz tu += proc_tu;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz ts += proc_ts;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz tcu += proc_tcu;
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz tcs += proc_tcs;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz#endif
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz pid_buffer[i] = ps_record->pid;
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz }
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz /* up_time in seconds */
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz up_time = (apr_uint32_t) apr_time_sec(nowtime -
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_scoreboard_image->global->restart_time);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz if (!short_report) {
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rputs(DOCTYPE_HTML_3_2
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz "<html><head>\n<title>Apache Status</title>\n</head><body>\n",
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz r);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rputs("<h1>Apache Server Status for ", r);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rvputs(r, ap_get_server_name(r), "</h1>\n\n", NULL);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rvputs(r, "<dl><dt>Server Version: ",
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_get_server_description(), "</dt>\n", NULL);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rvputs(r, "<dt>Server Built: ",
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_get_server_built(), "\n</dt></dl><hr /><dl>\n", NULL);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rvputs(r, "<dt>Current Time: ",
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_ht_time(r->pool, nowtime, DEFAULT_TIME_FORMAT, 0),
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz "</dt>\n", NULL);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rvputs(r, "<dt>Restart Time: ",
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_ht_time(r->pool,
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_scoreboard_image->global->restart_time,
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz DEFAULT_TIME_FORMAT, 0),
f54cad0338da90c6789bb9baae1caec50d994b3aEwaryst Schulz "</dt>\n", NULL);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rprintf(r, "<dt>Parent Server Generation: %d</dt>\n",
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz (int)ap_my_generation);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz ap_rputs("<dt>Server uptime: ", r);
67f09e0fddea50c48620c011b6d001cffe565de6Ewaryst Schulz show_time(r, up_time);
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz ap_rputs("</dt>\n", r);
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz }
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz if (ap_extended_status) {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz if (short_report) {
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz ap_rprintf(r, "Total Accesses: %lu\nTotal kBytes: %"
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz APR_OFF_T_FMT "\n",
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz count, kbcount);
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz#ifdef HAVE_TIMES
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz /* Allow for OS/2 not having CPU stats */
6c3ce177a0ad551edaae7daa17772b12f77a86daEwaryst Schulz if (ts || tu || tcu || tcs)
ap_rprintf(r, "CPULoad: %g\n",
(tu + ts + tcu + tcs) / tick / up_time * 100.);
#endif
ap_rprintf(r, "Uptime: %ld\n", (long) (up_time));
if (up_time > 0) {
ap_rprintf(r, "ReqPerSec: %g\n",
(float) count / (float) up_time);
ap_rprintf(r, "BytesPerSec: %g\n",
KBYTE * (float) kbcount / (float) up_time);
}
if (count > 0)
ap_rprintf(r, "BytesPerReq: %g\n",
KBYTE * (float) kbcount / (float) count);
}
else { /* !short_report */
ap_rprintf(r, "<dt>Total accesses: %lu - Total Traffic: ", count);
format_kbyte_out(r, kbcount);
ap_rputs("</dt>\n", r);
#ifdef HAVE_TIMES
/* Allow for OS/2 not having CPU stats */
ap_rprintf(r, "<dt>CPU Usage: u%g s%g cu%g cs%g",
tu / tick, ts / tick, tcu / tick, tcs / tick);
if (ts || tu || tcu || tcs)
ap_rprintf(r, " - %.3g%% CPU load</dt>\n",
(tu + ts + tcu + tcs) / tick / up_time * 100.);
#endif
if (up_time > 0) {
ap_rprintf(r, "<dt>%.3g requests/sec - ",
(float) count / (float) up_time);
format_byte_out(r, (unsigned long)(KBYTE * (float) kbcount
/ (float) up_time));
ap_rputs("/second - ", r);
}
if (count > 0) {
format_byte_out(r, (unsigned long)(KBYTE * (float) kbcount
/ (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, "
"%d idle workers</dt>\n", busy, ready);
else
ap_rprintf(r, "BusyWorkers: %d\nIdleWorkers: %d\n", busy, ready);
/* 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;
ap_rputc(stat_buffer[indx], r);
if ((indx % STATUS_MAXLINE == (STATUS_MAXLINE - 1))
&& !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;
if (stat_buffer[indx] != '.') {
ap_rprintf(r, " %" APR_PID_T_FMT
" 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) {
ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
if (ws_record->access_count == 0 &&
(ws_record->status == SERVER_READY ||
ws_record->status == SERVER_DEAD)) {
continue;
}
ps_record = ap_get_scoreboard_process(i);
if (ws_record->start_time == 0L)
req_time = 0L;
else
req_time = (long)
((ws_record->stop_time -
ws_record->start_time) / 1000);
if (req_time < 0L)
req_time = 0L;
lres = ws_record->access_count;
my_lres = ws_record->my_access_count;
conn_lres = ws_record->conn_count;
bytes = ws_record->bytes_served;
my_bytes = ws_record->my_bytes_served;
conn_bytes = ws_record->conn_bytes;
if (ws_record->pid) { /* MPM sets per-worker pid and generation */
worker_pid = ws_record->pid;
worker_generation = ws_record->generation;
}
else {
worker_pid = ps_record->pid;
worker_generation = ps_record->generation;
}
if (no_table_report) {
if (ws_record->status == SERVER_DEAD)
ap_rprintf(r,
"<b>Server %d-%d</b> (-): %d|%lu|%lu [",
i, (int)worker_generation,
(int)conn_lres, my_lres, lres);
else
ap_rprintf(r,
"<b>Server %d-%d</b> (%"
APR_PID_T_FMT "): %d|%lu|%lu [",
i, (int) worker_generation,
worker_pid,
(int)conn_lres, my_lres, lres);
switch (ws_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_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
ws_record->times.tms_utime / tick,
ws_record->times.tms_stime / tick,
ws_record->times.tms_cutime / tick,
ws_record->times.tms_cstime / tick,
#endif
(long)apr_time_sec(nowtime -
ws_record->last_used),
(long) req_time);
format_byte_out(r, conn_bytes);
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,
ws_record->client),
ap_escape_html(r->pool,
ap_escape_logitem(r->pool,
ws_record->request)),
ap_escape_html(r->pool,
ws_record->vhost));
}
else { /* !no_table_report */
if (ws_record->status == SERVER_DEAD)
ap_rprintf(r,
"<tr><td><b>%d-%d</b></td><td>-</td><td>%d/%lu/%lu",
i, (int)worker_generation,
(int)conn_lres, my_lres, lres);
else
ap_rprintf(r,
"<tr><td><b>%d-%d</b></td><td>%"
APR_PID_T_FMT
"</td><td>%d/%lu/%lu",
i, (int)worker_generation,
worker_pid,
(int)conn_lres,
my_lres, lres);
switch (ws_record->status) {
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
(ws_record->times.tms_utime +
ws_record->times.tms_stime +
ws_record->times.tms_cutime +
ws_record->times.tms_cstime) / tick,
#endif
(long)apr_time_sec(nowtime -
ws_record->last_used),
(long)req_time);
ap_rprintf(r, "</td><td>%-1.1f</td><td>%-2.2f</td><td>%-2.2f\n",
(float)conn_bytes / KBYTE, (float) my_bytes / MBYTE,
(float)bytes / MBYTE);
if (ws_record->status == SERVER_BUSY_READ)
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,
ws_record->client),
ap_escape_html(r->pool,
ws_record->vhost),
ap_escape_html(r->pool,
ap_escape_logitem(r->pool,
ws_record->request)));
} /* 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(ap_psignature("<hr />\n",r), r);
ap_rputs("</body></html>\n", r);
}
return 0;
}
static int status_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
server_rec *s)
{
status_flags[SERVER_DEAD] = '.'; /* We don't want to assume these are in */
status_flags[SERVER_READY] = '_'; /* any particular order in scoreboard.h */
status_flags[SERVER_STARTING] = 'S';
status_flags[SERVER_BUSY_READ] = 'R';
status_flags[SERVER_BUSY_WRITE] = 'W';
status_flags[SERVER_BUSY_KEEPALIVE] = 'K';
status_flags[SERVER_BUSY_LOG] = 'L';
status_flags[SERVER_BUSY_DNS] = 'D';
status_flags[SERVER_CLOSING] = 'C';
status_flags[SERVER_GRACEFUL] = 'G';
status_flags[SERVER_IDLE_KILL] = 'I';
ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
return OK;
}
#ifdef HAVE_TIMES
static void status_child_init(apr_pool_t *p, server_rec *s)
{
child_pid = getpid();
}
#endif
static void register_hooks(apr_pool_t *p)
{
ap_hook_handler(status_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(status_init, NULL, NULL, APR_HOOK_MIDDLE);
#ifdef HAVE_TIMES
ap_hook_child_init(status_child_init, NULL, NULL, APR_HOOK_MIDDLE);
#endif
}
module AP_MODULE_DECLARE_DATA status_module =
{
STANDARD20_MODULE_STUFF,
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 */
};