digikare / nestjs-prom

A prometheus module for nestjs
160 stars 54 forks source link

how to dynamically name for each function #10

Closed sgraham785 closed 5 years ago

sgraham785 commented 5 years ago

this work well thanks. however, I have a service that has multiple functions and I would like to split and track each separately. the easiest way is to name the stat with the function, even append the name when it's invoked in the function? just starting the conversation cause I am not completely clear on how you implemented yet

spike008t commented 5 years ago

Hi! Thank you for your feedback.

I don't really understand what you want. Do you mean that you want to create the entry on the fly?

sgraham785 commented 5 years ago

on the call of a single function in a service. for example is i have a service that has multiple functions that all compose the module. how can i define the entry specific to the function without having to create a separate static configuration for each function in the module and inject in the service

sgraham785 commented 5 years ago

does my above comment make it clearer? or still need further comments?

spike008t commented 5 years ago

Sorry for the delay, I was a quite busy at the moment.

I do understand your need, I'll try to find out some time to handle it. I need to think how can I manage it. I think it can be possible to have something like this:

class MyClass {
  @PromCounterMetric('myCounter')
  doStuff() {
    myCounter.inc();
  }
}

Or if the aim is to monitor how many time a function is called, can be cool to have something like that:

class MyClass {
  @PromCounterMetricAutoInc()
  doStuff() {
  }
}
spike008t commented 5 years ago

@sgraham785 I've updated the module with new decorators @PromInstanceCounter and @PromMethodCounter.

It's a simple decorator that will generate automatically counter without need to declare the counter. See