Search in sources :

Example 1 with Collector

use of io.prometheus.client.Collector in project micrometer by micrometer-metrics.

the class PrometheusMeterRegistry method newLongTaskTimer.

@Override
protected LongTaskTimer newLongTaskTimer(Meter.Id id) {
    MicrometerCollector collector = collectorByName(id);
    LongTaskTimer ltt = new DefaultLongTaskTimer(id, clock);
    List<String> tagValues = tagValues(id);
    collector.add((conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family(Collector.Type.UNTYPED, conventionName, Stream.of(new Collector.MetricFamilySamples.Sample(conventionName + "_active_count", tagKeys, tagValues, ltt.activeTasks()), new Collector.MetricFamilySamples.Sample(conventionName + "_duration_sum", tagKeys, tagValues, ltt.duration(TimeUnit.SECONDS))))));
    return ltt;
}
Also used : DefaultLongTaskTimer(io.micrometer.core.instrument.internal.DefaultLongTaskTimer) Collector(io.prometheus.client.Collector) DefaultLongTaskTimer(io.micrometer.core.instrument.internal.DefaultLongTaskTimer)

Example 2 with Collector

use of io.prometheus.client.Collector in project micrometer by micrometer-metrics.

the class PrometheusMeterRegistry method newDistributionSummary.

@Override
public DistributionSummary newDistributionSummary(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, double scale) {
    MicrometerCollector collector = collectorByName(id);
    PrometheusDistributionSummary summary = new PrometheusDistributionSummary(id, clock, distributionStatisticConfig, scale);
    List<String> tagValues = tagValues(id);
    collector.add((conventionName, tagKeys) -> {
        Stream.Builder<Collector.MetricFamilySamples.Sample> samples = Stream.builder();
        final ValueAtPercentile[] percentileValues = summary.takeSnapshot().percentileValues();
        final CountAtBucket[] histogramCounts = summary.histogramCounts();
        double count = summary.count();
        if (percentileValues.length > 0) {
            List<String> quantileKeys = new LinkedList<>(tagKeys);
            quantileKeys.add("quantile");
            // satisfies https://prometheus.io/docs/concepts/metric_types/#summary
            for (ValueAtPercentile v : percentileValues) {
                List<String> quantileValues = new LinkedList<>(tagValues);
                quantileValues.add(Collector.doubleToGoString(v.percentile()));
                samples.add(new Collector.MetricFamilySamples.Sample(conventionName, quantileKeys, quantileValues, v.value()));
            }
        }
        Collector.Type type = Collector.Type.SUMMARY;
        if (histogramCounts.length > 0) {
            // Prometheus doesn't balk at a metric being BOTH a histogram and a summary
            type = Collector.Type.HISTOGRAM;
            List<String> histogramKeys = new LinkedList<>(tagKeys);
            histogramKeys.add("le");
            // satisfies https://prometheus.io/docs/concepts/metric_types/#histogram
            for (CountAtBucket c : histogramCounts) {
                final List<String> histogramValues = new LinkedList<>(tagValues);
                histogramValues.add(Collector.doubleToGoString(c.bucket()));
                samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_bucket", histogramKeys, histogramValues, c.count()));
            }
            // the +Inf bucket should always equal `count`
            final List<String> histogramValues = new LinkedList<>(tagValues);
            histogramValues.add("+Inf");
            samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_bucket", histogramKeys, histogramValues, count));
        }
        samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_count", tagKeys, tagValues, count));
        samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_sum", tagKeys, tagValues, summary.totalAmount()));
        return Stream.of(new MicrometerCollector.Family(type, conventionName, samples.build()), new MicrometerCollector.Family(Collector.Type.GAUGE, conventionName + "_max", Stream.of(new Collector.MetricFamilySamples.Sample(conventionName + "_max", tagKeys, tagValues, summary.max()))));
    });
    return summary;
}
Also used : CountAtBucket(io.micrometer.core.instrument.distribution.CountAtBucket) LinkedList(java.util.LinkedList) ValueAtPercentile(io.micrometer.core.instrument.distribution.ValueAtPercentile) Collector(io.prometheus.client.Collector) Stream(java.util.stream.Stream)

Example 3 with Collector

use of io.prometheus.client.Collector in project micrometer by micrometer-metrics.

the class PrometheusMeterRegistry method newGauge.

@SuppressWarnings("unchecked")
@Override
protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, @Nullable T obj, ToDoubleFunction<T> valueFunction) {
    MicrometerCollector collector = collectorByName(id);
    Gauge gauge = new DefaultGauge(id, obj, valueFunction);
    List<String> tagValues = tagValues(id);
    collector.add((conventionName, tagKeys) -> Stream.of(new MicrometerCollector.Family(Collector.Type.GAUGE, conventionName, Stream.of(new Collector.MetricFamilySamples.Sample(conventionName, tagKeys, tagValues, gauge.value())))));
    return gauge;
}
Also used : DefaultGauge(io.micrometer.core.instrument.internal.DefaultGauge) Collector(io.prometheus.client.Collector) DefaultGauge(io.micrometer.core.instrument.internal.DefaultGauge)

