在安装apache_exporter之前,首先得保证Apache有mod_status这个模块
#修改Apache的配置文件:httpd-info.conf
vim /usr/local/apache/conf/extra/httpd-info.conf
<Location /server-status>
SetHandler server-status
Order deny,allow
allow from all
AuthType Basic
AuthName 'Apache Server Status'
AuthUserFile '/usr/local/apache/conf/.htpasswd'
Require valid-user
</Location>
<Location /server-info>
SetHandler server-status
Order deny,allow
allow from all
AuthType Basic
AuthName 'Apache Server Status'
AuthUserFile '/usr/local/apache/conf/.htpasswd'
Require valid-user
</Location>
-
由于Apache服务信息属于敏感信息,需配置用户身份证
htpasswd -c -m /usr/local/apache/conf/.htpasswd hdkj
-
接下来正式安装apache_exporter
-
创建一个临时目录
-
$ mkdir /tmp/go
-
设置环境变量
-
$ export GOPATH=/tmp/go
-
进入临时目录使用go命令从远程仓库获取apache_exporter
-
$ cd /tmp/go
-
$ go get -u github.com/Lusitaniae/apache_exporter
-
查看一下下载好的apache_exporter
-
ll src/github.com/Lusitaniae/apache_exporter/
-
使用make命令编译源代码
-
编译完成之后,将生成的apache_exporter拷贝至安装目录
配置启动服务:
-
vim /usr/lib/systemd/system/apache_exporter.service
[Unit]
Description=Prometheus apache exporter
Documentation=https://github.com/Lusitaniae/apache_exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/apache_exporter/apache_exporter --scrape_uri=http://hdkj:HDkj123456@localhost/server-status?auto
Restart=on-failure
[Install]
WantedBy=multi-user.target
-
启动一下服务
-
systemctl start apache_exporter
-
ss -tnl | grep 9117 #如果端口9117存在,说明服务启动成功;
在Promethus配置文件中加入apache_exporter
job_name: 'apache_exporter'
metrics_path: "/metrics"
static_configs:
- targets: ['192.168.8.133:9117']
labels:
instance: '192.168.8.133:9117'
- targets: ['192.168.8.134:9117']
labels:
instance: '192.168.8.134:9117'
配置监控规则:
groups:
- name: apache_exporter_alerts
rules:
- alert: ApacheWorkerStatus
expr: apache_workers{state="busy"} > 320
for: 30s
labels:
severity: warning
annotations:
summary: "ApacheWorkerStatus (instance {{ $labels.instance }})"
description: "Apache worker status is busy more than 80%
VALUE = {{ $value }}
LABELS: {{ $labels }}"
- alert: ApacheConnectionsStatus
expr: apache_connections{state="total"} > 1000
for: 30s
labels:
severity: warning
annotations:
summary: "Apache Connection Statuses (instance {{ $labels.instance }})"
description: "Apache Connections Is Too many
VALUE = {{ $value }}
LABELS: {{ $labels }}"
- alert: Apache Service
expr: apache_up == 0
for: 30s
labels:
severity: error
annotations:
summary: "ApacheServiceStatuses (instance {{ $labels.instance }})"
description: "Apache Service Is Not Work;Please Connect Ops Group Quick Deal With
VALUE = {{ $value }}
LABELS: {{ $labels }}"