1 package net.pterodactylus.sone.web.pages
3 import com.codahale.metrics.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.web.*
6 import net.pterodactylus.sone.web.page.*
7 import net.pterodactylus.util.template.*
11 @TemplatePath("/templates/metrics.html")
12 @ToadletPath("metrics.html")
13 class MetricsPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val metricsRegistry: MetricRegistry) : SoneTemplatePage(webInterface, loaders, templateRenderer, "Page.Metrics.Title") {
15 override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
16 addHistogram(templateContext, "sone.parsing.duration", "soneParsingDuration")
17 addHistogram(templateContext, "sone.insert.duration", "soneInsertDuration")
20 private fun addHistogram(templateContext: TemplateContext, metricName: String, variablePrefix: String) {
21 metricsRegistry.histogram(metricName).also { histogram ->
22 templateContext["${variablePrefix}Count"] = histogram.count
23 histogram.snapshot.also { snapshot ->
24 templateContext["${variablePrefix}Min"] = snapshot.min
25 templateContext["${variablePrefix}Max"] = snapshot.max
26 templateContext["${variablePrefix}Median"] = snapshot.median
27 templateContext["${variablePrefix}Mean"] = snapshot.mean
28 templateContext["${variablePrefix}Percentile75"] = snapshot.get75thPercentile()
29 templateContext["${variablePrefix}Percentile95"] = snapshot.get95thPercentile()
30 templateContext["${variablePrefix}Percentile98"] = snapshot.get98thPercentile()
31 templateContext["${variablePrefix}Percentile99"] = snapshot.get99thPercentile()
32 templateContext["${variablePrefix}Percentile999"] = snapshot.get999thPercentile()