介绍
Prometheus 提供了服务发现机制,即通过自动化的机制来检测、分类和识别新的和变更的目标。一般有这几种类型:静态、基于文件、基于API、基于DNS。
基于文件的服务发现
基于文件的方式用的配置是 file_sd_configs,它用于读取一组包含零个或多个列表的文件,这些文件可以是 YAML 或 JSON 格式,包含着定义的目标列表。
[root@devops ~]# vim /usr/local/prometheus/prometheus.yml - job_name: 'node' file_sd_configs: - files: - targets/*.json - targets/*.yaml refresh_interval: 10s
JSON
[root@iZ8vb623n6mbyx9d66w0a9Z ~]# mkdir /usr/local/prometheus/targets [root@iZ8vb623n6mbyx9d66w0a9Z ~]# cd /usr/local/prometheus/targets/ [root@iZ8vb623n6mbyx9d66w0a9Z targets]# vim node.json [{ "targets": [ "10.1.0.157:9100", "10.1.0.152:9100" ], "labels": { "role": "devops" } }]
YAML
[root@iZ8vb623n6mbyx9d66w0a9Z targets]# vim demo.yaml - targets: - "10.1.0.157:9100" - "10.1.0.152:9100" labels: role: demo
检查配置文件有没有错
[root@iZ8vb623n6mbyx9d66w0a9Z targets]# cd .. [root@iZ8vb623n6mbyx9d66w0a9Z prometheus]# pwd /usr/local/prometheus [root@iZ8vb623n6mbyx9d66w0a9Z prometheus]# ./promtool check config prometheus.yml Checking prometheus.yml SUCCESS: prometheus.yml is valid prometheus config file syntax
此处为隐藏的内容
注册登录后,方可查看
登录
此处为隐藏的内容
注册登录后,方可查看
登录
继续阅读
评论