prom-client icon indicating copy to clipboard operation
prom-client copied to clipboard

Pushgateway metrics

Open assada opened this issue 4 years ago • 4 comments

const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
const Registry = client.Registry;
const register = new Registry();
collectDefaultMetrics({ register: register, prefix: 'prefix_' }); //ok, but without prefix

const test = new client.Counter({
    name: 'prefix_test',
    help: 'prefix_test',
    registers: [register]
});
register.registerMetric(test);
test.inc(10); //not ok.

let gateway = new client.Pushgateway('http://127.0.0.1:9091', [], register);

gateway.push({ jobName: 'test' }, function (err, resp, body) {});

I am trying to use Pushgateway. Default metrics pushed successfully but without prefix. But my test counter doesn't push to gateway. Maybe I missed something? Really lacking a full-featured example with Pushgateway

assada avatar Apr 08 '20 12:04 assada

Is your node process ending before sending request to gateway?

In my case, I was doing

gateway.push({ jobName: 'test' }, function (err, resp, body) {});
process.exit(0);

I end up wrapping push inside Promise and wait until callback resolves.

    await new Promise((resolve, reject) => {
      gateway.push({ jobName: 'test' }, function (err, resp, body) {
        if (err) {
          console.log(`Error: ${err}`);
          reject(err);
        } else {
          console.log(`Success: ${body}`);
          console.log(`Response: ${resp}`);
          resolve(resp);
        }
      });
    });
    process.exit(0);

xcao65 avatar Apr 09 '20 07:04 xcao65

no, my process newer ending. All default metrics sends good(but still without prefix).

assada avatar Apr 09 '20 11:04 assada

This looks like a typo: http://prom/:9091

It should be: 'http://prom:9091'

nhartner avatar Apr 21 '20 23:04 nhartner

@nhartner no, in real code i am use another host. Default metrics - works fine

assada avatar Apr 22 '20 15:04 assada