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

Filters for Reporters

pbolduc opened this issue · comments

I think it would be useful to be able to support filters on reporters so only certain metrics are sent specific reporters. I am thinking of the case where I may want to only a subset of metrics to be sent to a metered service like Application Insights. Application Insights or New Relic provide instrumentation agents that already collect performance counter data, request time etc. The filter should be specific to specific a reporter.

I am not sure the best approach for this feature, however, the filter should apply before formatting the name for the specific reporter. One approach could be (I do not like this suggestion):

        Metric.Config.WithReporting(r => r
            .WithApplicationInsights(TimeSpan.FromSeconds(30))
            .WithFilter(new MetricsReportFilter(/*args*/)));

It could be something passed to the constructor of the filter and passed as an optional parameter in the extension method,

        Metric.Config.WithReporting(r => r
            .WithApplicationInsights(TimeSpan.FromSeconds(30), new MetricsReportFilter(/*args*/)));

The only issue is there is a bit of mismatch from the perspective of the developer. When writing to metrics, they are dealing with Timer, Meter, etc and then in the reporter, it deals with the raw values and formatted metric name. Could also use Tags filter.

Edit: 2015-05-02 14:50 PST

Another use case I came up with is that I may want to register the same reporter, ie Application Insights or Graphite, and report different metrics at different intervals. I may want to report CPU and RAM Performance counters every 60 seconds, but record number of messages processed every 10 seconds. I would add multiple reporters, each with different filter criteria.

@pbolduc filtering is something that I initially considered, but never got around to finish a proper solution. There is a class MetricsFilter with most of the required functionality.

I'll add to my to do list to expose the filtering in the reports API. I was planning anyhow to re-iterate and review the reporting APIs and infra to make sure they are simple and adaptable to all needs.

I also lean over to the second version of the API where a filter instance is passed to the WithReport call.