prometheus-net
48 строк · 2.9 Кб
1using System.ComponentModel;2
3namespace Prometheus;4
5/// <summary>
6/// Allows for substitution of MetricFactory in tests.
7/// You cannot provide your own implementation to prometheus-net code, only to your own code.
8/// </summary>
9public interface IMetricFactory10{
11// These require you to allocate a Configuration for each instance, which can be wasteful because often the only thing that differs is the label names.12// We will mark them as non-browsable to discourage their use. They still work, so they are not obsolete or anything like that. Just discouraged.13[EditorBrowsable(EditorBrowsableState.Never)]14Counter CreateCounter(string name, string help, CounterConfiguration? configuration = null);15[EditorBrowsable(EditorBrowsableState.Never)]16Gauge CreateGauge(string name, string help, GaugeConfiguration? configuration = null);17[EditorBrowsable(EditorBrowsableState.Never)]18Histogram CreateHistogram(string name, string help, HistogramConfiguration? configuration = null);19[EditorBrowsable(EditorBrowsableState.Never)]20Summary CreateSummary(string name, string help, SummaryConfiguration? configuration = null);21
22// These allow you to reuse a Configuration and only provide the label names. The reduced memory allocations can make a difference in high performance scenarios.23// If label names are provided in both, they must match. Otherwise, label names in the Configuration object may be null.24Counter CreateCounter(string name, string help, string[] labelNames, CounterConfiguration? configuration = null);25Gauge CreateGauge(string name, string help, string[] labelNames, GaugeConfiguration? configuration = null);26Histogram CreateHistogram(string name, string help, string[] labelNames, HistogramConfiguration? configuration = null);27Summary CreateSummary(string name, string help, string[] labelNames, SummaryConfiguration? configuration = null);28
29/// <summary>30/// Returns a new metric factory that will add the specified labels to any metrics created using it.31/// </summary>32IMetricFactory WithLabels(IDictionary<string, string> labels);33
34/// <summary>35/// Returns a factory that creates metrics with a managed lifetime.36/// </summary>37/// <param name="expiresAfter">38/// Metrics created from this factory will expire after this time span elapses, enabling automatic deletion of unused metrics.39/// The expiration timer is reset to zero for the duration of any active lifetime-extension lease that is taken on a specific metric.40/// </param>41IManagedLifetimeMetricFactory WithManagedLifetime(TimeSpan expiresAfter);42
43/// <summary>44/// Allows you to configure how exemplars are applied to published metrics. If null, uses default behavior (see <see cref="ExemplarBehavior"/>).45/// This is inherited by all metrics by default, although may be overridden in the configuration of an individual metric.46/// </summary>47ExemplarBehavior? ExemplarBehavior { get; set; }48}
49