Prometheus基礎(chǔ)-監(jiān)控linux、系統(tǒng)服務(wù)、docker、mysql

常用指令

服務(wù)啟動

[root@prometheus prometheus]# systemctl daemon-reload
[root@prometheus prometheus]# systemctl restart node_exporter
[root@prometheus prometheus]# systemctl  restart prometheus
[root@prometheus prometheus]# systemctl restart grafana
[root@prometheus prometheus]# systemctl restart updatetime

工具檢測

[root@prometheus prometheus]#  ./promtool check config ./prometheus.yml 

熱加載

[root@prometheus prometheus]# ps -ef|grep prometheus
[root@prometheus prometheus]# kill -HUP 1267

時間同步

$ yum install ntpdate -y
$ ntpdate time.windows.com

相關(guān)服務(wù)

prometheus

http://192.168.153.22:9090/

-------------------------------prometheus----------------------------------------
# vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
[Service]
ExecStart=/opt/monitor/prometheus/prometheus --config.file=/opt/monitor/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
---------------------------------------------------------------------

[root@prometheus prometheus]# systemctl daemon-reload
[root@prometheus prometheus]# systemctl start prometheus

grafana

http://192.168.153.21:3000/

------------------------------------grafana----------------------------------
[root@prometheus ~]# vi /usr/lib/systemd/system/grafana.service

[Unit]
Description=grafana
[Service]
ExecStart=/opt/monitor/grafana/bin/grafana-server -homepath=/opt/monitor/grafana
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
--------------------------------------------------------------------------------------
[root@prometheus prometheus]# systemctl daemon-reload
[root@prometheus prometheus]# systemctl start grafana

node_exporter

[root@k8snode1 prometheus]# vi /usr/lib/systemd/system/node_exporter.service 
[Unit]
Description=node_exporter
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

----------------------------------------------------------------------------

[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl start node_exporter

prometheus監(jiān)控

配置被監(jiān)控端

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'Linux Server'
    static_configs:
    - targets: ['192.168.153.20:9100']
1635429871239.png

監(jiān)控Linux服務(wù)器

使用Grafana展示node_exporter數(shù)據(jù)指標(biāo),儀表盤ID: 9276


1635430281665.png
1635430316866.png

node_exporter啟用HTTP認(rèn)證

安裝httpd-tool

[root@prometheus ~]# yum install httpd-tools –y

[root@prometheus ~]# htpasswd -nBC 12 '' | tr -d ':\n'
New password: 
Re-type new password: 
$2y$12$w78Y3R7SLaGlPY4OkmRCcu7esY.xzENZeDTj.87QhWsBRADyaRDLi

[root@prometheus node_exporter]# ls
LICENSE  node_exporter  NOTICE
[root@prometheus node_exporter]# vi config.yml
basic_auth_users:
  lql: $2y$12$w78Y3R7SLaGlPY4OkmRCcu7esY.xzENZeDTj.87QhWsBRADyaRDLi
  
  

系統(tǒng)服務(wù)-node_exporter

 
[root@prometheus node_exporter]# vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
[Service]
ExecStart=/usr/local/node_exporter/node_exporter  --web.config=/usr/local/node_exporter/config.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

----------------------------------------------------------------------------

[root@prometheus ~]# systemctl daemon-reload
[root@prometheus ~]# systemctl start node_exporter

primetheus配置文件

  - job_name: 'Linux Server'
    basic_auth:
      username: lql
      password: 12345678
    static_configs:
    - targets: ['192.168.153.20:9100']

監(jiān)控系統(tǒng)服務(wù)運行狀態(tài)

服務(wù)配置

 
[root@prometheus node_exporter]# vi /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
[Service]
ExecStart=/usr/local/node_exporter/node_exporter --web.config=/usr/local/node_exporter/config.yml --collector.systemd  --collector.systemd.unit-whitelist=
(docker|sshd|nginx).service
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

----------------------------------------------------------------------------------

[root@prometheus prometheus]# systemctl daemon-reload
[root@prometheus prometheus]# systemctl restart node_exporter

http://192.168.153.17:9100/metrics

服務(wù)檢測

1635475436994.png

查看服務(wù)狀態(tài)

node_systemd_unit_state
1635475662804.png
1635475816420.png
#docker服務(wù)關(guān)閉,value則為0 (systemctl stop dokcer )

監(jiān)控docker

Docker部署cAdvisor

docker run -d \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest

http://192.168.153.17:8080/metrics

prometheus配置

  - job_name: 'docker'
    static_configs:
    - targets: ['192.168.153.17:8080']
    
1635476978343.png

導(dǎo)入granfana

儀表盤模板ID:193
1635477572914.png

增加相關(guān)變量

1635489169318.png
label_values(up,instance)
.*:8080

#修改指標(biāo)【instance="$Node"】,每個指標(biāo)都要修改
#比如:sum(rate(container_cpu_user_seconds_total{image!="",instance="$Node"}[5m]) * 100)

監(jiān)控mysql

啟動mysql

[root@ansible ~]# docker start mysql

啟動mysqld_exporter服務(wù)

[root@ansible mysql_exporter]# ls
LICENSE  mysqld_exporter  NOTICE

#配置文件寫入mysql的用戶名和密碼
[root@ansible mysql_exporter]# vi .my.cnf
[client]
user=root
password=123
#啟動服務(wù)
[root@ansible mysql_exporter]# ./mysqld_exporter --config.my-cnf=".my.cnf"
http://192.168.153.17:9104/

prometheus配置

http://192.168.153.17:9104/

  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.153.17:9104']

導(dǎo)入granfana

儀表盤ID:7362
1635491714113.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請通過簡信或評論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容