无法在普罗米修斯中推送指标

Unable to push metrics in prometheus

我正在尝试使用 PushgatewayPrometheus 中推送指标,但无法完成任务。 这是代码:

var  client = require('prom-client');
var gateway = new client.Pushgateway('http://localhost:9091');
gateway.pushAdd({ jobName: 'test', group : "production" }, function(err, resp, body){

});

普罗米修斯配置:

scrape_interval:     15s 
evaluation_interval: 15s 

external_labels:
      monitor: 'codelab-monitor'

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

scrape_configs:
  - job_name: 'example-random'
    scrape_interval: 5s

static_configs:
  - targets: ['localhost:8080', 'localhost:8081']
    labels:
      group: 'production'

  - targets: ['localhost:8082']
    labels:
      group: 'canary'

scrape_configs:

  - job_name: 'test '
    static_configs:
      - targets: ['localhost:9091']

您的 prometheus 配置存在一些问题 - 查看 Prometheus github 存储库 example and the docs 以供将来参考。

一个问题是您有多个 scrape_configs。 您的 Prometheus 配置中只能有一个 scrape_configs

另一个问题是每个作业只能有一个static_configs

其余主要是格式不正确

下面编辑的配置现在应该适合你了:

global:
  scrape_interval:     15s
  evaluation_interval: 15s

  external_labels:
    monitor: 'codelab-monitor'

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'production'
    static_configs:
      - targets: ['localhost:8080', 'localhost:8081']
        labels:
          group: 'production'

  - job_name: 'canary'
    static_configs:
      - targets: ['localhost:8082']
        labels:
          group: 'canary'

  - job_name: 'test'
    static_configs:
      - targets: ['localhost:9091']

同样重要的是要注意,来自 Pushgateway 的指标不会推送到 Prometheus。 Prometheus 是基于拉取的,将从 Pushgateway 本身拉取指标。 Pushgateway 收集的指标由临时和批处理作业推送给它。