Reputation: 23
I am trying to push metrics in Prometheus
using Pushgateway
but not able to complete the task.
This is the code:
var client = require('prom-client');
var gateway = new client.Pushgateway('http://localhost:9091');
gateway.pushAdd({ jobName: 'test', group : "production" }, function(err, resp, body){
});
Prometheus config:
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']
Upvotes: 0
Views: 3754
Reputation: 686
Try to change the URL from http to https and try as follows:
var client = require('prom-client');
var gateway = new client.Pushgateway('https://localhost:9091');
gateway.pushAdd({ jobName: 'test', group : "production" }, function(err,
resp, body){
});
Upvotes: 0
Reputation: 3579
You've a few problems with your prometheus config - check out the Prometheus github repo example and the docs for future reference.
One issue is that you have multiple scrape_configs
.
You can only have one scrape_configs
in your configuration for Prometheus.
Another issue is that each job can only have one static_configs
.
The rest is mainly due to incorrect formatting.
The edited config below should work for you now:
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']
It's also important to note that the metrics from the Pushgateway are not pushed to Prometheus. Prometheus is pull based and will pull the metrics from the Pushgateway itself. The metrics the Pushgateway collects are pushed to it by ephemeral and batch jobs.
Upvotes: 1