关于apache:apache服务资源监控

52次阅读

共计 4262 个字符,预计需要花费 11 分钟才能阅读完成。

配置

须要批改 apache httpd 加载配置文件httpd-info.conf

须要凋谢拜访 server-infoserver-status的权限

docker实现

创立 Dockerfile 如下

FROM httpd:2.4-alpine

# 启用 httpd info 模块
RUN sed -i "s|#Include conf/extra/httpd-info.conf|Include conf/extra/httpd-info.conf|g" /usr/local/apache2/conf/httpd.conf
# 加载 mod info 凋谢拜访 server info 信息
RUN sed -i "s|#LoadModule info_module modules/mod_info.so|LoadModule info_module modules/mod_info.so|g" /usr/local/apache2/conf/httpd.conf
# 配置容许近程拜访,防止 403 谬误
RUN sed -i "s/Require host .example.com/Order deny,allow/g" /usr/local/apache2/conf/extra/httpd-info.conf
RUN sed -i "s/Require ip 127/Allow from all/g" /usr/local/apache2/conf/extra/httpd-info.conf

创立compose.yaml

services:
  apache:
    container_name: demo-apache
    image: demo-apache
    build: .
    restart: always
    ports:
      - "80:80"

构建镜像

$ docker compose build

服务启动

$ docker compose up -d

查看拜访配置信息

$ docker exec demo-apache cat /usr/local/apache2/conf/extra/httpd-info.conf
....
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Allow from all
</Location>
....
<Location /server-info>
    SetHandler server-info
    Order deny,allow
    Allow from all
</Location>

验证后果

浏览器拜访地址 http://127.0.0.1/server-status 获取服务状态信息

Apache Server Status for 127.0.0.1 (via 172.29.0.2)
Server Version: Apache/2.4.55 (Unix)
Server MPM: event
Server Built: Feb 11 2023 09:43:46
Current Time: Monday, 20-Mar-2023 07:01:24
Restart Time: Monday, 20-Mar-2023 07:00:29
Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 54 seconds
Server load: 0.75 0.88 0.92
Total accesses: 2 - Total Traffic: 52 kB - Total Duration: 4
CPU Usage: u.02 s.02 cu0 cs0 - .0741% CPU load
.037 requests/sec - 986 B/second - 26.0 kB/request - 2 ms/request
1 requests currently being processed, 99 idle workers
Slot    PID    Stopping    Connections    Threads    Async connections
total    accepting    busy    idle    writing    keep-alive    closing
0    8    no    0    yes    0    25    0    0    0
1    9    no    0    yes    0    25    0    0    0
2    10    no    0    yes    1    24    0    0    0
3    92    no    0    yes    0    25    0    0    0
Sum    4    0    0         1    99    0    0    0
___________________________________________________W____________
____________________________________............................
................................................................
................................................................
................................................................
................................................................
................
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
Srv    PID    Acc    M    CPU    SS    Req    Dur    Conn    Child    Slot    Client    Protocol    VHost    Request
1-0    9    0/1/1    _    0.00    50    3    3    0.0    0.05    0.05    172.29.0.1    http/1.1    172.29.0.2:80    GET /server-info HTTP/1.1
2-0    10    0/1/1    _    0.00    4    0    0    0.0    0.00    0.00    172.29.0.1    http/1.1    172.29.0.2:80    GET /serve-status HTTP/1.1
2-0    10    2/0/0    W    0.00    0    0    0    0.0    0.00    0.00    172.29.0.1    http/1.1    172.29.0.2:80    GET /server-status HTTP/1.1

拜访 http://127.0.0.1/server-info 获取服务根底配置信息

Apache Server Information
Subpages:
Configuration Files, Server Settings, Module List, Active Hooks, Available Providers
Sections:
Loaded Modules, Server Settings, Startup Hooks, Request Hooks, Other Hooks, Providers
Loaded Modules
core.c, event.c, http_core.c, mod_access_compat.c, mod_alias.c, mod_auth_basic.c, mod_authn_core.c, mod_authn_file.c, mod_authz_core.c, mod_authz_groupfile.c, mod_authz_host.c, mod_authz_user.c, mod_autoindex.c, mod_dir.c, mod_env.c, mod_filter.c, mod_headers.c, mod_info.c, mod_log_config.c, mod_mime.c, mod_reqtimeout.c, mod_setenvif.c, mod_so.c, mod_status.c, mod_unixd.c, mod_version.c,
Server Settings
Server Version: Apache/2.4.55 (Unix)
Server Built: Feb 11 2023 09:43:46
Server loaded APR Version: 1.7.2
Compiled with APR Version: 1.7.2
Server loaded APU Version: 1.6.3
Compiled with APU Version: 1.6.3
Server loaded PCRE Version: 8.45 2021-06-15
Compiled with PCRE Version: 8.45 2021-06-15
Module Magic Number: 20120211:126
Hostname/port: 127.0.0.1:80
Timeouts: connection: 60    keep-alive: 5
MPM Name: event
MPM Information: Max Daemons: 4 Threaded: yes Forked: yes
Server Architecture: 64-bit
Server Root: /usr/local/apache2
Config File: /usr/local/apache2/conf/httpd.conf
Server Built With: 
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/usr/local/apache2"
 -D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
Startup Hooks

正文完
 0