首页 > 解决方案 > 有没有办法用 Prometheus 和 Grafana 监控 Apache 服务器?

问题描述

我的要求是使用 Prometheus 和 Grafana 监控包含 Apache 的 Linode 虚拟机。(PS - Prometheus 和 Grafana 在单独的 Linode VM 中运行)

我使用以下文档安装 Apache 导出器: https ://www.techbeginner.in/2021/01/install-and-configure-apache-node.html 。服务文件是这样的:

[Unit]
Description=Prometheus
Documentation=https://github.com/Lusitaniae/apache_exporter
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/apache_exporter \
  --insecure \
  --scrape_uri=http://localhost/server-status/?auto \
  --telemetry.address=0.0.0.0:9117 \
  --telemetry.endpoint=/metrics

SyslogIdentifier=apache_exporter
Restart=always

[Install]
WantedBy=multi-user.target

我已将 --scrape_uri 更改为 http://usr_name:password@localhost/server-status/?auto \ 并将 --telemetry.address 更改为 127.0.0.1:9117 尽管我确信它不会有任何区别. Prometheus 能够抓取数据。但是当我导入一个 grafana 仪表板(ID - 3894)来可视化数据时,我没有得到任何数据。在整个仪表板的 7 个面板中(当前发送的总 kbytes、当前总 apache 访问、Apache 记分板状态、Apache 工作状态、Apache CPU 负载、正常运行时间和 Apache Up/Down),我可以看到 Apache Up/Down 的 grapf。其他 6 个说没有可用的数据

这是 prometheus.yml 配置:

#Apache Servers
  - job_name: apache-web-server
    static_configs:
      - targets: ['x.x.x.x:9117']
        labels:
          alias: server-apache

PS - 两个 Linode 实例都包含 Debian GNU/Linux 9.8 (stretch) 作为它们的操作系统。

我在这里想念什么?如何获取其余面板的图表?任何和所有的帮助表示赞赏。提前非常感谢。

标签: apacheprometheusgrafana

解决方案


从您提到的内容来看,您似乎没有设置 ExtendedStatus。

在这里查看:https ://httpd.apache.org/docs/2.4/mod/mod_status.html 。

The details given are:

The number of workers serving requests
The number of idle workers
The status of each worker, the number of requests that worker has     performed and the total number of bytes served by the worker (*)
A total number of accesses and byte count served (*)
The time the server was started/restarted and the time it has been running for
Averages giving the number of requests per second, the number of bytes served per second and the average number of bytes per request (*)
The current percentage CPU used by each worker and in total by all workers combined (*)
The current hosts and requests being processed (*)

The lines marked "(*)" are only available if ExtendedStatus is On. 

一个对我有用的示例配置,涵盖了所有指标:

ExtendedStatus On

<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from localhost
</Location>

也就是说,ExtendedStatus 从 2.3.6 开始默认为 On。我猜您使用的是低于该版本的 Apache 版本。


旁注:我写了一篇文章,涵盖了监控 Apache 的大部分方面,包括粒度流量指标:https ://www.giffgaff.io/tech/monitoring-apache-with-prometheus

它还涵盖了使用 ExtendedStatus 的 Apache 配置。


推荐阅读