SOLR-8785: Convert rates to be per minute from the default per second rates reported by the metrics library

This commit is contained in:
Shalin Shekhar Mangar 2016-11-23 23:11:36 +05:30
parent 7e6e68900b
commit dab2e24656
2 changed files with 12 additions and 6 deletions

View File

@ -27,6 +27,8 @@ import org.apache.solr.common.util.NamedList;
*/
public class TimerUtils {
private static final double RATE_FACTOR = TimeUnit.MINUTES.toSeconds(1);
/**
* Adds metrics from a Timer to a NamedList, using well-known names.
* @param lst The NamedList to add the metrics data to
@ -34,9 +36,9 @@ public class TimerUtils {
*/
public static void addMetrics(NamedList<Object> lst, Timer timer) {
Snapshot snapshot = timer.getSnapshot();
lst.add("avgRequestsPerMinute", timer.getMeanRate());
lst.add("5minRateRequestsPerMinute", timer.getFiveMinuteRate());
lst.add("15minRateRequestsPerMinute", timer.getFifteenMinuteRate());
lst.add("avgRequestsPerMinute", convertRateToPerMinute(timer.getMeanRate()));
lst.add("5minRateRequestsPerMinute", convertRateToPerMinute(timer.getFiveMinuteRate()));
lst.add("15minRateRequestsPerMinute", convertRateToPerMinute(timer.getFifteenMinuteRate()));
lst.add("avgTimePerRequest", nsToMs(snapshot.getMean()));
lst.add("medianRequestTime", nsToMs(snapshot.getMedian()));
lst.add("75thPcRequestTime", nsToMs(snapshot.get75thPercentile()));
@ -55,4 +57,8 @@ public class TimerUtils {
return ns / TimeUnit.MILLISECONDS.toNanos(1);
}
static double convertRateToPerMinute(double rate) {
return rate * RATE_FACTOR;
}
}

View File

@ -43,9 +43,9 @@ public class TimerUtilsTest extends SolrTestCaseJ4 {
assertEquals(lst.size(), 9);
final Snapshot snapshot = timer.getSnapshot();
// cannot test avgRequestsPerMinute directly because mean rate changes as time increases!
// assertEquals(lst.get("avgRequestsPerMinute"), timer.getMeanRate());
assertEquals(lst.get("5minRateRequestsPerMinute"), timer.getFiveMinuteRate());
assertEquals(lst.get("15minRateRequestsPerMinute"), timer.getFifteenMinuteRate());
// assertEquals(lst.get("avgRequestsPerMinute"), TimerUtils.convertRateToPerMinute(timer.getMeanRate()));
assertEquals(lst.get("5minRateRequestsPerMinute"), TimerUtils.convertRateToPerMinute(timer.getFiveMinuteRate()));
assertEquals(lst.get("15minRateRequestsPerMinute"), TimerUtils.convertRateToPerMinute(timer.getFifteenMinuteRate()));
assertEquals(lst.get("avgTimePerRequest"), TimerUtils.nsToMs(snapshot.getMean()));
assertEquals(lst.get("medianRequestTime"), TimerUtils.nsToMs(snapshot.getMedian()));
assertEquals(lst.get("75thPcRequestTime"), TimerUtils.nsToMs(snapshot.get75thPercentile()));