Esempio n. 1
0
        public TMetric RemoveLabelled(TLabels labels)
        {
            if (_labelledMetrics == null)
            {
                throw new InvalidOperationException("Metric family does not have any labels");
            }

            var key = LabelsHelper.GetHashCode(labels);

            _labelledMetrics.TryRemove(key, out var removed);

            return(removed);
        }
Esempio n. 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));
        }
Esempio n. 3
0
        TMetric IMetricFamily <TMetric> .RemoveLabelled(params string[] labels)
        {
            if (_labelledMetrics == null)
            {
                throw new InvalidOperationException("Metric family does not have any labels");
            }

            if (labels.Length != _configuration.LabelNames.Count)
            {
                throw new ArgumentException("Wrong number of labels");
            }

            var key = LabelsHelper.GetHashCode(labels);

            _labelledMetrics.TryRemove(key, out var removed);

            return(removed);
        }
Esempio n. 4
0
        TMetric IMetricFamily <TMetric> .WithLabels(params string[] labels)
        {
            if (_labelledMetrics == null)
            {
                throw new InvalidOperationException("Metric family does not have any labels");
            }

            if (labels.Length != _configuration.LabelNames.Count)
            {
                throw new ArgumentException("Wrong number of labels");
            }

            var key = LabelsHelper.GetHashCode(labels);

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

            metric = CreateLabelled(labels);
            return(_labelledMetrics.GetOrAdd(key, metric));
        }