Prometheus基于consul的服务发现机制

2020-06-09  本文已影响0人  印随2018

一、启动注册中心

./consul agent -dev  -client 0.0.0.0 -ui

二、创建配置文件

mkdir -p /etc/promethues

cat > /etc/promethues/promethues.xml <<EOF
global:
  scrape_interval:     15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'kong-custom-apis'
    consul_sd_configs:
      - server: '10.206.44.112:8500'
        services: ['kong-custom-apis']
    relabel_configs:
      - source_labels: [__address__]
        regex: (.*)
        target_label: instance
        replacement: kong-custom-apis-${1}

EOF

三、注册服务

curl -X PUT -d '{
    "id": "kong-custom-apis-5c9744f47-zg6vn",
    "name": "kong-custom-apis",
    "address": "10.206.180.74",
    "port": 8001,
    "tags": ["cluster-kong-custom-apis"],
    "checks": [{"http": "http://10.206.180.74:8001/status","interval": "5s"}]}' \
    http://10.206.44.112:8500/v1/agent/service/register

四、启动Prometheus

pkill prometheus
./prometheus \
  --config.file=/etc/promethues/promethues.xml \
  --storage.tsdb.retention.time=15d \
  --web.enable-admin-api  >> /var/log/prometheus.log &
上一篇下一篇

猜你喜欢

热点阅读