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

Update Metrics.java #610

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
30 changes: 21 additions & 9 deletions jpos/src/main/java/org/jpos/util/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class Metrics implements Loggeable {
private Histogram template;
private Map<String,Histogram> metrics = new ConcurrentHashMap<>();
private double conversion = 1;

public Metrics(Histogram template) {
super();
Expand Down Expand Up @@ -78,17 +79,18 @@ public void dump (PrintStream ps, String indent) {
}

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",
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 @@ -108,4 +110,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;
}
}
Loading