etishor / Metrics.NET

The Metrics.NET library provides a way of instrumenting applications with custom metrics (timers, histograms, counters etc) that can be reported in various ways and can provide insights on what is happening inside a running application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MetricsContext does not return metric reference for Gauges or PerfCounters

Paccc opened this issue · comments

The methods to create a gauge or performance counter metric don't return a reference to the metric that was just created, unlike all the other methods to create a metric. Is this a bug, or is this intentional?

Also, it doesn't look like there's any way to dispose the performance counter instance that's created by the PerformanceCounterGauge, which doesn't implement IDisposable. Would it make sense to expose the perf counter reference as a property on the gauge? I could then dispose it manually when I'm done using it. This would additionally be useful to me because I want to access some of the performance counter's properties, specifically, its name, category, instance name, help text, and counter type. Also, shouldn't PerformanceCounterGauge derive from GaugeImplementation?

Another unrelated thing I noticed, it seems like DerivedGauge is essentially identical to ScaledValueProvider with T : double. Is that the only difference, or am I misunderstanding something?

Thanks!

The methods to create a gauge are not suppose to return anything. This is intentional as you are not supposed to interact directly with the gauge. The gauge represents the value of "something" and that "something" is evaluated automatically every time the gauge value is needed.

I realize it is a bit strange as the other metric creation methods return something, but if the gauge would return something it would have to be an empty interface and I'm not a fan of empty interfaces.

You are correct, the PerformanceCounterGauge should implement GaugeImplementation (an empty interface which might disappear in the future).

The performance counter gauges are meant to live for the entire lifespan of the application so disposal was not relay a concern. It is not easy to implement IDisposable for metric objects as most of them don't really need to be disposed and, more important, user objects might still have references to the metrics (running timers, static counters etc). I'll thing about this some more and see if any easy way for having disposable metrics exists.

Given a good use-case I will consider exposing the PerformanceCounter as a property, but my guess is that you might be over-using the PerformanceCounterGauge. Can you provide a bit more details on why you need access to the Gauge properties?

You are correct about the DerivedGauge & ScaledValueProvider. They were created for different purposes and I honestly never noticed they were the same thing. Thanks for spotting this and for the interesting questions.

Closing this for now, feel free to re-open if more info is needed.