Example #1
0
        public static MetricsValue ToPrometheusMetric(this CounterValue.SetItem item)
        {
            var result = new MetricsValue
            {
                Gauge = new Gauge
                {
                    Value = item.Count
                },
                Label = item.Tags.ToLabelPairs()
            };

            return(result);
        }
Example #2
0
        private static void WriteMetric(StreamWriter streamWriter, MetricFamily family, MetricsValue metric)
        {
            var familyName = family.Name;

            if (metric.Gauge != null)
            {
                WriteSimpleValue(streamWriter, familyName, metric.Gauge.Value, metric.Label);
            }
            else if (metric.Counter != null)
            {
                WriteSimpleValue(streamWriter, familyName, metric.Counter.Value, metric.Label);
            }
            else if (metric.Summary != null)
            {
                WriteSimpleValue(streamWriter, familyName, metric.Summary.Sample_Sum, metric.Label, "_sum");
                WriteSimpleValue(streamWriter, familyName, metric.Summary.Sample_Count, metric.Label, "_count");

                foreach (var quantileValuePair in metric.Summary.Quantile)
                {
                    var quantile = double.IsPositiveInfinity(quantileValuePair.QuantileValue) ? "+Inf" : quantileValuePair.QuantileValue.ToString(CultureInfo.InvariantCulture);

                    WriteSimpleValue(
                        streamWriter,
                        familyName,
                        quantileValuePair.Value,
                        metric.Label.Concat(new[] { new LabelPair {
                                                        Name = "quantile", Value = quantile
                                                    } }));
                }
            }
            else if (metric.Histogram != null)
            {
                WriteSimpleValue(streamWriter, familyName, metric.Histogram.Sample_Sum, metric.Label, "_sum");
                WriteSimpleValue(streamWriter, familyName, metric.Histogram.Sample_Count, metric.Label, "_count");
                foreach (var bucket in metric.Histogram.Buckets)
                {
                    var value = double.IsPositiveInfinity(bucket.Upper_Bound) ? "+Inf" : bucket.Upper_Bound.ToString(CultureInfo.InvariantCulture);

                    WriteSimpleValue(
                        streamWriter,
                        familyName,
                        bucket.Cumulative_Count,
                        metric.Label.Concat(new[] { new LabelPair {
                                                        Name = "le", Value = value
                                                    } }),
                        "_bucket");
                }
            }
            else
            {
                // not supported
            }
        }