play-actuator

CI Renovate Licence

Play! Framework plugin with actuator routes that gives you infos about application uptime. You may consider some indicators to define what is Up or Down for your (check more info at Health endpoint details).

This project is inspired by Spring Boot Actuator architecture (Check this post to know more about it) .

How to use?

Version

You can import as a project dependency in your build.sbt file. Pick the suffix that matches the Play major your application is on (see Cross-building below).

  // Play 2.9 (existing, unsuffixed coordinates - no migration needed)
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator" % "(version)"

  // Play 3.0 (new)
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator_play30" % "(version)"

After that, you need to configure play.actuator.ActuatorRouter into project conf/routes file.

->      /actuator      play.actuator.ActuatorRouter

Run your project and check Actuators endpoints - e.g. /actuator/health.

Actuator endpoints

Below we have all project endpoints available on this project.

Endpoint ID Description Path Ready to use?
health Aggregated health (all active indicators). /actuator/health ✔️
health (liveness) Kubernetes liveness probe (default: diskSpace only). /actuator/health/liveness ✔️
health (readiness) Kubernetes readiness probe (default: external deps). /actuator/health/readiness ✔️
health (group) Any user-defined group from play.actuator.health.groups. /actuator/health/<group> ✔️
info Displays information about your application. /actuator/info ✔️
metrics List/inspect Micrometer meters (opt-in module). /actuator/metrics ✔️
prometheus Prometheus exposition (opt-in module). /actuator/metrics/prometheus ✔️
logfile Returns the contents of the log file. /actuator/logfile ✖️

Health endpoints return HTTP 200 when the aggregated status is UP and HTTP 503 when any included indicator is DOWN — so Kubernetes liveness and readiness probes work out of the box. Unknown group names return HTTP 404.

Health endpoint details

You can check all health indicators by simple activating each configuration.

Disk Space Indicator

Show to you the total, free and usable disk space.

No need of any extra dependency, it's under the hood.

play.actuator.health.indicators.diskSpace = true

Database Indicator

Show to you information about your database using JDBC or Slick connection.

play.actuator.health.indicators.database = true

It depends on which dependency indicator you'll use. You need to choose only one dependency to work with!

JDBC

  // Play 2.9
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-jdbc-indicator" % "(version)"
  // Play 3.0
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-jdbc-indicator_play30" % "(version)"

Slick

  // Play 2.9
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-slick-indicator" % "(version)"
  // Play 3.0
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-slick-indicator_play30" % "(version)"

Redis Indicator

Show to you information about your Redis connection. For now, it only works with play-redis as your connector.

play.actuator.health.indicators.redis = true

  // Play 2.9
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-redis-indicator" % "(version)"
  // Play 3.0
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-redis-indicator_play30" % "(version)"

Health groups (liveness / readiness)

play-actuator ships with two opinionated default groups so Kubernetes probes work without any extra configuration:

Group Default indicators Suitable for
liveness diskSpace only livenessProbe
readiness everything except diskSpace readinessProbe

Both can be overridden in application.conf. You can also define arbitrary custom groups (each becomes a new /actuator/health/<name> endpoint):

play.actuator.health.groups {
  liveness  { include = ["diskSpace"] }
  readiness { exclude = ["diskSpace"] }

  # any user-defined group
  storage   { include = ["database"]  }
}

include is a whitelist (empty means "all indicators"). exclude always subtracts from the include set.

Metrics endpoint details

Add the optional metrics module to expose Micrometer-based JVM metrics and a Prometheus scrape endpoint.

  // Play 2.9
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-metrics" % "(version)"
  // Play 3.0
  libraryDependencies += "io.github.felipebonezi" %% "play-actuator-metrics_play30" % "(version)"

Then mount the metrics sub-router in conf/routes alongside the main actuator router:

->   /actuator           play.actuator.ActuatorRouter
->   /actuator/metrics   play.actuator.metrics.MetricsRouter

This exposes:

Method + path Returns
GET /actuator/metrics JSON list of meter names
GET /actuator/metrics/<name> JSON detail (measurements + available tags)
GET /actuator/metrics/prometheus text/plain Prometheus exposition format

JVM and system meter binders (memory, GC, threads, classloader, processor, uptime, file descriptors) are registered eagerly at startup and can be turned off individually under play.actuator.metrics.bindings.*. Apply common tags to every meter (e.g. application/env) via play.actuator.metrics.common-tags { … }.

Info endpoint details

You can enable to get all operational system info inside the JSON return by /actuator/info route. Default is disabled.

play.actuator.info.system.enabled = true

Cross-building

play-actuator is published for two Play majors. Pick the coordinate suffix that matches the Play version your application is on:

Your Play Coordinate suffix Scala
2.9.x (none, unsuffixed) 2.13
3.0.x _play30 2.13 or 3.3

The Play 2.9 axis continues to publish under the original, unsuffixed coordinates — existing consumers do not need to update their libraryDependencies strings when they pick up a new release. Only the new Play 3.0 axis introduces a coordinate suffix.

For local development, switch axes with the play.version JVM property (or the equivalent PLAY_VERSION env var). The default is Play 2.9:

sbt -Dplay.version=2.9 ++2.13.18 compile test    # Play 2.9 / Scala 2.13
sbt -Dplay.version=3.0 ++2.13.18 compile test    # Play 3.0 / Scala 2.13
sbt -Dplay.version=3.0 ++3.3.6   compile test    # Play 3.0 / Scala 3

Scala compatibility

This project is published for Scala 2.13 on both Play axes, plus Scala 3.3 (LTS) on the Play 3.0 axis.

Sponsors & Backers

If you find Play Actuator useful to you, please consider become a backer. If your company seems to feel the same, please consider become a sponsor.

Thank you to all our backers on OpenCollective!