Metrics is a framework for reporting data point information (measurements and time-series) for .NET applications, uncompromisingly simple.
Metrics can also be used as a .NET client for Graphite.
- We currently support the following targets out of the box:
- Graphite
- Console
- In-momeory (for tests)
- .Net Core support - targeting .Net Standard 1.6
To start reporting metrics on an application, just call MetricsStarter.Initialize
with the required reporters, on the application startup:
MetricsStarter.Initialize(
new GraphiteMetricsReporterFactory(_graphiteConfiguration),
new ConsoleMetricsReporterFactory(0)
);
Next, to report metrics data, you need to use the static Metrics
object, with the required operation. For example:
//first, declare a space:
private MetricsSpace _metrics = Metrics.Space("Custom").Space("SubSpace").Space("SubSubSpace");
public void SomeMethod()
{
//reporting an increment:
_metrics.Meter("MeterName").Increment(1);
//reporting execution time:
using (_meter("MeterName").TimeScope())
{
// operations to measure...
}
//reporting value distribution:
_metrics.Meter("MeterName").ValueDistribution(value);
}
One of Metric's main targets is Graphite. Graphite is a monitoring tool that applications can report numeric data-points to, and afterwards visualize this data. (more info abour Graphite can be found on Graphite's webstite: https://graphiteapp.org/.
To use Graphite, you will need to implement IGraphiteConfiguration
on your application, and pass it to the GraphiteMetricsReporterFactory
as shown above.
public class GraphiteConfiguration : IGraphiteConfiguration
{
public string IpAddress { get; }
public GraphiteConfiguration(string ipAddress)
{
IpAddress = ipAddress;
}
}
You can turn on/off/suspend the metrics reporting while the application is still running.
Just take dependency on IMetricsSwitch
and use the actions it provides. Note that IMetricsSwitch
controls all metrics reporters.
There's also a switch for controlling graphite only, with the suprising name - IGraphiteSwitch
.
You can customize metrics and take it to a whole new level by creating your own implementation of IMetricsReporterFactory
.
Implement the CreateReporter
Method, and register it to MetricsStarter.Initialize
, along with all other out-of-the-box reporters.
For example, this is basically how our beloved PerfDbg works... it's based on metrics reporting:
public class PerfDbgReporterFactory : IMetricsReporterFactory
{
public Action<DataPoint> CreateReporter()
{
return PerfDbgReporter.Report;
}
}
We encorage contribution via pull requests on any feature you see fit.
When submitting a pull request make sure to do the following:
- Check that new and updated code follows OhioBox existing code formatting and naming standard
- Run all tests to ensure no existing functionality has been affected
- Write tests to test your changes. All features and fixed bugs must have tests to verify they work. Read GitHub Help for more details about creating pull requests
You can simply run the tests in Visual Studio or with NUnit test runner.