导语:需要排查部分出问题的私有化环境。直接上一个docker的node_exporter + prometheus + grafana 最方便。
所用到的安装包在最下面的云盘。
解压安装自定义node_exporter
# 这个abc的包名可以忽略
tar zxvf abc.tgz
cd abc
cp node_exporter /usr/local/
cat <<EOF >/usr/lib/systemd/system/node_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter --collector.systemd --collector.systemd.unit-whitelist=(docker|kubelet|kube-proxy|flanneld).service
[Install]
WantedBy=multi-user.target
EOF
#刷新systemctl、设置开机自启动并启动node_exporter
systemctl daemon-reload
systemctl enable node_exporter
systemctl restart node_exporter
监控安装
mkdir -p /data1/prometheus
#cat > /data1/prometheus/prometheus.yml << EOF
#global:
# scrape_interval: 15s
# evaluation_interval: 15s
#rule_files:
# - "rules/node.rules"
#scrape_configs:
# - job_name: 'Prometheus'
# scrape_interval: 5s
# static_configs:
# - targets: ['192.168.10.84:9090']
# - job_name: 'Linux'
# static_configs:
# - targets: ['192.168.10.84:19100','192.168.10.84:19100']
#EOF
echo "
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- "rules/node.rules"
scrape_configs:
- job_name: 'Prometheus'
scrape_interval: 5s
static_configs:
- targets: ['192.168.10.84:9090']
- job_name: 'Linux'
static_configs:
- targets: ['192.168.10.84:19100','192.168.10.84:19100']
"> /data1/prometheus/prometheus.yml
启动prometheus
docker run -d \
--name=prometheus \
-p 9090:9090 \
-v /data1/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
启动grafana
#创建目录,拷贝配置文件,并授权,否则会报错
mkdir -p /data1/grafana/grafana-etc && mkdir -p /data1/grafana/grafana
docker run -d --name=grafana -p 3000:3000 grafana/grafana
# 如果有需要修改配置文件可以执行这一步
docker cp grafana:/etc/grafana/grafana.ini /data1/grafana/grafana-etc
chmod 777 /data1/grafana && chmod 777 /data1/grafana/grafana
# http://192.168.10.82:3000/datasources/new admin/admin
curl -X PUT -H "Content-Type: application/json" -d '{"oldPassword": "admin","newPassword": "deepwise","confirmNew": "deepwise"}' http://admin:admin@192.168.10.84:3000/api/user/password
# 修改grafana密码之后需要重启生效
docker restart grafana
# 申请并获取api key
curl -X POST -H "Content-Type: application/json" -d '{"name":"apikeycurl", "role": "Admin"}' http://admin:deepwise@192.168.10.84:3000/api/auth/keys
# 创建数据源
curl -X POST --retry 5 -H "Content-Type: application/json" -d '{"name":"prometheus_datasource","type":"prometheus","url":"http://192.168.10.84:9090","access":"proxy","basicAuth":false}' "http://admin:deepwise@192.168.10.84:3000/api/datasources"
curl -H "Content-Type: application/json" -X POST -d @/data1/docker_monitor/1.json "http://admin:deepwise@192.168.10.84:3000/api/dashboards/db"
grafana创建dashboard需要一个固定的格式:
替换对应的panels和templating即可
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H7VMIVIx-1675133872470)(null)]
如果无法访问 grafana报proxy错误 需要更新浏览器版本
对应包下载地址
链接: https://pan.baidu.com/s/1G1lFfWTxlLifuwuG6L9-rA?pwd=hfkt 提取码: hfkt
–来自百度网盘超级会员v6的分享
参考
https://blog.51cto.com/u_5650011/5388579