示例#1
0
        /// <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);
        }
示例#2
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> 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);
        }
示例#3
0
        /// <summary>
        ///     Create int-based counter.
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="help">Help text.</param>
        /// <param name="includeTimestamp">Include unix timestamp for metric.</param>
        /// <param name="suppressEmptySamples">Define if empty samples should be included into scrape output</param>
        /// <param name="labelNames">Array of label names.</param>
        public CounterInt64 CreateCounterInt64(string name, string help, bool includeTimestamp, bool suppressEmptySamples, params string[] labelNames)
        {
            var metric = TryGetByName <CounterInt64>(name);

            if (metric == null)
            {
                var configuration = new MetricConfiguration(name, help, includeTimestamp, suppressEmptySamples, labelNames);
                metric = _registry.GetOrAdd(configuration, config => new CounterInt64(config));
            }

            ValidateLabelNames(labelNames, metric.LabelNames);
            return(metric);
        }
        /// <summary>
        ///     Create Gauge
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="help">Help text.</param>
        /// <param name="includeTimestamp">Include unix timestamp for metric.</param>
        /// <param name="labelNames">Array of label names.</param>
        public Gauge CreateGauge(string name, string help, bool includeTimestamp, params string[] labelNames)
        {
            var metric = TryGetByName <Gauge>(name);

            if (metric == null)
            {
                var configuration = new MetricConfiguration(name, help, includeTimestamp, labelNames);
                metric = _registry.GetOrAdd(configuration, config => new Gauge(config));
            }

            ValidateLabelNames(labelNames, metric.LabelNames);
            return(metric);
        }
示例#5
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> CreateCounter(string name, string help, bool includeTimestamp = false, params string[] labelNames)
        {
            var metric = TryGetByName <IMetricFamily <ICounter> >(name);

            if (metric == null)
            {
                var configuration = new MetricConfiguration(name, help, labelNames, includeTimestamp);
                metric = GetCounterFactory(labelNames?.Length ?? 0)(this, configuration);
            }
            else
            {
                ValidateLabelNames(metric.LabelNames, labelNames);
            }

            return(metric);
        }
示例#6
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);
        }
示例#7
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);
        }