You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Prometheus推送Apache指标到CloudWatch时部分指标缺失问题

排查解决步骤

1. 先确认apache exporter是否正常输出目标指标

  • 本地请求exporter暴露的metrics接口验证指标是否存在:
curl http://localhost:9117/metrics | grep "apache_workers"
  • 检查返回结果中是否存在apache_workers{state="busy"}条目:
    • 若不存在:优先检查apache服务是否开启了mod_status,且exporter启动参数中开启了workers collector(默认是开启的,若手动指定了--collectors.enabled参数需要确认包含workers)
    • 若存在:继续向下排查CloudWatch Agent配置问题

2. 修正CloudWatch Agent配置错误

你当前配置存在2处语法错误,是导致指标无法匹配的核心原因:

CloudWatch Agent的metric_selectors字段仅支持匹配纯指标名称,不支持直接写入带标签过滤的PromQL表达式;同时metric_unit的键也仅支持填写纯指标名,不能携带标签匹配规则。

修正后的配置片段示例(仅展示需要修改的emf_processor部分)

"emf_processor": {
  "metric_declaration_dedup": true,
  "metric_namespace": "Apache",
  "metric_unit": {
    "apache_accesses_total": "Count",
    "apache_cpuload": "Percent",
    "apache_up": "Count",
    "apache_sent_kilobytes_total": "Bytes",
    "apache_workers": "Count"
  },
  "metric_declaration": [
    {
      "source_labels": ["job", "state"],
      "label_matcher": "^httpd;busy$",
      "dimensions": [["InstanceId","ComponentName"],["ComponentName"]],
      "metric_selectors": [
        "^apache_accesses_total$",
        "^apache_cpuload$",
        "^apache_up$",
        "^apache_sent_kilobytes_total$",
        "^apache_workers$"
      ]
    }
  ]
}
  • 说明:通过将state加入source_labels,用label_matcher的;分隔多个标签的匹配规则,实现仅采集state为busy的apache_workers指标。如果需要同时上报其他state的workers指标,也可以单独新增一条metric_declaration规则,或者将state加入dimensions维度区分不同状态的指标。

3. 验证配置并重启Agent

  • 先执行配置校验命令,确认语法合法:
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a check-config -c /path/to/your/config.json
  • 校验无报错后重启Agent生效:
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a start -c file:/path/to/your/config.json

4. 排查Agent日志确认上报正常

查看Agent运行日志,确认无指标匹配、上报相关报错:

tail -f /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log | grep -i "prometheus\|apache"

内容的提问来源于stack exchange,提问作者Jijo John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 17:54:03