普罗米修斯上的多个目标
Posted
技术标签:
【中文标题】普罗米修斯上的多个目标【英文标题】:Multiple Targets on prometheus 【发布时间】:2019-04-17 03:42:14 【问题描述】:我已经在Centos上配置了prometheus,版本详情如下。
prometheus-2.5.0.linux-386
我在 prometheus.yml 配置文件中添加了两个目标,所有服务器节点导出器都在运行。配置如下,
scrape_configs:
- job_name: "node"
scrape_interval: "15s"
target_groups:
- targets: ['192.168.x.x:9100','192.168.x.y:9100']
但在 prometheus UI Tragets 中仅显示单个节点,其他未显示。如果我删除一个节点,则显示现有节点。如何监控多个节点。但在 Grafana Dashboard 中显示 Multiple Series Error。
【问题讨论】:
【参考方案1】:我已经在 prometheus.yml 上配置了这个配置
# my global config
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).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'node'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.x.x:9100']
- targets: ['192.168.x.y:9100']
- targets: ['192.168.x.z:9100']
【讨论】:
【参考方案2】:供以后参考,以下配置在prometheus V2.3.1版本上运行良好。
-
prometheus yml 配置:
- job_name: 'etcd-stats'
static_configs:
- targets: ['10.18.210.2:2379','10.18.210.199:2379','10.18.210.16:2379']
.......
-
Web UI 目标
【讨论】:
【参考方案3】:您可以在 prometheus 中抓取多个目标。试试这个方法:
global:
scrape_interval: 15s # Scrape targets every 15 seconds
scrape_timeout: 15s # Timeout after 15 seconds
# Attach the label monitor=dev-monitor to all scraped time series scraped by this server
labels:
monitor: 'dev-monitor'
scrape_configs:
- job_name: "job-name"
scrape_interval: 10s # Override the default global interval for this job
scrape_timeout: 10s # Override the default global timeout for this job
static_configs:
# First group of scrape targets
- targets: ['localhost:9100', 'localhost:9101']
labels:
group: 'first-group'
# Second group of scrape targets
- targets: ['localhost:9200', 'localhost:9201']
labels:
group: 'second-group'
希望这会有所帮助。
【讨论】:
新版本的 Prometheus 使用“static_configs”而不是“target_groups”。另一个答案是最新版本。以上是关于普罗米修斯上的多个目标的主要内容,如果未能解决你的问题,请参考以下文章