diff --git a/documentation/developer/Performance-Metrics.md b/documentation/developer/Performance-Metrics.md new file mode 100644 index 00000000..eca7bdb3 --- /dev/null +++ b/documentation/developer/Performance-Metrics.md @@ -0,0 +1,18 @@ + +The Libresonic framework contains a convenient class (called MetricsManager) to add inner metrics that constructs in real time some performance indicators. + +The use of MetricsManager is illustrated in the org.libresonic.player.filter.MetricsFilter class. + +The MetricsFilter adds a metric based on the time spent by each /main.view HTTP request. This is interesting as the main.view request is invoqued when something is displayed in the main Libresonic web frame. + +By default, the MetricsManager is deactivated; it does nothing. +It can be activated only by adding the following line inside the livresonic.properties configuration file : + +``` +Metrics= +``` + +Once the MetricsManager as been activated this way, each metric can be inspected using a jmx console like VisualVM. +Each metric is registered as a MBean as shown below. + +![](metrics-visualvm-screenshot.png) \ No newline at end of file diff --git a/documentation/developer/metrics-visualvm-screenshot.png b/documentation/developer/metrics-visualvm-screenshot.png new file mode 100644 index 00000000..d9a52c7c Binary files /dev/null and b/documentation/developer/metrics-visualvm-screenshot.png differ diff --git a/libresonic-main/src/main/java/org/libresonic/player/filter/MetricsFilter.java b/libresonic-main/src/main/java/org/libresonic/player/filter/MetricsFilter.java index 528e6039..18e886f8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/filter/MetricsFilter.java +++ b/libresonic-main/src/main/java/org/libresonic/player/filter/MetricsFilter.java @@ -25,6 +25,7 @@ public class MetricsFilter implements Filter { HttpServletRequest httpServletRequest = (HttpServletRequest)request; String timerName = httpServletRequest.getRequestURI(); + // Add a metric that measures the time spent for each http request for the /main.view url. try (MetricsManager.Timer t = metricsManager.condition(timerName.contains("main.view")).timer(this,timerName)) { chain.doFilter(request, response); }