提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
本文主要将prometheus和consul 结合起来使用,通过conusl 注册服务至prometheus,实现服务统一注册,统一报警管理等。
整个架构思路consul+prometheus+alertmanager ,consul通过check检测服务状态,然后暴露给prometheus,prometheus通过alert规则,通知alertmanager,接着邮件通知管理人员。
在各服务器上安装node_expoert,然后将node配置到consul的hcl服务文件中,进行服务注册,当然也可以http api发现。然后在prometheus主yml文件中配置consul_sd_configs对服务进行发现。
架构如下
1. prometheus&consul部署
-
安装node_exporter
-
安装consul(单机)
-
二进制部署
官网找到对应版本下载下来
Install | Consul | HashiCorp Developer
解压到指定目录
unzip -o consul_1.20.1_linux_amd64.zip
查看版本
consul --version
启动服务
consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=node1 -bind=127.0.0.1
-
docker部署
[root@flink-worker02 monitor]# cat docker-compose.yml version: '3.8' networks: monitor: driver: bridge services: consul: image: consul:latest container_name: "consul" restart: always # user: root ports: - "18500:8500" volumes: - ./consul/data/:/consul/data/ command: [agent,-server,-ui,-client,"0.0.0.0",-bind,"127.0.0.1",-bootstrap-expect=1] networks: - monitor
-
-
配置prometheus.yml
# 增加一个job - job_name: 'consul-exporter' consul_sd_configs: - server: '192.99.17.20:18500' services: ["node-exporter","node_exporter"] relabel_configs: - source_labels: [__meta_consul_tags] regex: .* action: keep - regex: __meta_consul_service_metadata_(.+) action: labelmap
-
调用API接口进行注册
# 注册接口 curl -X PUT -d @testjson.json http://IP:port/v1/agent/service/register
vim testjson.json
编辑好testjson.json文件,可以一次注册多个exporter
{ "ID": "node_exporter-192.168.105.64-49100", "Name": "node_exporter", "Address": "192.168.105.64", "Port": 49100, "Meta": { "exporterType": "node_exporter", "agentVersion": "1.6.1", "hostUuid":"019a8ac1b3c9967d45bae8e3fdab26b6" }, "Tags": [ "node_exporter" ], "checks": [ { "http": "http://192.168.105.64:49100/metrics", "interval": "30s", "tls_skip_verify": true, "header": { "Authorization": ["Basic YWRtaW46TGh3eDEyMzQ1NiM="] } } ] }
-
注册成功
✅为注册成功
2. 展示
prometheus页面也可以顺利采集到
grafana查看
模板地址
标签:node,基于,exporter,http,consul,prometheus,注册 From: https://blog.csdn.net/youmiqianyue/article/details/144392215