Prometheus之基于consul发现
原创
©著作权归作者所有:来自51CTO博客作者小吉猫w的原创作品,请联系作者获取转载授权,否则将追究法律责任
一 配置Prometheus
1.1 配置prometheus.yml
~# cat prometheus.yml
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
static_configs:
- targets: ["192.168.174.103:9090"]
- job_name: 'k8s-masters'
consul_sd_configs: #consul服务发现
- server: "192.168.174.105:8500"
tags:
- "k8s-masters"
refresh_interval: 2m
# All nodes
- job_name: 'k8s-nodes'
consul_sd_configs: #consul服务发现
- server: "192.168.174.105:8500"
tags:
- "k8s-nodes"
refresh_interval: 2m
1.2 重启Prometheus服务
root@prometheus-01:~# systemctl restart prometheus
1.3 验证Prometheus web界面
二 向consul注册节点信息
2.1 注册k8s-master-01信息
2.1.1 定义k8s-master信息
root@consul-01:~# cat k8s-master.json
{
"id": "node_exporter-k8s-master-01",
"name": "k8s-master-01",
"address": "192.168.174.100",
"port": 9100,
"tags": ["k8s-masters"],
"checks": [{
"http": "http://192.168.174.100:9100/metrics",
"interval": "5s"
}]
}
2.1.2 注册k8s-master信息
root@consul-01:~# curl --request PUT --data @k8s-master.json http://192.168.174.103:8500/v1/agent/service/register
2.1.3 查看consul web界面
2.1.4 验证Prometheus web界面信息
2.1.5 反注册k8s-master信息
root@consul-01:~# curl -X PUT http://192.168.174.103:8500/v1/agent/service/deregister/node_exporter-k8s-master-01
2.1.6 验证Prometheus web界面信息