Example 4 with Collector

use of io.prometheus.client.Collector in project alluxio by Alluxio.

the class RatisDropwizardExports method deregisterDropwizard.

private static void deregisterDropwizard(RatisMetricRegistry registry, Map<String, RatisDropwizardExports> ratisMetricsMap) {
    String name = registry.getMetricRegistryInfo().getName();
    Collector c = ratisMetricsMap.remove(name);
    if (c != null) {
        CollectorRegistry.defaultRegistry.unregister(c);
    }
}
Also used : Collector(io.prometheus.client.Collector)

Example 5 with Collector

use of io.prometheus.client.Collector in project micrometer by micrometer-metrics.

the class PrometheusMeterRegistry method newTimer.

@Override
protected io.micrometer.core.instrument.Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
    MicrometerCollector collector = collectorByName(id);
    PrometheusTimer timer = new PrometheusTimer(id, clock, distributionStatisticConfig, pauseDetector);
    List<String> tagValues = tagValues(id);
    collector.add((conventionName, tagKeys) -> {
        Stream.Builder<Collector.MetricFamilySamples.Sample> samples = Stream.builder();
        final ValueAtPercentile[] percentileValues = timer.takeSnapshot().percentileValues();
        final CountAtBucket[] histogramCounts = timer.histogramCounts();
        double count = timer.count();
        if (percentileValues.length > 0) {
            List<String> quantileKeys = new LinkedList<>(tagKeys);
            quantileKeys.add("quantile");
            // satisfies https://prometheus.io/docs/concepts/metric_types/#summary
            for (ValueAtPercentile v : percentileValues) {
                List<String> quantileValues = new LinkedList<>(tagValues);
                quantileValues.add(Collector.doubleToGoString(v.percentile()));
                samples.add(new Collector.MetricFamilySamples.Sample(conventionName, quantileKeys, quantileValues, v.value(TimeUnit.SECONDS)));
            }
        }
        Collector.Type type = distributionStatisticConfig.isPublishingHistogram() ? Collector.Type.HISTOGRAM : Collector.Type.SUMMARY;
        if (histogramCounts.length > 0) {
            // Prometheus doesn't balk at a metric being BOTH a histogram and a summary
            type = Collector.Type.HISTOGRAM;
            List<String> histogramKeys = new LinkedList<>(tagKeys);
            histogramKeys.add("le");
            // satisfies https://prometheus.io/docs/concepts/metric_types/#histogram
            for (CountAtBucket c : histogramCounts) {
                final List<String> histogramValues = new LinkedList<>(tagValues);
                histogramValues.add(Collector.doubleToGoString(c.bucket(TimeUnit.SECONDS)));
                samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_bucket", histogramKeys, histogramValues, c.count()));
            }
            // the +Inf bucket should always equal `count`
            final List<String> histogramValues = new LinkedList<>(tagValues);
            histogramValues.add("+Inf");
            samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_bucket", histogramKeys, histogramValues, count));
        }
        samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_count", tagKeys, tagValues, count));
        samples.add(new Collector.MetricFamilySamples.Sample(conventionName + "_sum", tagKeys, tagValues, timer.totalTime(TimeUnit.SECONDS)));
        return Stream.of(new MicrometerCollector.Family(type, conventionName, samples.build()), new MicrometerCollector.Family(Collector.Type.GAUGE, conventionName + "_max", Stream.of(new Collector.MetricFamilySamples.Sample(conventionName + "_max", tagKeys, tagValues, timer.max(getBaseTimeUnit())))));
    });
    return timer;
}
Also used : CountAtBucket(io.micrometer.core.instrument.distribution.CountAtBucket) LinkedList(java.util.LinkedList) ValueAtPercentile(io.micrometer.core.instrument.distribution.ValueAtPercentile) Collector(io.prometheus.client.Collector) Stream(java.util.stream.Stream)

Aggregations

Collector (io.prometheus.client.Collector)9 LinkedList (java.util.LinkedList)4 CountAtBucket (io.micrometer.core.instrument.distribution.CountAtBucket)2 ValueAtPercentile (io.micrometer.core.instrument.distribution.ValueAtPercentile)2 AbstractMap (java.util.AbstractMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Stream (java.util.stream.Stream)2 CumulativeFunctionCounter (io.micrometer.core.instrument.cumulative.CumulativeFunctionCounter)1 CumulativeFunctionTimer (io.micrometer.core.instrument.cumulative.CumulativeFunctionTimer)1 DefaultGauge (io.micrometer.core.instrument.internal.DefaultGauge)1 DefaultLongTaskTimer (io.micrometer.core.instrument.internal.DefaultLongTaskTimer)1