⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_status.c

📁 Apache官方在今天放出产品系列2.2的最新版本2.2.11的源码包 最流行的HTTP服务器软件之一
💻 C
📖 第 1 页 / 共 3 页
字号:
/* 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 * *     http://www.apache.org/licenses/LICENSE-2.0 * * 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: * * http://your_server_name/server-status * * /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] * 25.3.96  Show uptime better [Mark/Ben Laurie] * 29.3.96  Better HTML and explanation [Mark/Rob Hartill suggested] * 09.4.96  Added message for non-STATUS compiled version * 18.4.96  Added per child and per slot counters [Jim Jagielski] * 01.5.96  Table format, cleanup, even more spiffy data [Chuck Murcko/Jim J.] * 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 *          extended STATUS is enabled) [George Burgyan/Jim J.] * 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 "ap_mpm.h"#include "util_script.h"#include <time.h>#include "scoreboard.h"#include "http_log.h"#include "mod_status.h"#if APR_HAVE_UNISTD_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#include <machine/param.h>#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"module AP_MODULE_DECLARE_DATA status_module;static int server_limit, thread_limit;/* Implement 'ap_run_status_hook'. */APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap, STATUS, int, status_hook,                                    (request_rec *r, int flags),                                    (r, flags),                                    OK, DECLINED)#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 */static pid_t child_pid;#endif/* * command-related code. This is here to prevent use of ExtendedStatus * without status_module included. */static const char *set_extended_status(cmd_parms *cmd, void *dummy, int arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_extended_status = arg;    return NULL;}static const char *set_reqtail(cmd_parms *cmd, void *dummy, int arg){    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);    if (err != NULL) {        return err;    }    ap_mod_status_reqtail = arg;    return NULL;}static const command_rec status_module_cmds[] ={    AP_INIT_FLAG("ExtendedStatus", set_extended_status, NULL, RSRC_CONF,      "\"On\" to enable extended status information, \"Off\" to disable"),    AP_INIT_FLAG("SeeRequestTail", set_reqtail, NULL, RSRC_CONF,      "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 */static void format_byte_out(request_rec *r, apr_off_t bytes){    if (bytes < (5 * KBYTE))        ap_rprintf(r, "%d B", (int) bytes);    else if (bytes < (MBYTE / 2))        ap_rprintf(r, "%.1f kB", (float) bytes / KBYTE);    else if (bytes < (GBYTE / 2))        ap_rprintf(r, "%.1f MB", (float) bytes / MBYTE);    else        ap_rprintf(r, "%.1f GB", (float) bytes / GBYTE);}static void format_kbyte_out(request_rec *r, apr_off_t kbytes){    if (kbytes < KBYTE)        ap_rprintf(r, "%d kB", (int) kbytes);    else if (kbytes < MBYTE)        ap_rprintf(r, "%.1f MB", (float) kbytes / KBYTE);    else        ap_rprintf(r, "%.1f GB", (float) kbytes / MBYTE);}static void show_time(request_rec *r, apr_interval_time_t tsecs){    int days, hrs, mins, secs;    secs = (int)(tsecs % 60);    tsecs /= 60;    mins = (int)(tsecs % 60);    tsecs /= 60;    hrs = (int)(tsecs % 24);    days = (int)(tsecs / 24);    if (days)        ap_rprintf(r, " %d day%s", days, days == 1 ? "" : "s");    if (hrs)        ap_rprintf(r, " %d hour%s", hrs, hrs == 1 ? "" : "s");    if (mins)        ap_rprintf(r, " %d minute%s", mins, mins == 1 ? "" : "s");    if (secs)        ap_rprintf(r, " %d second%s", secs, secs == 1 ? "" : "s");}/* 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     2struct stat_opt {    int id;    const char *form_data_str;    const char *hdr_out_str;};static const struct stat_opt status_options[] = /* see #defines above */{    {STAT_OPT_REFRESH, "refresh", "Refresh"},    {STAT_OPT_NOTABLE, "notable", NULL},    {STAT_OPT_AUTO, "auto", NULL},    {STAT_OPT_END, NULL, NULL}};static char status_flags[SERVER_NUM_STATUS];static int status_handler(request_rec *r){    const char *loc;    apr_time_t nowtime;    apr_interval_time_t up_time;    int j, i, res;    int ready;    int busy;    unsigned long count;    unsigned long lres, my_lres, conn_lres;    apr_off_t bytes, my_bytes, conn_bytes;    apr_off_t bcount, kbcount;    long req_time;#ifdef HAVE_TIMES    float tick;    int times_per_thread = getpid() != child_pid;#endif    int short_report;    int no_table_report;    worker_score *ws_record;    process_score *ps_record;    char *stat_buffer;    pid_t *pid_buffer, worker_pid;    clock_t tu, ts, tcu, tcs;    ap_generation_t worker_generation;    if (strcmp(r->handler, STATUS_MAGIC_TYPE) &&        strcmp(r->handler, "server-status")) {        return DECLINED;    }#ifdef HAVE_TIMES#ifdef _SC_CLK_TCK    tick = sysconf(_SC_CLK_TCK);#else    tick = HZ;#endif#endif    ready = 0;    busy = 0;    count = 0;    bcount = 0;    kbcount = 0;    short_report = 0;    no_table_report = 0;    pid_buffer = apr_palloc(r->pool, server_limit * sizeof(pid_t));    stat_buffer = apr_palloc(r->pool, server_limit * thread_limit * sizeof(char));    nowtime = apr_time_now();    tu = ts = tcu = tcs = 0;    if (!ap_exists_scoreboard_image()) {        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,                      "Server status unavailable in inetd mode");        return HTTP_INTERNAL_SERVER_ERROR;    }    r->allowed = (AP_METHOD_BIT << M_GET);    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) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -