Skip to content

Commit

Permalink
Update Metrics.java
Browse files Browse the repository at this point in the history
Changed dumped value format to use .7f precision.
Added 50ieth percentile
Changed the % used for percentile to P Added conversion variable to
allow changing the output number by divided by the conversion factor,
handy when your recorded amounts are nanoseconds and need to show
milliseconds.
  • Loading branch information
chhil authored and ar committed Sep 19, 2024
1 parent 8cc2f59 commit 7532bb2
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions jpos/src/main/java/org/jpos/util/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

public class Metrics implements Loggeable {
private Histogram template;
private Map<String, Histogram> metrics = new ConcurrentHashMap<>();
private Map<String,Histogram> metrics = new ConcurrentHashMap<>();
private double conversion = 1;

public Metrics(Histogram template) {
super();
Expand Down Expand Up @@ -75,18 +76,19 @@ public void dump(PrintStream ps, String indent) {
.forEach(e -> dumpPercentiles(ps, indent, e.getKey(), e.getValue().copy()));
}

private void dumpPercentiles(PrintStream ps, String indent, String key, Histogram h) {
ps.printf("%s%s min=%d, max=%d, mean=%.4f stddev=%.4f 90%%=%d, 99%%=%d, 99.9%%=%d, 99.99%%=%d tot=%d size=%d%n",
private void dumpPercentiles (PrintStream ps, String indent, String key, Histogram h) {
ps.printf("%s%s min=%.7f, max=%.7f, mean=%.7f stddev=%.7f P50=%.7f, P90=%.7f, P99=%.7f, P99.9=%.7f, P99.99=%.7f tot=%d size=%d%n",
indent,
key,
h.getMinValue(),
h.getMaxValue(),
h.getMean(),
h.getStdDeviation(),
h.getValueAtPercentile(90.0),
h.getValueAtPercentile(99.0),
h.getValueAtPercentile(99.9),
h.getValueAtPercentile(99.99),
h.getMinValue()/conversion,
h.getMaxValue()/conversion,
h.getMean()/conversion,
h.getStdDeviation()/conversion,
h.getValueAtPercentile(50.0)/conversion,
h.getValueAtPercentile(90.0)/conversion,
h.getValueAtPercentile(99.0)/conversion,
h.getValueAtPercentile(99.9)/conversion,
h.getValueAtPercentile(99.99)/conversion,
h.getTotalCount(),
h.getEstimatedFootprintInBytes()
);
Expand All @@ -106,4 +108,14 @@ public void dumpHistograms(File dir, String prefix) {
.sorted(Map.Entry.comparingByKey())
.forEach(e -> dumpHistogram(dir, prefix + e.getKey(), e.getValue().copy()));
}

/**
* @param conversion
* This is used to divide the percentile values while dumping.
* If you are using nano seconds to record and want to display the numbers in millis then conversion can be set to 1000000.
* By default conversion is set to 1.
*/
public void setConversion(double conversion) {
this.conversion = conversion;
}
}

0 comments on commit 7532bb2

Please sign in to comment.