Prometheus_consul自動注冊


Consul是什么
Consul是一個服務管理軟件。支持多數據中心下,分布式高可用的,服務發現和配置共享。用來保證服務的高可用,(本文章搭建一個單節點consul環境與prometheus環境實現自動注冊功能);

二進制包安裝,安裝方法:
環境准備

1:下載安裝包,最新版本根據官方為准;(consul官方下載地址:https://releases.hashicorp.com/consul)

cd /usr/local/
wget https://releases.hashicorp.com/consul/0.8.1/consul_0.8.1_linux_amd64.zip

 

 

 

2:解壓縮 consul_0.8.1_linux_amd64.zip

unzip consul_0.8.1_linux_amd64.zip &&  mv consul_0.8.1_linux_amd64 consul

 

 

3:啟動consul服務器

./consul agent -dev -client 0.0.0.0 -ui

 

 

4:prometheus與consul結合實現自動發現配置

# grep -v "^#" 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.
# scrape_timeout is set to the global default (10s).

remote_write:
- url: "http://192.168.152.137:9201/write"
remote_read:
- url: "http://192.168.152.137:9201/read"

alerting:
alertmanagers:
- static_configs:
- targets: ['192.168.152.137:9093']
# - ['localhost:9093']

rule_files:
- "/opt/prometheus-2.15.1.linux-amd64/rules/cpu_usage.yml"
- "/opt/prometheus-2.15.1.linux-amd64/rules/disk.yml"
- "/etc/prometheus/promgen.rule.yml"
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ['localhost:9090','192.168.152.180:9100','192.168.152.114:9100','192.168.151.41:9100','192.168.152.106:9100']

- job_name: 'consul' #prometheus與consul配置段
consul_sd_configs:
- server: '192.168.152.186:8500'
services: [ ]

- job_name: 'ping'
scrape_interval: 1m
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['192.168.152.106','192.168.152.114']
labels:
type: '虛擬機'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.152.133:9115

- job_name: pushgateway
static_configs:
- targets: ['192.168.152.133:9091']

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

客戶端通過HTTP API注冊服務

注冊服務:curl -X PUT -d '{"id": "node-exporter","name": "node-exporter-192.168.152.106","address": "192.168.152.106","port": 9100,"tags": ["test"],"checks": [{"http": "http://192.168.152.106:9100/metrics", "interval": "5s"}]}' http://192.168.152.186:8500/v1/agent/service/register
注銷服務:curl -X PUT http://192.168.152.186:8500/v1/agent/service/deregister/node-exporter

 

 

 

 

 

通過頁面查看是否注冊成功

http://192.168.152.137:9090/targets


免責聲明!

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



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