jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
303 stars 67 forks source link

How to create a custom metric that gets measured on all paths? #69

Closed vamsioyo closed 3 years ago

vamsioyo commented 3 years ago

For suppose I created a metrics like this:

const counter = new promClient.Counter({ name: 'http_requests_total', help: 'no.of http requests received ont the page', labelNames: ['method', 'path'], }); Now How to get this metric measured on every route?

@disjunction Pls help

disjunction commented 3 years ago

The purpose of this module is to create such a metric for you. You don't need to create the metric yourself, but instead use the module as described in the README (e.g. use includePath option) and get the counts from the histogram. The histogram implicitly includes the count - http_request_duration_seconds_count.

vamsioyo commented 3 years ago

@disjunction Yeah I understand the Readme. I was just giving an example above.

My actual doubt was... The module actually creates http_request_duration_second implicitly and its get's measured on all paths, which is great!!!

But I am curious to know .. Whether Can I create some other metric apart from http_request_duration_second that get's measured on all paths similar to http_request_duration_second?

disjunction commented 3 years ago

You can, it will mean essentially - cut off the latency information and keep the count only. But that is not what this module is about. You can look into the code and create your (simplified) version of it if you like. Instead of doing timer() stuff here https://github.com/jochen-schweizer/express-prom-bundle/blob/7654a4ec79fa3b85affcfb23cf48cf7c9ba570a2/src/index.js#L165 you would call your metric counter.inc({ method: ..., path: ...}) (that's what comes from the top of my head, didn't test it)

vamsioyo commented 3 years ago

Oh..Great!!, Thanks for the Clarification