运维监控grafana+prometheus+node_exporter(or mysqld_exporter)
grafana+prometheus+node_exporter
前言
node_exporter在各个工作节点用程序本地运行,grafana和prometheus只需一个非工作节点通过网络访问这些node_exporter,所以grafana和prometheus可以用容器部署,方便。
参考文章
grafana+Prometheus(普罗米修斯)实现监控功能
保姆级教程--容器化部署prometheusd监控系统(yaml文件、docker命令均有详细解释、大白话描述服务作用、适合小白)_prometheus容器化部署-CSDN博客
Node Exporter 简介
下载
Prometheus:
exe:
https://github.com/prometheus/prometheus/releases
docker:
https://hub.docker.com/r/prom/prometheus/
node_exporter
https://github.com/prometheus/node_exporter/releases/
grafana
https://grafana.com/grafana/download?platform=docker
xx_exporter负责信息抓取(保存本地),Prometheus负责搜集(通过网络),grafana负责可视化
这个expoter最好直接运行在节点上,不要用容器运行。
node_expoter下载地址:Releases · prometheus/node_exporter · GitHub
启动
node_expoter
推荐直接运行可执行程序:
tar -xf node_exporter-1.8.2.linux-amd64.tar.gz
cd node_exporter-1.8.2.linux-amd64/
mkdir ../node_metrics
pwd
./node_exporter --web.listen-address=":9096" --web.telemetry-path="/home/xxx/tmp/node_metrics" &
ps aux | grep node_exporter
也可以容器运行(未测试其中存储映射):
docker run -d -p 9100:9100 --restart=always --name node-exporter -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter:latest
浏览器测试:
prometheus
推荐容器运行:
docker run -d --name prometheus --privileged=true -u root --restart=always -p 9090:9090 -v D:\rd\yw\prometheus\config:/etc/prometheus -v D:\rd\yw\prometheus\data:/prometheus -v D:\rd\yw\prometheus\rules:/usr/local/prometheus/rules prom/prometheus:latest --storage.tsdb.retention.time=100d --config.file=/etc/prometheus/prometheus.yml
prometheus.yml示例:
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
alerting:
alertmanagers:
- static_configs:
- targets: ['15.66.11.13:9093']
rule_files:
- "/usr/local/prometheus/rules/*.yml"
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "soc"
static_configs:
- targets: ["15.66.6.180:9096"]
metrics_path: "/node_metrics"
- job_name: "compile server"
static_configs:
- targets: ["15.66.2.101:9096","15.66.2.102:9096"]
metrics_path: "/home/xiaojun.zhang/tmp/node_metrics"
- job_name: "work test"
static_configs:
- targets: ["15.66.11.13:9100"]
浏览器测试:
grafana
推荐容器安装:
Linux:
docker run -d -p 3000:3000 --name grafana --restart=always -v /opt/grafana/data:/var/lib/grafana -v /etc/localtime:/etc/localtime grafana/grafana:latest
Windows(Windows上docker容器默认就与Window时间一致):
docker run -d -p 3000:3000 --name grafana -v D:\rd\yw\grafana\data:/var/lib/grafana grafana/grafana:latest
也可以用这个镜像(暂时不知区别)
grafana/grafana-enterprise:latest
注意:
如果是容器启动grafana,则配置Prometheus地址时不能用localhost,因为会从容器内尝试连接,要用主机分配的IP地址比如192.168.xx.xx
否则出现如下报错:
浏览器测试:
拉到最下面:
输入仪表盘ID,点击load
点击import
画面立即出现在眼前:
查找仪表盘:
访问Grafana: The open observability platform | Grafana Labs
搜索dashboard
比如再倒入一个1860