public StringBuilder toText()

in geronimo-metrics-common/src/main/java/org/apache/geronimo/microprofile/metrics/common/prometheus/PrometheusFormatter.java [121:188]


    public StringBuilder toText(final MetricRegistry registry,
                                final String registryKey,
                                final Map<String, Metric> entries) {
        final Map<String, Metadata> metadatas = registry.getMetadata();
        final Map<Metric, MetricID> ids = registry.getMetrics().entrySet().stream()
                .collect(toMap(Map.Entry::getValue, Map.Entry::getKey));
        return entries.entrySet().stream()
                .map(it -> {
                    String key = it.getKey();
                    final int tagSep = key.indexOf(';');
                    if (tagSep > 0) {
                        key = key.substring(0, tagSep);
                    }
                    final Metadata metadata = metadatas.get(key);
                    return new Entry(metadata, registryKey + '_' + toPrometheusKey(metadata), it.getValue(), ids.get(it.getValue()));
                })
                .filter(it -> prefixFilter == null || prefixFilter.test(it.prometheusKey))
                .map(entry -> {
                    final List<Tag> tagsAsList = getTags(entry);
                    switch (entry.metadata.getTypeRaw()) {
                        case COUNTER: {
                            String key = toPrometheusKey(entry.metadata);
                            if (!key.endsWith("_total")) {
                                key += "_total";
                            }
                            return counter(registryKey, entry, tagsAsList, key);
                        }
                        case CONCURRENT_GAUGE: {
                            final String key = toPrometheusKey(entry.metadata);
                            final ConcurrentGauge concurrentGauge = ConcurrentGauge.class.cast(entry.metric);
                            return concurrentGauge(registryKey, entry, tagsAsList, key, concurrentGauge);
                        }
                        case GAUGE: {
                            final Object value = Gauge.class.cast(entry.metric).getValue();
                            if (Number.class.isInstance(value)) {
                                final String key = toPrometheusKey(entry.metadata);
                                return gauge(registryKey, entry, tagsAsList, Number.class.cast(value), key);
                            }
                            return new StringBuilder();
                        }
                        case METERED: {
                            final Meter meter = Meter.class.cast(entry.metric);
                            final String keyBase = toPrometheus(entry.metadata);
                            return meter(registryKey, entry, tagsAsList, meter, keyBase);
                        }
                        case TIMER: {
                            final String keyBase = toPrometheus(entry.metadata);
                            final String keyUnit = toUnitSuffix(entry.metadata, false);
                            final Timer timer = Timer.class.cast(entry.metric);
                            return timer(registryKey, entry, tagsAsList, keyBase, keyUnit, timer);
                        }
                        case SIMPLE_TIMER: {
                            final String keyBase = toPrometheus(entry.metadata);
                            final String keyUnit = toUnitSuffix(entry.metadata, false);
                            final SimpleTimer timer = SimpleTimer.class.cast(entry.metric);
                            return simpleTimer(registryKey, entry, tagsAsList, keyBase, keyUnit, timer);
                        }
                        case HISTOGRAM:
                            final String keyBase = toPrometheus(entry.metadata);
                            final String keyUnit = toUnitSuffix(entry.metadata, false);
                            final Histogram histogram = Histogram.class.cast(entry.metric);
                            return histogram(registryKey, entry, tagsAsList, keyBase, keyUnit, histogram);
                        default:
                            return new StringBuilder();
                    }
                })
                .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append);
    }