prometheus file_sd_config 基于文件的服务发现
所属分类 prometheus
浏览量 483
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config
File-based service discovery provides a more generic way to configure static targets and serves as an interface to plug in custom service discovery mechanisms.
It reads a set of files containing a list of zero or more static_config s.
Changes to all defined files are detected via disk watches and applied immediately.
Files may be provided in YAML or JSON format.
Only changes resulting in well-formed target groups are applied.
[
{
"targets": [ "host", ... ],
"labels": {
"labelname": "labelvalue", ...
}
},
...
]
- targets:
[ - 'host' ]
labels:
[ labelname: labelvalue ... ]
# Patterns for files from which target groups are extracted.
files:
[ - filename_pattern ... ]
# Refresh interval to re-read the files.
[ refresh_interval: duration | default = 5m ]
filename_pattern may be a path ending in .json, .yml or .yaml
The last path segment may contain a single * that matches any character sequence, e.g. my/path/tg_*.json.
./promtool check config prometheus.yml
- job_name: 'nodes'
file_sd_configs:
- files:
- targets/nodes-*.yaml
refresh_interval: 2m
scrape_interval: 15s
- job_name: 'elasticsearch'
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: "/metrics"
file_sd_configs:
- files:
- targets/elasticsearch.yml
refresh_interval: 2m
- job_name: 'kafka'
scrape_interval: 15s
scrape_timeout: 10s
file_sd_configs:
- files:
- targets/kafka.yml
refresh_interval: 2m
- job_name: 'nacos'
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: "/nacos/actuator/prometheus"
file_sd_configs:
- files:
- targets/nacos.yml
refresh_interval: 2m
elasticsearch.yml
- targets:
- 192.168.1.10:9114
- 192.168.1.11:9114
- 192.168.1.12:9114
labels:
app: elasticsearch
elasticsearch_cluster_health_up
elasticsearch_cluster_health_up{app="elasticsearch",instance="192.168.1.10:9114",job="elasticsearch"} 1
elasticsearch_cluster_health_up{app="elasticsearch",instance="192.168.1.11:9114",job="elasticsearch"} 1
elasticsearch_cluster_health_up{app="elasticsearch",instance="192.168.1.12:9114",job="elasticsearch"} 1
app="elasticsearch"
job="elasticsearch"
- job_name: 'file_sd_demo'
# metrics_path: '/actuator/prometheus'
file_sd_configs:
- files:
- targets/app-*.json
refresh_interval: 5s
app-1.json
[{"targets":["codefun007.xyz"],"labels":{"app":"web1"}}]
app-2.json
[{"targets":["codefun007.xyz"],"labels":{"app":"web2"}}]
app-3.json
[{"targets":["codefun007.xyz"],"labels":{"app":"web3","job":"web3"}}]
注意 json 数组 格式
labels 的标签会覆盖 外面的配置
total_pv
total_pv{app="web1", instance="codefun007.xyz:80", job="file_sd_demo"} 3884967
total_pv{app="web2", instance="codefun007.xyz:80", job="file_sd_demo"} 3884966
total_pv{app="web3", instance="codefun007.xyz:80", job="web3"} 3884967
上一篇
下一篇
RabbitMQ 消息发送和消费过程
Flink JobManager与TaskManage 运行架构
springboot 接口 post 报错 Cannot generate variable name for non-typed Collection parameter type
MAC 安装 rabbitmq
rabbitmq prometheus插件 和 rabbitmq-exporter
rabbitmq prometheus 插件 指标说明