Apache
Apache 采集器可以从 Apache 服务中采集请求数、连接数等,并将指标采集到观测云,帮助监控分析 Apache 各种异常情况。
配置¶
前置条件¶
-
Apache 版本 >=
2.4.6 (Unix)。已测试版本:- 2.4.56
- 2.4.54
- 2.4.41
- 2.4.38
- 2.4.29
- 2.4.6
-
默认配置路径:
- /etc/apache2/apache2.conf
- /etc/apache2/httpd.conf
- /usr/local/apache2/conf/httpd.conf
-
开启 Apache
mod_status,在 Apache 配置文件中添加:
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from [YOUR_IP]
</Location>
- 重启 Apache
采集器配置¶
进入 DataKit 安装目录下的 conf.d/samples 目录,复制 apache.conf.sample 并命名为 apache.conf。示例如下:
[[inputs.apache]]
url = "http://127.0.0.1/server-status?auto"
# ##(optional) collection interval, default is 30s
# interval = "30s"
# username = ""
# password = ""
## Optional TLS Config
# tls_ca = "/xxx/ca.pem"
# tls_cert = "/xxx/cert.cer"
# tls_key = "/xxx/key.key"
## Use TLS but skip chain & host verification
insecure_skip_verify = false
## Set true to enable election
election = true
# [inputs.apache.log]
# files = []
# #grok pipeline script path
# pipeline = "apache.p"
[inputs.apache.tags]
# some_tag = "some_value"
# more_tag = "some_other_value"
# ...
配置好后,重启 DataKit 即可。
目前可以通过 ConfigMap 方式注入采集器配置来开启采集器。
指标集¶
以下所有数据采集,默认会追加全局选举 tag,也可以在配置中通过 [inputs.apache.tags] 指定其它标签:
apache¶
Apache HTTP Server metrics parsed from the machine-readable mod_status server-status?auto output. Available fields depend on Apache version, MPM, platform, and ExtendedStatus configuration.
| Tags & Fields | Description |
|---|---|
| host ( tag) |
Hostname. |
| server_mpm ( tag) |
Apache server Multi-Processing Module, prefork, worker and event. Optional. |
| server_version ( tag) |
Apache server version. Optional. |
| url ( tag) |
Apache server status url. |
| busy_workers | Current number of workers serving requests. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| closing_connection | Current workers closing connections. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| conns_async_closing | Current asynchronous connections in closing state; unavailable on Windows. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| conns_async_keep_alive | Current asynchronous connections in keep-alive state; unavailable on Windows. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| conns_async_writing | Current asynchronous connections in writing state; unavailable on Windows. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| conns_total | Current total asynchronous connections; unavailable on Windows. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| cpu_load | Current CPU usage percentage reported by Apache mod_status; unavailable on Windows and optional depending on configuration.Type: float | (gauge) Unit: percent,percent Tagged by: server_mpm, server_version, url |
| disabled | Current disabled scoreboard slots. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| dns_lookup | Current workers waiting for DNS lookup. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| gracefully_finishing | Current workers gracefully finishing requests. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| idle_cleanup | Current workers in idle cleanup. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| idle_workers | Current number of idle workers. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| keepalive | Current workers in keep-alive state. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| logging | Current workers writing to Apache logs. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| max_workers | Current total number of worker slots in the Apache scoreboard. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| net_bytes | Cumulative bytes served since the Apache server started. Type: int | (count) Unit: digital,B Tagged by: server_mpm, server_version, url |
| net_hits | Cumulative requests served since the Apache server started. Type: int | (count) Unit: count Tagged by: server_mpm, server_version, url |
| open_slot | Current open scoreboard slots with no process. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| reading_request | Current workers reading requests. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| sending_reply | Current workers sending replies. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| starting_up | Current workers starting up. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
| uptime | Seconds since the Apache server started. Type: int | (gauge) Unit: time,s Tagged by: server_mpm, server_version, url |
| waiting_for_connection | Current workers waiting for a connection. Type: int | (gauge) Unit: count Tagged by: server_mpm, server_version, url |
collector¶
Shared collector availability metric emitted by multiple collectors to report whether the target was successfully scraped.
| Tags & Fields | Description |
|---|---|
| instance ( tag) |
Server addr of the instance |
| job ( tag) |
Server name of the instance |
| up | Whether the collector successfully scraped the target during the last collection cycle: 1 means true and 0 means false. Type: int | (gauge) Unit: bool |
自定义对象¶
web_server¶
Apache web server instance inventory and collector status information emitted as a custom object.
| Tags & Fields | Description |
|---|---|
| col_co_status ( tag) |
Collector status for this instance, such as OK or NotOK. |
| host ( tag) |
Hostname or address of the server that runs this instance. |
| ip ( tag) |
Configured connection IP address for this instance. |
| name ( tag) |
Stable object identifier for this monitored instance. |
| reason ( tag) |
Reason reported when the collector status is not OK. |
| display_name | Display name shown for this instance in the Datakit UI. Type: string | (string) Unit: N/A Tagged by: col_co_status, host, ip, name, reason |
| uptime | Time in seconds since this instance last started. Type: int | (gauge) Unit: time,s Tagged by: col_co_status, host, ip, name, reason |
| version | Server version reported by this instance. Type: string | (string) Unit: N/A Tagged by: col_co_status, host, ip, name, reason |
日志采集¶
如需采集 Apache 的日志,可在 apache.conf 中 将 files 打开,并写入 Apache 日志文件的绝对路径。比如:
[[inputs.apache]]
...
[inputs.apache.log]
files = [
"/var/log/apache2/error.log",
"/var/log/apache2/access.log"
]
开启日志采集以后,默认会产生日志来源(source)为 apache 的日志。
Info
必须将 DataKit 安装在 Apache 所在主机才能采集 Apache 日志
Pipeline 字段说明¶
- Apache 错误日志切割
错误日志文本示例:
[Tue May 19 18:39:45.272121 2021] [access_compat:error] [pid 9802] [client ::1:50547] AH01797: client denied by server configuration: /Library/WebServer/Documents/server-status
切割后的字段列表如下:
| 字段名 | 字段值 | 说明 |
|---|---|---|
status |
error |
日志等级 |
pid |
9802 |
进程 id |
type |
access_compat |
日志类型 |
time |
1621391985000000000 |
纳秒时间戳(作为行协议时间) |
- Apache 访问日志切割
访问日志文本示例:
切割后的字段列表如下:
| 字段名 | 字段值 | 说明 |
|---|---|---|
status |
info |
日志等级 |
ip_or_host |
127.0.0.1 |
请求方 IP 或者 host |
http_code |
200 |
http status code |
http_method |
GET |
http 请求类型 |
http_url |
/ |
http 请求 URL |
http_version |
1.1 |
http version |
time |
1621205469000000000 |
纳秒时间戳(作为行协议时间) |