Class PrometheusExportUtils

java.lang.Object
io.opencensus.exporter.stats.prometheus.PrometheusExportUtils

final class PrometheusExportUtils extends Object
Util methods to convert OpenCensus Metrics data models to Prometheus data models.

Each OpenCensus MetricDescriptor will be converted to a Prometheus Collector.MetricFamilySamples with no Collector.MetricFamilySamples.Samples, and is used for registering Prometheus Metrics.

Each OpenCensus Metric will be converted to a Prometheus Collector.MetricFamilySamples, and each Point of the Metric will be converted to Prometheus Collector.MetricFamilySamples.Samples.

io.opencensus.metrics.export.Value.ValueDouble, io.opencensus.metrics.export.Value.ValueLong will be converted to a single Collector.MetricFamilySamples.Sample. io.opencensus.metrics.export.Value.ValueSummary will be converted to two Samples sum and count. io.opencensus.metrics.export.Value.ValueDistribution will be converted to a list of Collector.MetricFamilySamples.Samples that have the sum, count and histogram buckets.

LabelKey and LabelValue will be converted to Prometheus LabelName and LabelValue. Null LabelValue will be converted to an empty string.

Please note that Prometheus Metric and Label name can only have alphanumeric characters and underscore. All other characters will be sanitized by underscores.

  • Field Details

  • Constructor Details

    • PrometheusExportUtils

      private PrometheusExportUtils()
  • Method Details

    • createMetricFamilySamples

      static io.prometheus.client.Collector.MetricFamilySamples createMetricFamilySamples(Metric metric, String namespace)
    • createDescribableMetricFamilySamples

      static io.prometheus.client.Collector.MetricFamilySamples createDescribableMetricFamilySamples(MetricDescriptor metricDescriptor, String namespace)
    • getNamespacedName

      private static String getNamespacedName(String metricName, String namespace)
    • getType

      static io.prometheus.client.Collector.Type getType(MetricDescriptor.Type type)
    • getSamples

      static List<io.prometheus.client.Collector.MetricFamilySamples.Sample> getSamples(String name, List<String> labelNames, List<LabelValue> labelValuesList, Value value)
    • convertToLabelNames

      static List<String> convertToLabelNames(List<LabelKey> labelKeys)
    • containsDisallowedLeLabelForHistogram

      static boolean containsDisallowedLeLabelForHistogram(List<String> labelNames, io.prometheus.client.Collector.Type type)
    • containsDisallowedQuantileLabelForSummary

      static boolean containsDisallowedQuantileLabelForSummary(List<String> labelNames, io.prometheus.client.Collector.Type type)