Prometheus基於consul的服務發現


Prometheus添加被監控端支持兩種方式:

•靜態配置

•服務發現

支持服務發現的來源:

•consul_sd_configs

•openstack_sd_configs

•file_sd_configs

•kubernetes_sd_configs

基於consul的架構圖

  1. exporter是提供者,向consul注冊,提供ip、端口、metrics等信息;
  2. prometheus是消費者:

 Docker部署Consul:

docker run --name consul -d -p 8500:8500 consul

向Consul注冊服務,http://192.168.121.132:8500/v1/agent/service/register是api接口地址:

curl -X PUT -d '{"id": "k8s-2","name": "Linux","address": "192.168.121.132","port": 9100,"tags": ["service"],"checks": [{"http": "http://192.168.121.132:9100","interval": "5s"}]}' http://192.168.121.132:8500/v1/agent/service/register

普羅米修斯配置:

- job_name: 'consul_sd'
basic_auth:
username: prometheus
password: 123456
consul_sd_configs:
- server: 192.168.121.132:8500
services: ['Linux']

檢查語法:

root@k8s-1 prometheus]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 0 rule files found

重新加載:

[root@k8s-1 prometheus]# ps -ef|grep prom
root 776 1 0 10:43 ? 00:00:27 /opt/monitor/prometheus/prometheus --config.file=/opt/monitor/prometheus/prometheus.yml
root 1753 1556 0 12:03 pts/0 00:00:00 grep --color=auto prom
[root@k8s-1 prometheus]# kill -HUP 776

查看網頁,已經能看到consul發現的主機:

增加一台被監控端:

只需要再向Consul注冊服務,http://192.168.121.132:8500/v1/agent/service/register是api接口地址:

curl -X PUT -d '{"id": "k8s-3","name": "Linux","address": "192.168.121.133","port": 9100,"tags": ["service"],"checks": [{"http": "http://192.168.121.133:9100","interval": "5s"}]}' http://192.168.121.132:8500/v1/agent/service/register

 看到兩台被監控機器:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM