Prometheus动态发现监控targets —— 基于文件的服务发现
为实现Prometheus监控目标配置的动态加载,可通过基于文件的服务发现完成配置
Kafka服务的自动发现配置
Prometheus官方exporter
链接:
https://github.com/danielqsj/kafka_exporter
在kafka
节点上运行docker
版kafka-exporter
docker run -d -p 9308:9308 danielqsj/kafka-exporter --kafka.server=kafka:9092
创建targets
文件夹:
mkdir -p /etc/promethues/targets/kafka
创建组件targets
的yml
文件:
vim /etc/promethues/targets/kafka
- targets:
- "kafka1:9308"
- "kafka2:9308"
- "kafka3:9308"
修改/etc/prometheus/prometheus.yml
:
...
- job_name: 'kafka'
file_sd_configs:
- files:
- targets/kafka/*.yml
refresh_interval: 5m
MySQL服务的自动发现配置
Prometheus官方exporter
链接:
https://github.com/prometheus/mysqld_exporter
在mysql
节点上运行docker
版mysql-exporter
,并对应双实例
- 单实例
docker run -d -p 9104:9104 -e DATA_SOURCE_NAME="exporter:pwd@(mysql-1:3306)/" prom/mysqld-exporter
- 双实例
docker run -d -p 9105:9104 -e DATA_SOURCE_NAME="exporter:pwd@(mysql-1:13306)/" prom/mysqld-exporter
创建targets
文件夹:
mkdir -p /etc/promethues/targets/mysql
创建组件targets
的yml
文件:
- targets:
- "mysql-1:9104"
- "mysql-1:9105"
修改/etc/prometheus/prometheus.yml
:
- job_name: 'mysql'
file_sd_configs:
- files:
- targets/mysql/*.yml
refresh_interval: 5m
Redis Cluster服务的自动发现配置
Prometheus官方exporter
链接:
https://github.com/oliver006/redis_exporter
在redis
节点上运行docker
版redis-exporter
docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter
创建targets
文件夹:
mkdir -p /etc/promethues/targets/redis
创建组件targets
的yml
文件:
- targets:
- redis://redis-1:16379
- redis://redis-2:16379
- redis://redis-3:16379
修改/etc/prometheus/prometheus.yml
:
...
- job_name: 'redis_exporter_targets'
file_sd_configs:
- files:
- targets/redis/redis.yml
metrics_path: /scrape
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: redis_exporter:9121
## config for scraping the exporter itself
- job_name: 'redis_exporter'
static_configs:
- targets:
- redis_exporter:9121
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/25/prometheus-dynamic-discovery-monitoring-targets-file-based-service-discovery/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论