Prometheus Consul实现自动服务发现

Prometheus Consul实现自动服务发现

 

1、概述

Consul 是一个支持多数据中心分布式高可用的服务发现和配置共享的服务软件.
Consul 由 HashiCorp公司用Go语言开发, 基于Mozilla Public License 2.0的协议进行开源.
Consul 支持健康检查,并允许 HTTP 和 DNS 协议调用 API 存储键值对.
命令行超级好用的虚拟机管理软件 vgrant 也是 HashiCorp 公司开发的产品.
一致性协议采用 Raft 算法,用来保证服务的高可用. 使用 GOSSIP 协议管理成员和广播消息, 并且支持 ACL 访问控制.
docker run -d --name=qas-consul -p 8500:8500 consul

http://172.16.8.80:8500/ui
Prometheus Consul实现自动服务发现

vim prometheus.yml

scrape_configs:
- job_name: qas_discover
metrics_path: /metrics
scheme: http
consul_sd_configs:
- server: 172.16.8.80:8500
scheme: http
services:
- node_exporter
- cadvisor
- prometheus-node
tag_separator: '' relabel_configs:
- source_labels: ['__meta_consul_tags']
target_label: 'product'
- source_labels: ['__meta_consul_dc']
target_label: 'idc'
- source_labels: ['__meta_consul_service']
target_label: 'service'
- source_labels: ['job']
target_label: 'environment'
regex: '(.*)_discover'
replacement: '${1}'
curl -X PUT -d '{"id": "zabbix","name": "prometheus-node","address": "172.16.8.59","port":9100,"tags": ["node-exporter"],"checks": [{"http": "http://172.16.8.59:9100/","interval": "5s"}]}' http://172.16.8.80:8500/v1/agent/service/register
curl -X PUT -d '{"id": "habor","name": "prometheus-node","address": "172.16.8.55","port":9100,"tags": ["node-exporter"],"checks": [{"http": "http://172.16.8.55:9100/","interval": "5s"}]}' http://172.16.8.80:8500/v1/agent/service/register
curl -X PUT -d '{"id": "node","name": "harbor","address": "172.16.8.55","port":8080,"tags": [""],"checks": [{"http": "http://172.16.8.55:8080/","interval": "5s"}]}' http://172.16.8.80:8500/v1/agent/service/register

Prometheus Consul实现自动服务发现

上一篇:MongoDB的常用命令和增查改删


下一篇:K8s基于DNS的服务发现(转)