public void CanReadOptions(MetricFlags options, bool includeTimestamp, bool suppressEmptySamples) { var config = new MetricConfiguration("test_name", string.Empty, null, options); Assert.Equal(includeTimestamp, config.IncludeTimestamp); Assert.Equal(suppressEmptySamples, config.SuppressEmptySamples); }
/// <summary> /// Create Summary /// </summary> /// <param name="name">Name.</param> /// <param name="help">Help text.</param> /// <param name="options">Metric flags</param> /// <param name="labels">Array of label names.</param> /// <param name="objectives">.</param> /// <param name="maxAge"></param> /// <param name="ageBuckets"></param> /// <param name="bufCap"></param> public IMetricFamily <ISummary, TLabels> CreateSummary <TLabels>( string name, string help, TLabels labels, IReadOnlyList <QuantileEpsilonPair> objectives = null, TimeSpan?maxAge = null, int?ageBuckets = null, int?bufCap = null, MetricFlags options = MetricFlags.Default) #if HasITuple where TLabels : struct, ITuple, IEquatable <TLabels> #else where TLabels : struct, IEquatable <TLabels> #endif { var metric = TryGetByName <IMetricFamily <ISummary, TLabels> >(name); if (metric == null) { var configuration = new SummaryConfiguration(name, help, LabelsHelper.ToArray(labels), options, objectives, maxAge, ageBuckets, bufCap); metric = CreateSummaryInternal <TLabels>(configuration); } ValidateLabelNames(metric.LabelNames, labels); return(metric); }
public SummaryConfiguration( string name, string help, IReadOnlyList <string> labelNames, MetricFlags options, IReadOnlyList <QuantileEpsilonPair> objectives = null, TimeSpan?maxAge = null, int?ageBuckets = null, int?bufCap = null) : base(name, help, labelNames, options) { Objectives = objectives; if (Objectives == null || Objectives.Count == 0) { Objectives = DefaultObjectives; } var sorted = new double[Objectives.Count]; for (int i = 0; i < Objectives.Count; i++) { sorted[i] = Objectives[i].Quantile; } Array.Sort(sorted); SortedObjectives = sorted; FormattedObjectives = SortedObjectives .Select(o => o.ToString(CultureInfo.InvariantCulture)) .ToArray(); MaxAge = maxAge ?? _defaultMaxAge; if (MaxAge < TimeSpan.Zero) { throw new ArgumentException($"Illegal max age {MaxAge}"); } AgeBuckets = ageBuckets ?? _defaultAgeBuckets; if (AgeBuckets == 0) { AgeBuckets = _defaultAgeBuckets; } BufCap = bufCap ?? _defaultBufCap; if (BufCap == 0) { BufCap = _defaultBufCap; } if (LabelNames.Any(_ => _ == _quantileLabel)) { throw new ArgumentException($"{_quantileLabel} is a reserved label name"); } }
/// <summary> /// Create Counter. /// </summary> /// <param name="name">Metric name.</param> /// <param name="help">Help text.</param> /// <param name="options">Metric flags</param> /// <param name="labels">Label names</param> public IMetricFamily <ICounter> CreateCounter(string name, string help, MetricFlags options = MetricFlags.Default, params string[] labels) { var metric = TryGetByName <IMetricFamily <ICounter> >(name); if (metric == null) { var configuration = new MetricConfiguration(name, help, labels, options); metric = GetCounterFactory(labels?.Length ?? 0)(this, configuration); } ValidateLabelNames(metric.LabelNames, labels); return(metric); }
public static IMetricFamily <ISummary, ValueTuple <string> > CreateSummary( this MetricFactory factory, string name, string help, string labelName, IReadOnlyList <QuantileEpsilonPair> objectives = null, TimeSpan?maxAge = null, int?ageBuckets = null, int?bufCap = null, MetricFlags options = MetricFlags.Default) { return(factory.CreateSummary(name, help, ValueTuple.Create(labelName), objectives, maxAge, ageBuckets, bufCap, options)); }
/// <summary> /// Create Untyped. /// </summary> /// <param name="name">Metric name.</param> /// <param name="help">Help text.</param> /// <param name="options">Metric flags</param> public IUntyped CreateUntyped(string name, string help, MetricFlags options = MetricFlags.Default) { var metric = TryGetByName <IMetricFamily <IUntyped, ValueTuple> >(name); if (metric == null) { var configuration = new MetricConfiguration(name, help, null, options); metric = CreateUntypedInternal <ValueTuple>(configuration); } ValidateLabelNames(metric.LabelNames, default); return(metric.Unlabelled); }
/// <summary> /// Create Summary /// </summary> /// <param name="name">Name.</param> /// <param name="help">Help text.</param> /// <param name="options">Metric flags</param> /// <param name="objectives">.</param> /// <param name="maxAge"></param> /// <param name="ageBuckets"></param> /// <param name="bufCap"></param> public ISummary CreateSummary( string name, string help, IReadOnlyList <QuantileEpsilonPair> objectives = null, TimeSpan?maxAge = null, int?ageBuckets = null, int?bufCap = null, MetricFlags options = MetricFlags.Default) { var metric = TryGetByName <IMetricFamily <ISummary, ValueTuple> >(name); if (metric == null) { var configuration = new SummaryConfiguration(name, help, null, options, objectives, maxAge, ageBuckets, bufCap); metric = CreateSummaryInternal <ValueTuple>(configuration); } ValidateLabelNames(metric.LabelNames, default); return(metric.Unlabelled); }
/// <summary> /// Create Summary /// </summary> /// <param name="name">Name.</param> /// <param name="help">Help text.</param> /// <param name="options">Metric flags</param> /// <param name="labels">Array of label names.</param> /// <param name="objectives">.</param> /// <param name="maxAge"></param> /// <param name="ageBuckets"></param> /// <param name="bufCap"></param> public IMetricFamily <ISummary> CreateSummary( string name, string help, IReadOnlyList <QuantileEpsilonPair> objectives = null, TimeSpan?maxAge = null, int?ageBuckets = null, int?bufCap = null, MetricFlags options = MetricFlags.Default, params string[] labels) { var metric = TryGetByName <IMetricFamily <ISummary> >(name); if (metric == null) { var configuration = new SummaryConfiguration(name, help, labels, options, objectives, maxAge, ageBuckets, bufCap); metric = GetSummaryFactory(labels?.Length ?? 0)(this, configuration); } ValidateLabelNames(metric.LabelNames, labels); return(metric); }
public static IMetricFamily <IHistogram, ValueTuple <string> > CreateHistogram(this MetricFactory factory, string name, string help, string labelName, double[] buckets = null, MetricFlags options = MetricFlags.Default) { return(factory.CreateHistogram(name, help, ValueTuple.Create(labelName), buckets, options)); }
/// <summary> /// Create Counter. /// </summary> /// <param name="name">Metric name.</param> /// <param name="help">Help text.</param> /// <param name="options">Metric flags</param> /// <param name="labels">Label names</param> public IMetricFamily <ICounter, TLabels> CreateCounter <TLabels>(string name, string help, TLabels labels, MetricFlags options = MetricFlags.Default) #if HasITuple where TLabels : struct, ITuple, IEquatable <TLabels> #else where TLabels : struct, IEquatable <TLabels> #endif { var metric = TryGetByName <IMetricFamily <ICounter, TLabels> >(name); if (metric == null) { var configuration = new MetricConfiguration(name, help, LabelsHelper.ToArray(labels), options); metric = CreateCounterInternal <TLabels>(configuration); } ValidateLabelNames(metric.LabelNames, labels); return(metric); }
private IGauge CreateGauge(MetricFlags options = MetricFlags.Default) { var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), options); return(new Gauge(config, Array.Empty <string>())); }
/// <summary> /// Create Histogram. /// </summary> /// <param name="name">Metric name.</param> /// <param name="help">Help text.</param> /// <param name="buckets">Buckets.</param> /// <param name="options">Metric flags</param> /// <param name="labels">Label names</param> public IMetricFamily <IHistogram> CreateHistogram(string name, string help, double[] buckets = null, MetricFlags options = MetricFlags.Default, params string[] labels) { var metric = TryGetByName <IMetricFamily <IHistogram> >(name); if (metric == null) { var configuration = new HistogramConfiguration(name, help, labels, buckets, options); metric = GetHistogramFactory(labels?.Length ?? 0)(this, configuration); } ValidateLabelNames(metric.LabelNames, labels); return(metric); }
/// <summary> /// Create Histogram. /// </summary> /// <param name="name">Name.</param> /// <param name="help">Help text.</param> /// <param name="buckets">Buckets.</param> /// <param name="options">Metric flags</param> public IHistogram CreateHistogram(string name, string help, double[] buckets = null, MetricFlags options = MetricFlags.Default) { var metric = TryGetByName <IMetricFamily <IHistogram, ValueTuple> >(name); if (metric == null) { var configuration = new HistogramConfiguration(name, help, null, buckets, options); metric = CreateHistogramInternal <ValueTuple>(configuration); } ValidateLabelNames(metric.LabelNames, default); return(metric.Unlabelled); }
private IHistogram CreateHistogram(IReadOnlyList <double> buckets = null, MetricFlags options = MetricFlags.Default) { var config = new HistogramConfiguration("test", string.Empty, Array.Empty <string>(), buckets, options); return(new Histogram(config, Array.Empty <string>())); }
private IUntyped CreateUntyped(MetricFlags options = MetricFlags.Default) { var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), options); return(new Untyped(config, Array.Empty <string>())); }
public HistogramConfiguration(string name, string help, IReadOnlyList <string> labels, IReadOnlyList <double> buckets, MetricFlags options) : base(name, help, labels, options) { Buckets = buckets ?? _defaultBuckets; if (LabelNames.Any(l => l == "le")) { throw new ArgumentException("'le' is a reserved label name"); } if (Buckets.Count == 0) { throw new ArgumentException("Histogram must have at least one bucket"); } if (!double.IsPositiveInfinity(Buckets[Buckets.Count - 1])) { Buckets = Buckets.Concat(_positiveInf).ToArray(); } for (int i = 1; i < Buckets.Count; i++) { if (Buckets[i] <= Buckets[i - 1]) { throw new ArgumentException("Bucket values must be increasing"); } } FormattedBuckets = Buckets .Select(b => b.ToString(CultureInfo.InvariantCulture)) .ToArray(); }
public static IMetricFamily <IGauge, ValueTuple <string> > CreateGauge(this MetricFactory factory, string name, string help, string labelName, MetricFlags options = MetricFlags.Default) { return(factory.CreateGauge(name, help, ValueTuple.Create(labelName), options)); }
private Counter CreateCounter(MetricFlags options = MetricFlags.Default) { var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), options); return(new Counter(config, Array.Empty <string>())); }
public static IMetricFamily <ICounter <long>, ValueTuple <string> > CreateCounterInt64(this MetricFactory factory, string name, string help, string labelName, MetricFlags options = MetricFlags.Default) { return(factory.CreateCounterInt64(name, help, ValueTuple.Create(labelName), options)); }
public MetricConfiguration(string name, string help, IReadOnlyList <string> labels, MetricFlags options) : base(name) { Help = help; IncludeTimestamp = options.HasFlag(MetricFlags.IncludeTimestamp); SuppressEmptySamples = options.HasFlag(MetricFlags.SupressEmptySamples); LabelNames = labels ?? Array.Empty <string>(); foreach (string labelName in LabelNames) { if (string.IsNullOrEmpty(labelName)) { throw new ArgumentException("Label name cannot be empty"); } if (!ValidateLabelName(labelName)) { throw new ArgumentException($"Invalid label name: {labelName}"); } } }