Loupe - Log - Monitor - Resolve
Loupe / Developer's Guide / For .NET Core & .NET 5 / Metrics / Developer's Guide - Metrics - Object Model
In This Topic
    Developer's Guide - Metrics - Object Model
    In This Topic

    Data is modeled by Loupe using three classes:

    1. Metric Definitions:  Record the design of the metric, which can be shared between multiple metric instances.
    2. Metric:  A single instance of a metric definition that can have samples recorded against it.  Multiple metrics can share the same Metric Definition.  Each metric has a unique name to distinguish it.
    3. Metric Sample:  A single data point for a metric (only visible for Event Metrics)

    There are two ways to record metrics:

    1. Declarative:  You can decorate objects with attributes to define how to record metrics from them and then use these objects to record metrics easily.
    2. Programmatically:  You can define and record metrics through the API.  While this requires more lines of  code it is slightly faster and more flexible than the declarative method.

    Metric Definitions

    Each metric definition has a three element key:

    Metric definition keys need to be unique between both Sampled and Event metrics.  Because event metrics can be used as sampled metrics it's useful to lay out categories and counters so they make sense to your users together, however a single definition can't be used for both.

    The main purpose of the Metric Definition object is to make it possible to share the metadata that describes a metric between multiple instances of the metric.  For example, in Windows Performance Counters there are a set of metrics that are defined for every network interface.  With this model, all of the metadata is ensured to be consistent between the metric instances. 

    Metric Definitions are immutable for the duration of a session; they are locked as soon as they are registered.  A new metric definition can be added at any time.

    Metric

    Each Metric is a single instance of a metric definition which has a unique string name.  For each definition there can be one metric with a null name, called the Default Instance.   When no name is specified, the default instance is used.  Use multiple instances of a metric instead of separate Metric Definitions when you want to distinguish a runtime separation (such as between databases or network interfaces or files) but share a common data structure.

    Each Metric is immutable for the duration of the session; it is locked as soon as it is registered.  A new metric can be added at any time.

    Metric Sample

    Every value recorded for a specific Metric is recorded as a Metric Sample.  Each sample always has a timestamp recorded with full time zone awareness and a sequence number that's unique within the session.  This ensures that samples can be consistently and uniquely ordered in time based on when they were written to the Loupe Agent.  The data structure that can be recorded with each sample varies depending on whether the metric is a Sampled Metric or Event Metric.

    Metric samples are immutable.
    See Also