diff --git a/common/src/main/java/com/zegelin/cassandra/exporter/CassandraMetricsUtilities.java b/common/src/main/java/com/zegelin/cassandra/exporter/CassandraMetricsUtilities.java index 6c57fd1..05dcc1b 100644 --- a/common/src/main/java/com/zegelin/cassandra/exporter/CassandraMetricsUtilities.java +++ b/common/src/main/java/com/zegelin/cassandra/exporter/CassandraMetricsUtilities.java @@ -91,7 +91,11 @@ public Stream getIntervals() { new Interval(Interval.Quantile.P_95, (float) histogram.get95thPercentile()), new Interval(Interval.Quantile.P_98, (float) histogram.get98thPercentile()), new Interval(Interval.Quantile.P_99, (float) histogram.get99thPercentile()), - new Interval(Interval.Quantile.P_99_9, (float) histogram.get999thPercentile()) + new Interval(Interval.Quantile.P_99_9, (float) histogram.get999thPercentile()), + new Interval(Interval.Quantile.MIN, (float) histogram.getMin()), + new Interval(Interval.Quantile.MEAN, (float) histogram.getMean()), + new Interval(Interval.Quantile.MAX, (float) histogram.getMax()), + new Interval(Interval.Quantile.STDDEV, (float) histogram.getStdDev()) ); } }; @@ -109,7 +113,7 @@ public long getCount() { public Stream getIntervals() { final Snapshot snapshot = metric.getSnapshot(); - return Interval.asIntervals(Interval.Quantile.STANDARD_PERCENTILES, q -> (float) snapshot.getValue(q.value)); + return Interval.asIntervals(Interval.Quantile.STANDARD_PERCENTILES, q -> q.decode(snapshot)); } }; } diff --git a/common/src/main/java/com/zegelin/prometheus/domain/Interval.java b/common/src/main/java/com/zegelin/prometheus/domain/Interval.java index a353f61..e2c8242 100644 --- a/common/src/main/java/com/zegelin/prometheus/domain/Interval.java +++ b/common/src/main/java/com/zegelin/prometheus/domain/Interval.java @@ -1,5 +1,6 @@ package com.zegelin.prometheus.domain; +import com.codahale.metrics.Snapshot; import com.google.common.collect.ImmutableSet; import com.zegelin.function.FloatFloatFunction; @@ -19,8 +20,12 @@ public static class Quantile { public static final Quantile P_98 = q(.98f); public static final Quantile P_99 = q(.99f); public static final Quantile P_99_9 = q(.999f); + public static final Quantile MIN = q(0.0f, "min"); + public static final Quantile MEAN = q(0.0f, "mean"); + public static final Quantile MAX = q(0.0f, "max"); + public static final Quantile STDDEV = q(0.0f, "stddev"); - public static final Set STANDARD_PERCENTILES = ImmutableSet.of(P_50, P_75, P_95, P_98, P_99, P_99_9); + public static final Set STANDARD_PERCENTILES = ImmutableSet.of(P_50, P_75, P_95, P_98, P_99, P_99_9, MIN, MEAN, MAX, STDDEV); public static final Quantile POSITIVE_INFINITY = q(Float.POSITIVE_INFINITY); public final float value; @@ -29,9 +34,13 @@ public static class Quantile { private final Labels summaryLabel, histogramLabel; public Quantile(final float value) { + this(value, Float.toString(value)); + } + + public Quantile(final float value, final String stringRepr) { this.value = value; - this.stringRepr = Float.toString(value); + this.stringRepr = stringRepr; this.summaryLabel = Labels.of("quantile", this.stringRepr); this.histogramLabel = Labels.of("le", this.stringRepr); } @@ -40,6 +49,25 @@ public static Quantile q(final float value) { return new Quantile(value); } + public static Quantile q(final float value, final String stringRepr) { + return new Quantile(value, stringRepr); + } + + public float decode(Snapshot snapshot) { + switch (stringRepr) { + case "min": + return (float) snapshot.getMin(); + case "mean": + return (float) snapshot.getMean(); + case "max": + return (float) snapshot.getMax(); + case "stddev": + return (float) snapshot.getStdDev(); + default: + return (float) snapshot.getValue(value); + } + } + public Labels asSummaryLabel() { return summaryLabel; }