首页 > 解决方案 > Push aggregated metrics to the Prometheus Pushgateway from clustered Node JS

问题描述

I've ran my node apps in a cluster with Prometheus client implemented. And I've mutated the metrics (for testing purpose) so I've got these result:

# HELP otp_generator_generate_failures A counter counts the number of generate OTP fails.
# TYPE otp_generator_generate_failures counter
otp_generator_generate_failures{priority="high"} 794

# HELP otp_generator_verify_failures A counter counts the number of verify OTP fails.
# TYPE otp_generator_verify_failures counter
otp_generator_verify_failures{priority="high"} 802

# HELP smsblast_failures A counter counts the number of SMS delivery fails.
# TYPE smsblast_failures counter
smsblast_failures{priority="high"} 831

# HELP send_success_calls A counter counts the number of send API success calls.
# TYPE send_success_calls counter
send_success_calls{priority="low"} 847

# HELP send_failure_calls A counter counts the number of send API failure calls.
# TYPE send_failure_calls counter
send_failure_calls{priority="high"} 884

# HELP verify_success_calls A counter counts the number of verify API success calls.
# TYPE verify_success_calls counter
verify_success_calls{priority="low"} 839

# HELP verify_failure_calls A counter counts the number of verify API failure calls.
# TYPE verify_failure_calls counter
verify_failure_calls{priority="high"} 840

FYI: I have adopted the given example from: https://github.com/siimon/prom-client/blob/master/example/cluster.js

Then, I pushed the metrics and everything work fine at the process. But, when I checked the gateway portal, it gives different result from those metrics above.

The one that becomes my opinion is the pushed metrics came from single instance instead of aggregated metrics from few instances running. Isn't it?

So, has anyone ever solved this problem?

Oh, this is my push code:

const { Pushgateway, register } = require('prom-client')
const promPg = new Pushgateway(
  config.get('prometheus.pushgateway'),
  {
    timeout: 5000
  },
  register
)

promPg.push({ jobName: 'sms-otp-middleware' }, (err, resp, body) => {
  console.log(`Error: ${err}`)
  console.log(`Body: ${body}`)
  console.log(`Response status: ${resp.statusCode}`)
  res.status(200).send('metrics_pushed')
})

标签: node.jsprometheusprometheus-pushgateway

解决方案


推荐阅读