Prometheus监控MySQL和Linux主机结合Grafana出图

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Prometheus监控MySQL和Linux主机结合Grafana出图脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

监控的命令

top
DF
free
htop
uptime
cat /PRoc/meminfo 
iftop         流量监控工具
nethogs       查看进程占用的网络带宽
iotop

prometheus监控流程

# 携带metrics接口的服务
1、使用prometheus链接metrics获取数据

# 不携带metrics接口的服务
1、安装exporter服务(为不提供metrics的服务提供一个metrics接口)

2、使用prometheus链接metrics获取数据

部署prometheus

[root@prometheus ~]# wget https://gIThub.COM/prometheus/prometheus/releases/download/v2.30.0/prometheus-2.30.0.linux-amd64.tar.gz

[root@prometheus ~]# tar xf prometheus-2.30.0.linux-amd64.tar.gz -C /usr/local/
[root@prometheus ~]# cd /usr/local

#做软链接
[root@prometheus /usr/local]# chown -R root.root prometheus-2.30.0.linux-amd64
[root@prometheus /usr/local]# ln -s /usr/local/prometheus-2.30.0.linux-amd64 /usr/local/prometheus

#配置环境变量
[root@prometheus /usr/local]# vim /etc/profile.d/prometheus.sh
export PATH=/usr/local/prometheus:$PATH

[root@prometheus /usr/local]# source /etc/profile

# 启动(测试)
[root@promethues /usr/local/prometheus]# prometheus --config.file="/usr/local/prometheus/prometheus.yML"

#添加至System管理
[root@promethues ~]# vim /usr/lib/systemd/system/prometheus.service 
[Unit]
Description=Prometheus
[Service]
TyPE=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle  
Restart=on-failure
[Install]
WantedBy=multi-user.target

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

#目录说明
[root@promethus /usr/local/prometheus]# ls 
console_libraries       --->控制台函数库
consoles                --->控制台
data                    --->数据存放目录
 
LICENSE                 --->许可证
NOTICE                  --->通知
prometheus              --->启动脚本
prometheus.yml          --->主配置文件
promtool                --->系统工具

#主配置文件说明
[root@promethus /usr/local/prometheus]# cat prometheus.yml
 
global:                 --->全局变量
  scrape_interval:     15s # 抓取时间间隔,每隔15秒去抓取一次
  evaluation_interval: 15s # 监控数据评估间隔
 
scrape_configs:
  - job_name: 'prometheus'           --->定义job名字
 
    static_configs:
    - targets: ['localhost:9090','web01:9100','10.0.0.8:9100']    --->定义监控节点

#检测
[root@prometheus ~]# netstat -lntp | grep prometheus
tcp6       0      0 :::9090                 :::*                    LISTEN      8280/prometheus 

#浏览器访问10.0.0.72:9090

Prometheus监控MySQL和Linux主机结合Grafana出图

安装node_exporter

[root@promethues ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz

[root@prometheus ~]# tar xf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local
[root@prometheus ~]# cd /usr/lcoal

[root@prometheus /usr/local]# chown -R root.root node_exporter-1.2.2.linux-amd64
[root@prometheus /usr/local]# ln -s node_exporter-1.2.2.linux-amd64 /usr/local/node_exporter

#配置环境变量
[root@prometheus /usr/local]# vim /etc/profile.d/node_exporter.sh
export PATH=/usr/local/node_exporter:$PATH

[root@prometheus /usr/local]# source /etc/profile

# 启动(测试)
[root@promethues /usr/local]# node_exporter 

#添加至system管理
[root@prometheus /usr/local]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=This is prometheus node exporter
After=node_exporter.service
[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
ExecReload=/bin/kill -HUP 
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@prometheus /usr/local]# systemctl daemon-reload
[root@prometheus /usr/local]# systemctl start node_exporter

#检验
[root@prometheus /usr/local]# netstat -lntp | grep node_exporter
tcp6       0      0 :::9100                 :::*                    LISTEN      8384/nod_exporter

#将node_exporter服务加入prometheus
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
#在结尾添加
- job_name: "node"
    static_configs:
      - targets: ["172.16.1.72:9100"]

#被监控端主机同上操作,只需添加被监控端的主机IP
  - job_name: "node"
    static_configs:
      - targets: ["172.16.1.72:9100","172.16.1.7:9100"]


[root@prometheus ~]# systemctl restart prometheus

监控MySQL

[root@prometheus ~]# wget https://github.com/prometheus/mySQLd_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

[root@prometheus ~]# tar xf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local
[root@prometheus ~]# cd /usr/local

[root@prometheus /usr/local]# chown -R root.root mysqld_exporter-0.13.0.linux-amd64
[root@prometheus /usr/local]# ln -s mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysqld_exporter

#建立远程连接用户
[root@db01 ~]# mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysql-exporter'@'%' identified by '12345';
mysql> FLUSH PRIVILEGES;

#编写mysql连接配置文件
[root@prometheus /usr/local]# cat mysqld_exporter/my.cnf
[client]
host=172.16.1.51
user=msyql-exporter
password=12345

4、启动(测试)
[root@promethues /usr/local/mysqld_exporter]# ./mysqld_exporter  --config.my-cnf="my.cnf"

#加入systemd
[root@prometheus /usr/local]# vim /usr/lib/systemd/system/mysql_exporter.service
[Unit]
Description=Prometheus
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf --web.listen-address=:9104
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@prometheus /usr/local]# systemctl daemon-reload
[root@prometheus /usr/local]# systemctl start mysql_exporter
[root@prometheus /usr/local]# netstat -lntp | grep mysql
tcp6       0      0 :::9104                 :::*                    LISTEN      9298/mysqld_exporte 

#结尾添加
[root@prometheus /usr/local]# vim prometheus/prometheus.yml 
  - job_name: "mysqldb"
    static_configs:
      - targets: ["172.16.1.72:9104"]

[root@prometheus /usr/local]# systemctl restart prometheus

Prometheus监控MySQL和Linux主机结合Grafana出图

Prometheus监控MySQL和Linux主机结合Grafana出图

安装监控大屏(grafana)

[root@promethues ~]# wget https://dl.grafana.com/Enterprise/release/grafana-enterprise-8.1.2-1.x86_64.rpm

[root@promethues ~]# yum install grafana-enterprise-8.1.2-1.x86_64.rpm 

[root@promethues ~]# systemctl start grafana-server

#浏览器访问10.0.0.72:3000
默认密码:admin /  admin

图形化监控

Prometheus监控MySQL和Linux主机结合Grafana出图

Prometheus监控MySQL和Linux主机结合Grafana出图

Prometheus监控MySQL和Linux主机结合Grafana出图

Prometheus监控MySQL和Linux主机结合Grafana出图

Prometheus监控MySQL和Linux主机结合Grafana出图

Prometheus监控MySQL和Linux主机结合Grafana出图

脚本宝典总结

以上是脚本宝典为你收集整理的Prometheus监控MySQL和Linux主机结合Grafana出图全部内容,希望文章能够帮你解决Prometheus监控MySQL和Linux主机结合Grafana出图所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。