(六)Prometheus 監控 apache 服務

通過上一篇(四)Prometheus + Grafana 可視化 的學習,我們已經對 prometheus 做了一個精美的可視化,本篇詳細講解 Prometheus + Grafana 監控 apache 服務。

準備環境

# 這裏使用的是(四)Prometheus + Grafana 可視化 完成時的環境
centos 7
prometheus 運行正常
grafana 運行正常

[root@fp-21 ~]# getenforce
Permissive

[root@fp-21 ~]# ss -lntp |grep prometheus
LISTEN     0      128         :::9090                    :::*                   users:(("prometheus",pid=10531,fd=6))

[root@fp-21 ~]# ss -lntp |grep grafana
LISTEN     0      128    10.0.0.21:3000                     *:*                   users:(("grafana-server",pid=10690,fd=7))

安裝 Apache

[root@fp-21 ~]# yum -y install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
……
Dependency Installed:
  mailcap.noarch 0:2.1.41-2.el7                                                                     

Complete!

安裝 Apache exporter 收集 nginx 的 json 數據,點擊下載

# 本地下載也可以
[root@fp-21 ~]# cd /opt/ ; mkdir apache_exporter ; cd apache_exporter
[root@fp-21 apache_exporter]# wget https://github.com/Lusitaniae/apache_exporter/releases/download/v0.5.0/apache_exporter-0.5.0.linux-amd64.tar.gz
[root@fp-21 apache_exporter]# ls
apache_exporter-0.5.0.linux-amd64.tar.gz

# 解壓
[root@fp-21 apache_exporter]# tar xf apache_exporter-0.5.0.linux-amd64.tar.gz 
[root@fp-21 apache_exporter]# ls
apache_exporter-0.5.0.linux-amd64  apache_exporter-0.5.0.linux-amd64.tar.gz

# 移動位置
[root@fp-21 apache_exporter]# mv apache_exporter-0.5.0.linux-amd64 /usr/local/apache_exporter
[root@fp-21 apache_exporter]# cd !$
cd /usr/local/apache_exporter
[root@fp-21 apache_exporter]# ls
apache_exporter  LICENSE
[root@fp-21 apache_exporter]# cp apache_exporter /usr/local/bin

啓動 apahce 服務

# 啓動
[root@fp-21 apache_exporter]# systemctl start httpd

# 查看進程
[root@fp-21 apache_exporter]# ps -ef |grep httpd
root      15455      1  0 21:06 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    15456  15455  0 21:06 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    15457  15455  0 21:06 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    15458  15455  0 21:06 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    15459  15455  0 21:06 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    15460  15455  0 21:06 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root      15462  15029  0 21:07 pts/1    00:00:00 grep --color=auto httpd

# 查看端口
[root@fp-21 apache_exporter]# ss -lntp |grep httpd
LISTEN     0      128         :::80                      :::*                   users:(("httpd",pid=15460,fd=4),("httpd",pid=15459,fd=4),("httpd",pid=15458,fd=4),("httpd",pid=15457,fd=4),("httpd",pid=15456,fd=4),("httpd",pid=15455,fd=4))

啓動 apache_exporter

[root@fp-21 ~]# apache_exporter 
INFO[0000] Starting apache_exporter (version=0.5.0, branch=HEAD, revision=f6a5b4814ea795ee9eac745c55649cce9e5117a9)  source="apache_exporter.go:305"
INFO[0000] Build context (go=go1.9.2, user=root@0fdc4d8924f5, date=20171113-21:19:13)  source="apache_exporter.go:306"
INFO[0000] Starting Server: :9117                        source="apache_exporter.go:307"

查看是否啓動成功

[root@fp-21 ~]# ss -lntp |grep 9117
LISTEN     0      128         :::9117                    :::*                   users:(("apache_exporter",pid=15466,fd=3))

添加監控至 Prometheus

[root@fp-21 ~]# vim /usr/local/prometheus/conf/prometheus.yml
 
 35   - job_name: 'apache_status'	# 標籤名,監控名
 36     static_configs:
 37     - targets: ['10.0.0.21:9117']	# IP:端口

查看 Prometheus 狀態

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-NG5qNLS5-1585663304207)(E:\知識點總結\Prometheus\assets\prometheus_26.png)]

報錯:無法收集到頁面信息

ERRO[0206] Error scraping apache: Status 404 Not Found (404): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /server-status/ was not found on this server.</p>

</body></html>
  source="apache_exporter.go:287"

添加 apache 模板

[root@fp-21 ~]# vim /etc/httpd/conf/httpd.conf 
354 LoadModule status_module modules/mod_status.so
355 <location /server-status>
356          SetHandler server-status
357          Order Deny,Allow
358          Deny from nothing
359          Allow from all
360 </location>

訪問測試數據頁面

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-6U5pi2Kz-1585663304211)(E:\知識點總結\Prometheus\assets\prometheus_27.png)]

再次啓動

[root@fp-21 ~]# apache_exporter 
INFO[0000] Starting apache_exporter (version=0.5.0, branch=HEAD, revision=f6a5b4814ea795ee9eac745c55649cce9e5117a9)  source="apache_exporter.go:305"
INFO[0000] Build context (go=go1.9.2, user=root@0fdc4d8924f5, date=20171113-21:19:13)  source="apache_exporter.go:306"
INFO[0000] Starting Server: :9117                        source="apache_exporter.go:307"

[root@fp-21 ~]# ss -lntp |grep 9117
LISTEN     0      128         :::9117                    :::*                   users:(("apache_exporter",pid=15709,fd=3))

導入 Grafana 模板

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

只有注入思想的博客纔是好的博客

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章