This is a simple metrics system for collecting data.
To use the metrics system you will need to implement the IMetricsEmitter interface.
A metrics emitter emit function has three parameters:
-
properties: This is a dictionary of the properties for the current batch of metrics.
-
metrics: An array of all current cached metrics.
-
metricsIndex: The index of the last current valid metric (Note: it is the responsibility of the emitter to remove the invalid metrics).
public class ExampleEmitter : IMetricsEmitter { public Emit(IDictionary<string, object> properties, Metric[] metrics, int metricsIndex) { // Implement. } }
When initalizing the metrics system you will have to pass it an IMetricsEmitter and an int defining the batch size.
var metrics = new Metrics(new ExampleEmitter(), 1);
metrics.Entry("Entry", "Data");
A metric is a struct that is used by all metrics.
- Name: A string used for the name given to the metric.
- TimeStamp: DateTime set to the time that the metric was emitted.
- Type: A string used for indicating the type of metric.
- Data: An object that is the data to be sent with the metric.
Note: The type of a metric is wrapped by the API. They are set by the function call itself. These types are string, float, int, inc (see 'Increment' below) or event (see 'Event' below)
The metrics system has three different metrics that it can emit:
The Entry function for sending data as a string, int or a float.
metrics.Entry("Entry", "Data");
metrics.Entry("Entry", 1);
metrics.Entry("Entry", 1.0f);
The Increment function is used to emit an increment style Metric.
metrics.Inc("Name");
Increment sets the metric type to 'inc'
Designed to be a used for recording the occurances of events.
metrics.Event("Name");
Event sets the metric type to 'event'.
Emits any metrics that are currently in the batch queue.
metrics.Flush();
Within this repository there are several simple examples of using the metrics system with different emitters.
A basic example of the metric system with a simple implementation of the IMetricEmitter interface that writes metrics to a file.
This example implements a IMetricsEmitter that emits the metrics via http post.
Example 3 is an example of using the built in batching system in the metrics system.
An example of running the metrics system under Unity3D using the Unity3D method of http post.