Apache
Apache collector can collect the number of requests, connections and others from Apache services, and collect indicators to TrueWatch to help monitor and analyze various abnormal situations of Apache.
Configuration¶
Preconditions¶
-
Apache version >=
2.4.6 (Unix). Already tested version:- 2.4.56
- 2.4.54
- 2.4.41
- 2.4.38
- 2.4.29
- 2.4.6
-
Default configuration path:
- /etc/apache2/apache2.conf
- /etc/apache2/httpd.conf
- /usr/local/apache2/conf/httpd.conf
-
Open Apache
mod_statusand add the followings in Apache profile:
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from [YOUR_IP]
</Location>
- Restart Apache
Collector Configuration¶
Go to the conf.d/samples directory under the DataKit installation directory, copy apache.conf.sample and name it apache.conf. Examples are as follows:
[[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"
# ...
After configuration, restart DataKit.
The collector can now be turned on by configMap injection collector configuration.
Metric¶
For all of the following data collections, the global election tags will added automatically, we can add extra tags in [inputs.apache.tags] if needed:
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 |
Custom Object¶
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 |
Log Collection¶
To collect the Apache log, open files in apache.conf and write to the absolute path of the Apache log file. For example:
[[inputs.apache]]
...
[inputs.apache.log]
files = [
"/var/log/apache2/error.log",
"/var/log/apache2/access.log"
]
When log collection is turned on, logs with apache log (source) will be generated by default.
Info
DataKit must be installed on the host where Apache is located to collect Apache logs.
Log Pipeline Function Cut Field Description¶
- Apache Error Log Cutting
Error Log Text Example
[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
The list of cut fields is as follows:
| Field Name | Field Value | Description |
|---|---|---|
status |
error |
log level |
pid |
9802 |
process id |
type |
access_compat |
log type |
time |
1621391985000000000 |
nanosecond timestamp (as row protocol time) |
- Apache Access Log Cutting
Example of access log text:
The list of cut fields is as follows:
| Field Name | Field Value | Description |
|---|---|---|
status |
info |
log level |
ip_or_host |
127.0.0.1 |
requester ip or host |
http_code |
200 |
http status code |
http_method |
GET |
http request type |
http_url |
/ |
http request url |
http_version |
1.1 |
http version |
time |
1621205469000000000 |
nanosecond timestamp (as row protocol time) |