Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min/max/mean/stddev to histogram #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public Stream<Interval> 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())
);
}
};
Expand All @@ -109,7 +113,7 @@ public long getCount() {
public Stream<Interval> 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));
}
};
}
Expand Down
32 changes: 30 additions & 2 deletions common/src/main/java/com/zegelin/prometheus/domain/Interval.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<Quantile> STANDARD_PERCENTILES = ImmutableSet.of(P_50, P_75, P_95, P_98, P_99, P_99_9);
public static final Set<Quantile> 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;
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down