Consul与Prometheus [1]
Posted 3rdworld
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Consul与Prometheus [1]相关的知识,希望对你有一定的参考价值。
环境准备
192.168.122.211 |
Consul Prometheus |
---|---|
192.168.122.212 |
node_export |
服务安装
Consul
# consul
docker run --name consul -d -p 8500:8500 consul
prometheus 配置
useradd —M -s /sbin/nologin prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.19.2/prometheus-2.19.2.linux-amd64.tar.gz -O /opt/prometheus
tar -xf prometheus-2.19.2.linux-amd64.tar.gz -O /opt
mv prometheus-2.19.2.linux-amd64/ prometheus
chown -R prometheus.prometheus /opt/prometheus
# 数据目录 SSD
mkdir -pv /opt/prometheus/data
cat << EOF > ./prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target
[Service]
User=prometheus
Restart=on-failure
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl link /opt/node_exporter/prometheus.service
node_exporter 配置
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz -O /opt/prometheus
mv node_exporter-1.0.1.linux-amd64 node_exporter
chown -R prometheus.prometheus /opt/prometheus
cat << EOF > ./node_exporter.service
#Prometheus Node Exporter Upstart script
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
[Install]
WantedBy=default.target
EOF
systemctl link /opt/node_exporter/node_exporter.service
服务启动
systemctl daemon-reload
systemctl start prometheus
systemctl status prometheus
systemctl enable node_exporter
systemctl start node_exporter
配置Prometheus自动发现
Node_exporter 注册到consul
#1 / 注册API
curl -X PUT -d ‘{"id": "node-exporter","name": "node-exporter-192.168.122.212","address": "192.168.122.212","port": 9100,"tags": ["test"],"checks": [{"http": "http://192.168.122.212:9100/metrics", "interval": "5s"}]}‘ http://192.168.122.211/v1/agent/service/register
#2 / 注销API 注销上边添加的 node-exporter服务
curl -X PUT http://192.168.122.211:8500/v1/agent/service/deregister/node-exporter
编辑prometheus.yaml
- job_name: ‘consul‘
consul_sd_configs:
- server: ‘192.168.112.212:8500‘
services: []
consul_sd_configs
来配置使用 Consul 服务发现类型,server
为 Consul 的服务地址
说明
后续还会有很多问题如:
relabel_configs
来进行匹配区分、自定义标签信息添加到 Meta Data 数据 等详情见:
以上是关于Consul与Prometheus [1]的主要内容,如果未能解决你的问题,请参考以下文章
Prometheus + consul + grafana 监控体系搭建1
Prometheus + Consul:为每个 Consul 服务器创建 2 个目标(复制目标)
Centos7.5 Prometheus2.5配置和基于Consul1.2.4的服务发现