From 6786bfaaf465c8434610362ee11d91377e80a72a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 31 Jul 2019 11:04:05 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=A8=20Add=20metrics=20for=20Sone=20insert?= =?utf8?q?=20durations?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/web/pages/MetricsPage.kt | 27 +++++++++++++--------- src/main/resources/i18n/sone.en.properties | 1 + src/main/resources/templates/metrics.html | 13 +++++++++++ .../sone/web/pages/MetricsPageTest.kt | 7 ++++++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt index e097daf..236848d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/MetricsPage.kt @@ -13,18 +13,23 @@ import javax.inject.* class MetricsPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer, private val metricsRegistry: MetricRegistry) : SoneTemplatePage(webInterface, loaders, templateRenderer, "Page.Metrics.Title") { override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) { - metricsRegistry.histogram("sone.parsing.duration").also { histogram -> - templateContext["soneParsingDurationCount"] = histogram.count + addHistogram(templateContext, "sone.parsing.duration", "soneParsingDuration") + addHistogram(templateContext, "sone.insert.duration", "soneInsertDuration") + } + + private fun addHistogram(templateContext: TemplateContext, metricName: String, variablePrefix: String) { + metricsRegistry.histogram(metricName).also { histogram -> + templateContext["${variablePrefix}Count"] = histogram.count histogram.snapshot.also { snapshot -> - templateContext["soneParsingDurationMin"] = snapshot.min - templateContext["soneParsingDurationMax"] = snapshot.max - templateContext["soneParsingDurationMedian"] = snapshot.median - templateContext["soneParsingDurationMean"] = snapshot.mean - templateContext["soneParsingDurationPercentile75"] = snapshot.get75thPercentile() - templateContext["soneParsingDurationPercentile95"] = snapshot.get95thPercentile() - templateContext["soneParsingDurationPercentile98"] = snapshot.get98thPercentile() - templateContext["soneParsingDurationPercentile99"] = snapshot.get99thPercentile() - templateContext["soneParsingDurationPercentile999"] = snapshot.get999thPercentile() + templateContext["${variablePrefix}Min"] = snapshot.min + templateContext["${variablePrefix}Max"] = snapshot.max + templateContext["${variablePrefix}Median"] = snapshot.median + templateContext["${variablePrefix}Mean"] = snapshot.mean + templateContext["${variablePrefix}Percentile75"] = snapshot.get75thPercentile() + templateContext["${variablePrefix}Percentile95"] = snapshot.get95thPercentile() + templateContext["${variablePrefix}Percentile98"] = snapshot.get98thPercentile() + templateContext["${variablePrefix}Percentile99"] = snapshot.get99thPercentile() + templateContext["${variablePrefix}Percentile999"] = snapshot.get999thPercentile() } } } diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index dedaf18..41fa10c 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -335,6 +335,7 @@ Page.Invalid.Text=An invalid action was performed, or the action was valid but t Page.Metrics.Title=Metrics Page.Metrics.Page.Title=Metrics +Page.Metrics.SoneInsertDuration.Title=Sone Insert Duration Page.Metrics.SoneParsingDuration.Title=Sone Parsing Duration View.Search.Button.Search=Search diff --git a/src/main/resources/templates/metrics.html b/src/main/resources/templates/metrics.html index 9c143eb..8b3a37c 100644 --- a/src/main/resources/templates/metrics.html +++ b/src/main/resources/templates/metrics.html @@ -22,6 +22,19 @@ + <%= Page.Metrics.SoneInsertDuration.Title|l10n|html> + <% soneInsertDurationCount|html> + <% soneInsertDurationMin|html>μs + <% soneInsertDurationMax|html>μs + <% soneInsertDurationMean|format format=='%.0f'|html>μs + <% soneInsertDurationMedian|format format=='%.0f'|html>μs + <% soneInsertDurationPercentile75|format format=='%.0f'|html>μs + <% soneInsertDurationPercentile95|format format=='%.0f'|html>μs + <% soneInsertDurationPercentile98|format format=='%.0f'|html>μs + <% soneInsertDurationPercentile99|format format=='%.0f'|html>μs + <% soneInsertDurationPercentile999|format format=='%.0f'|html>μs + + <%= Page.Metrics.SoneParsingDuration.Title|l10n|html> <% soneParsingDurationCount|html> <% soneParsingDurationMin|html>μs diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt index b727909..d805f65 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/MetricsPageTest.kt @@ -69,6 +69,13 @@ class MetricsPageTest : WebPageTest() { } @Test + fun `metrice pags lists stats about sone insert durations`() { + createHistogram("sone.insert.duration") + page.handleRequest(soneRequest, templateContext) + verifyHistogram("soneInsertDuration") + } + + @Test fun `metrics page delivers correct histogram size`() { val histogram = metricRegistry.histogram("sone.parsing.duration") (0..4000).forEach(histogram::update) -- 2.7.4