prometheus+consul+node_exporter
修改prometheus.yml
global:
alerting:
alertmanagers:
- static_configs:
- targets:
rule_files:
scrape_configs:
# - job_name: 'prometheus'是监听prometheus服务本身
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# job_name: 'node_exporter'是按固定IP:PORT的方式监听微服务
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
# job_name: 'overwritten-default'就是一个监听consul的任务,在consul_sd_configs下,server是consul服务器的访问地址,
- job_name: 'consul'
consul_sd_configs:
# - server: 'localhost:8500'
- server: '192.168.0.25:8500'
# consul里name的名称 或者curl注册的名称 services是微服务名的数组,如果什么都不填,则默认全选
services: ['test']
#relabel_configs:
# - source_labels: [__meta_consul_tags]
# regex: .*test.*
# action: keep
curl -X PUT -d ‘{“id”: “test-001”,“name”: “test”,“address”: “192.168.0.33”,“port”: 9100,“tags”: [“test”],“checks”: [{“http”: “http://192.168.0.33:9100/”,“interval”: “5s”}]}’ http://localhost:8500/v1/agent/service/register
curl -X PUT -d '{"id": "sentry","name": "prod","address": "192.168.0.33","port": 9100,"tags": ["prod"],"checks": [{"http": "http://192.168.0.336:9100/","interval": "5s"}]}' http://localhost:8500/v1/agent/service/register
查看prometheus是否接受到数据
http://ip:9090/targets
查看grafana视图
删除
curl -X PUT http://localhost:8500/v1/agent/service/deregister/${id}
curl -X PUT http://localhost:8500/v1/agent/service/deregister/test-001