-
Notifications
You must be signed in to change notification settings - Fork 110
Grouping & Organizing Metrics
Shortly after starting to instrument your first application with the Metrics library, you notice that you start adding more an more metrics and soon they become a bit harder to organize and manage. Collecting them is no problem, as the Metrics.NET library should not cause any noticeable overhead even for thousands of metrics. But when you try to view a particular metric, things can get tricky. This could be solved by pushing metrics to an external metrics store (like Graphite) but sometimes that is not possible.
The Metrics.NET library provides a few ways to organize the metrics. You can group collected metrics into Contexts. You can also tag metrics.
By default all the metrics declared are kept into a global metrics context. The static Metric class provides an easy way of accessing the global context.
Whenever you register a metric by using the Metric static helper class the metric is added to the global context:
// gets added to the global metrics context
Timer requestTimer = Metric.Timer("HTTP Requests", Unit.Requests);
However you can also add child contexts to the global context:
// "HTTP" that is a child context of the global context
Timer requestTimer = Metric.Context("HTTP").Timer("Requests", Unit.Requests);
You can nest contexts as deep as you need, but usually one level provides enough structure to be able to view them.
For more details about see the MetricsContext and the AdvancedMetricsContext interfaces
In the (hopefully near) future the visualization app will use context to better organize metrics on the UI.
Each overload to register a metric accepts a tags parameter which can be either a MetricsTags structure or a string, or a string array, or string containing a comma separated list of tags.
Timer requestTimer = Metric.Timer("HTTP Requests", Unit.Requests, "advanced, storage");
In the (hopefully near) future the visualization app will use tags to better organize metrics on the UI.
For any issues please use the GitHub issues. For any other questions and ideas feel free to ping us: @PaulParau, @HinteaDan, @BogdanGaliceanu.