Custom prom-client metrics always shows 0 value

186 Views Asked by At

I am creating custom metrics and when I trigger /metric endpoint it always shows 0 as output even its enters inside if condition.

//This is my metrics.ts file
import express from 'express';
import client from 'prom-client';
const register = new client.Registry();
client.collectDefaultMetrics({ register });
export const myCounterData = new client.Counter({
  name: 'myCounter_data',
  help: 'Its my counter test data',
});
register.registerMetric(myCounterData);
export const router = express.Router();
router.get('/', async (req, res) => {
  res.setHeader('Content-Type', register.contentType);
  res.send(await register.metrics());
});

//This is my worker.ts file
import { myCounterData } from './myproj/myapi/routes/metrics';
const data = 'Success'

if (data !== null) {
  console.log("inside If")
  myCounterData.inc();
}
0

There are 0 best solutions below