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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations