Class PrometheusExportUtils


  • final class PrometheusExportUtils
    extends java.lang.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.

    • Constructor Detail

      • PrometheusExportUtils

        private PrometheusExportUtils()
    • Method Detail

      • createMetricFamilySamples

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

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

        private static java.lang.String getNamespacedName​(java.lang.String metricName,
                                                          java.lang.String namespace)
      • getSamples

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

        static java.util.List<java.lang.String> convertToLabelNames​(java.util.List<LabelKey> labelKeys)
      • containsDisallowedLeLabelForHistogram

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

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