Apache 网络服务器集成会收集与流量相关的指标,例如打开连接数或传入请求。集成还会收集访问和错误日志。访问日志会被解析为专注于请求详细信息的 JSON 载荷,而错误日志会被解析为其错误代码和消息。
如需详细了解 Apache 网络服务器,请参阅 http://httpd.apache.org/。
前提条件
如需收集 Apache Web Server 遥测数据,您必须安装 Ops Agent 2.7.0 或更高版本。
此接收器支持 Apache Web Server 2.4 版。
配置 Apache Web Server 实例
如需从 Apache Web Server 收集遥测,您必须配置服务器的 httpd.conf
文件以启用 mod_status
插件。
很多情况下,安装 Apache 时会默认启用此插件。如需查看您的虚拟机实例上是否启用了该插件,请运行以下命令:
curl localhost:80/server-status?auto
如果已启用该插件,则输出将包含类似于以下内容的行:
Total Accesses: 2 Total kBytes: 1 BusyWorkers: 1 IdleWorkers: 4
如果您看到 404 Not Found
页面,则表明 mod_status
插件未启用。
为 Apache Web Server 配置 Ops Agent
按照配置 Ops Agent 指南,添加从 Apache Web Server 实例收集日志所需的元素,并重启代理。
配置示例
以下命令会创建相关配置,以收集和注入 Apache Web Server 的日志和指标,并在 Linux 上重启 Ops Agent。
sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF
logging:
receivers:
apache_access:
type: apache_access
apache_error:
type: apache_error
service:
pipelines:
apache:
receivers:
- apache_access
- apache_error
metrics:
receivers:
apache:
type: apache
service:
pipelines:
apache:
receivers:
- apache
EOF
sudo service google-cloud-ops-agent restart
配置日志收集
如需从 Apache Web Server 注入日志,您必须为 Apache Web Server 生成的日志创建接收器,然后为新的接收器创建流水线。如需为日志配置接收器,请指定以下字段:
如需为 apache_access
日志配置接收器,请指定以下字段:
字段 | 默认 | 说明 |
---|---|---|
type |
该值必须为 apache_access 。 |
|
include_paths |
[/var/log/apache2/access.log,/var/log/apache2/access_log,/var/log/httpd/access_log] |
要通过跟踪每个文件读取的文件系统路径列表。路径中可以使用通配符 (* );例如 /var/log/apache*/*.log 。 |
exclude_paths |
[] |
要从 include_paths 匹配的集合中排除的文件系统路径模式列表。 |
wildcard_refresh_interval |
60s |
include_paths 中通配符文件路径的刷新间隔。指定为时长,例如 30s 或 2m 。该属性在高日志记录吞吐量下可能很有用,因为日志文件的轮替速度快于默认时间间隔。 |
如需为 apache_error
日志配置接收器,请指定以下字段:
字段 | 默认 | 说明 |
---|---|---|
type |
该值必须为 apache_error 。 |
|
include_paths |
[/var/log/apache2/error.log,/var/log/apache2/error_log,/var/log/httpd/error_log] |
要通过跟踪每个文件读取的文件系统路径列表。路径中可以使用通配符 (* );例如 /var/log/apache*/*.log 。 |
exclude_paths |
[] |
要从 include_paths 匹配的集合中排除的文件系统路径模式列表。 |
wildcard_refresh_interval |
60s |
include_paths 中通配符文件路径的刷新间隔。指定为时长,例如 30s 、2m 。该属性在高日志记录吞吐量下可能很有用,因为日志文件的轮替速度快于默认时间间隔。 |
记录的内容
apache_access
和 apache_error
日志的 logName
派生自配置中指定的接收器 ID。LogEntry
中的详细字段如下所示。
apache_access
日志包含 httpRequest
字段:
字段 | 类型 | 说明 |
---|---|---|
httpRequest.protocol |
字符串 | 用于请求的协议 |
httpRequest.referer |
字符串 | Referer 标头的内容 |
httpRequest.requestMethod |
字符串 | HTTP 方法 |
httpRequest.requestUrl |
字符串 | 请求网址(通常只是网址的路径部分) |
httpRequest.responseSize |
字符串 (int64 ) |
响应大小 |
httpRequest.status |
数字 | HTTP 状态代码 |
httpRequest.userAgent |
字符串 | User-Agent 标头的内容 |
jsonPayload.host |
字符串 | Host 标头的内容 |
jsonPayload.user |
字符串 | 请求经过身份验证的用户名 |
timestamp |
字符串 (Timestamp ) |
收到请求的时间 |
日志条目不包含任何空白字段或缺失字段。
apache_error
日志包含 LogEntry
中的以下字段:
字段 | 类型 | 说明 |
---|---|---|
jsonPayload.errorCode |
字符串 | Apache 错误代码 |
jsonPayload.level |
字符串 | 日志条目级别 |
jsonPayload.module |
字符串 | 日志源自的 Apache 模块 |
jsonPayload.pid |
数字 | 进程 ID |
jsonPayload.tid |
数字 | 线程 ID |
jsonPayload.message |
字符串 | 日志消息 |
jsonPayload.client |
字符串 | 客户端 IP 地址(可选) |
severity |
字符串 (LogSeverity ) |
日志条目级别(已转换) |
timestamp |
字符串 (Timestamp ) |
记录条目的时间 |
配置指标收集
如需从 Apache Web Server 收集指标,您必须为 Apache 指标创建接收器,然后为新接收器创建流水线。要为 Apache 指标配置接收器,请指定以下字段:
字段 | 默认 | 说明 |
---|---|---|
type |
该值必须为 apache 。 |
|
server_status_url |
http://localhost:80/server-status?auto |
由 mod_status 模块公开的网址。 |
collection_interval |
60s |
time.Duration 值,例如 30s 或 5m 。 |
监控的内容
下表提供了 Ops Agent 从 Apache Web Server 实例收集的指标列表。
指标类型 | |
---|---|
种类、类型 受监控的资源 |
标签 |
workload.googleapis.com/apache.current_connections
|
|
GAUGE 、INT64 gce_instance |
server_name
|
workload.googleapis.com/apache.requests
|
|
CUMULATIVE 、INT64 gce_instance |
server_name
|
workload.googleapis.com/apache.scoreboard
|
|
GAUGE 、INT64 gce_instance |
state
server_name
|
workload.googleapis.com/apache.traffic
|
|
CUMULATIVE 、INT64 gce_instance |
server_name
|
workload.googleapis.com/apache.workers
|
|
GAUGE 、INT64 gce_instance |
state
server_name
|
示例信息中心
您可以使用示例 Cloud Monitoring 信息中心查看集成中的指标。完成安装示例信息中心过程,从示例库中导入 Apache GCE 概览信息中心并查看图表显示 Apache 网络服务器指标。验证配置
您可以使用日志浏览器和 Metrics Explorer 来验证已正确配置 Apache Web Server 接收器。Ops Agent 可能需要一两分钟才会开始收集日志和指标。
如需验证是否已注入日志,请转到日志浏览器并运行以下查询来查看 Apache Web Server 日志:
resource.type="gce_instance"
logName=("projects/PROJECT_ID/logs/apache_access" OR "projects/PROJECT_ID/logs/apache_error")
如需验证指标是否已注入,请转到 Metrics Explorer 并在 MQL 标签页中运行以下查询。
fetch gce_instance
| metric 'workload.googleapis.com/apache.requests'
| align rate(1m)
| every 1m