码迷,mamicode.com
首页 > 其他好文 > 详细

Consul与Prometheus [1]

时间:2020-07-03 12:53:47      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:tag   col   default   实现   eof   intro   register   ref   自定义标签   

环境准备

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 数据 等详情见:

Prometheus 通过 consul 实现自动服务发现

Consul与Prometheus [1]

标签:tag   col   default   实现   eof   intro   register   ref   自定义标签   

原文地址:https://www.cnblogs.com/3rdworld/p/13229473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!