Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Enables pan-app request metrics in the example-play app.
Browse files Browse the repository at this point in the history
I think this is the canonical way to enable these metrics. It's worth
noting that the metrics previously set up in Global.scala weren't actually
getting displayed anywhere, as they weren't being passed into the
constructor of the management StatusPage.

Also use internal Management server (port 18080) for example-play app -
this makes it easy to do request metrics that cover the entire app,
but not count requests to the management urls themselves.
  • Loading branch information
rtyley committed Nov 22, 2012
1 parent 5c46a55 commit f801e8d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
14 changes: 9 additions & 5 deletions example-play/app/Global.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import com.gu.management.play.{ OkCounter, RequestTimer }
import com.gu.management.{ TimingMetric, CountMetric }
import com.gu.management.play.{ StatusCounters, RequestTimer }
import play.api.GlobalSettings

object Global extends GlobalSettings with RequestTimer with OkCounter {
override val okCounter = new CountMetric("status", "200_ok", "Status OK", "requests that return a status of 200")
override val requestTimer = new TimingMetric("performance", "request", "Request", "time taken to serve requests")
object Global extends GlobalSettings with RequestTimer with StatusCounters {
import conf.RequestMetrics._

override val okCounter = Request200s
override val errorCounter = Request50xs
override val notFoundCounter = Request404s
override val redirectCounter = Request30xs
override val requestTimer = conf.TimingMetrics.requests
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controllers
package conf

import com.gu.management._
import com.gu.management.play.ManagementController
Expand All @@ -18,6 +18,16 @@ object Switches {
val all = List(omniture, takeItDown, Healthcheck.switch)
}

object RequestMetrics {
object Request200s extends CountMetric("request-status", "200_ok", "200 Ok", "number of pages that responded 200")
object Request50xs extends CountMetric("request-status", "50x_error", "50x Error", "number of pages that responded 50x")
object Request404s extends CountMetric("request-status", "404_not_found", "404 Not found", "number of pages that responded 404")
object Request30xs extends CountMetric("request-status", "30x_redirect", "30x Redirect", "number of pages that responded with a redirect")
object RequestOther extends CountMetric("request-status", "other", "Other", "number of pages that responded with an unexpected status code")

val all = List(Request200s, Request50xs, Request404s, RequestOther, Request30xs)
}

// timing stuff
object TimingMetrics {
val downtime = new TimingMetric("example", "downtime", "downtime", "Amount of downtime")
Expand All @@ -33,13 +43,13 @@ object Properties {
val all = "key1=value1\nkey2=value2"
}

object Management extends ManagementController {
object Management extends com.gu.management.play.Management {
val applicationName: String = "Example Play App"
lazy val pages = List(
new DummyPage(),
new ManifestPage(),
new Switchboard(applicationName, Switches.all),
StatusPage(applicationName, ExceptionCountMetric :: ServerErrorCounter :: ClientErrorCounter :: TimingMetrics.all),
StatusPage(applicationName, ExceptionCountMetric :: ServerErrorCounter :: ClientErrorCounter :: TimingMetrics.all ::: RequestMetrics.all),
new HealthcheckManagementPage(),
new PropertiesPage(Properties.all),
new LogbackLevelPage(applicationName)
Expand Down
8 changes: 3 additions & 5 deletions example-play/app/controllers/ScalaApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import play.api.libs.concurrent.Akka

object ScalaApp extends Controller {
def apply() = Action {
TimingMetrics.requests measure {
Switches.takeItDown match {
case On() => InternalServerError("Temporarily switched off!")
case _ => Ok("Thank you for invoking this app!")
}
conf.Switches.takeItDown match {
case On() => InternalServerError("Temporarily switched off!")
case _ => Ok("Thank you for invoking this app!")
}
}

Expand Down
1 change: 1 addition & 0 deletions example-play/conf/play.plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000:com.gu.management.play.InternalManagementPlugin
2 changes: 0 additions & 2 deletions example-play/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ GET /scala-app controllers.ScalaApp.apply()
GET /scala-app/long controllers.ScalaApp.long()
GET /scala-app/exception controllers.ScalaApp.exception()
GET /scala-app/async controllers.ScalaApp.async()
GET /management$path<.*> controllers.Management.apply(path)
POST /management$path<.*> controllers.Management.apply(path)

0 comments on commit f801e8d

Please sign in to comment.