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
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