Пример #1
0
        /// <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);
        }
Пример #2
0
        public TMetric WithLabels(TLabels labels)
        {
            if (_labelledMetrics == null)
            {
                throw new InvalidOperationException("Metric family does not have any labels");
            }

            var key = LabelsHelper.GetHashCode(labels);

            if (_labelledMetrics.TryGetValue(key, out var metric))
            {
                return(metric);
            }

            metric = CreateLabelled(LabelsHelper.ToArray(labels));
            return(_labelledMetrics.GetOrAdd(key, metric));
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <summary>
        ///     Create  Counter.
        /// </summary>
        /// <param name="name">Metric name.</param>
        /// <param name="help">Help text.</param>
        /// <param name="includeTimestamp">Include unix timestamp for metric.</param>
        /// <param name="labelNames">Label names</param>
        public IMetricFamily <ICounter, TLabels> CreateCounter <TLabels>(string name, string help, TLabels labelNames, bool includeTimestamp = false)
#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(labelNames), includeTimestamp);
                metric = CreateCounterInternal <TLabels>(configuration);
            }
            else
            {
                ValidateLabelNames(metric.LabelNames, labelNames);
            }

            return(metric);
        }