This play library provides four types of filters that collect prometheus metrics.
Two of these filters are also compatible with the lagom framework.
A simple hello world application using these filters can be found in the following repo: https://github.com/stijndehaes/play-prometheus-filters-example-app
To use the library add the following to you build.sbt:
libraryDependencies += "com.github.stijndehaes" %% "play-prometheus-filters" % "0.3.0"
This version only supports play 2.6. For more info on play version compatibility see the releases matrix.
Release | Play version |
---|---|
0.1.x | 2.5.x |
0.2.x | 2.5.x |
0.3.x | 2.6.x |
This filter counts all the requests in your application and adds a label for the status. This filter is compatible with the lagom framework.
This filter collects the latency of all requests. This filter is compatible with the lagom framework.
This filter collects the latency for all requests and adds a label called RouteActionMethod. This action method is the method name of the method you provided your routes file. This filter makes it possible to measure the latency for all your routes. This filter is not compatible with the lagom framework, since it does not provide the RouteActionMethod.
This filter collects the latency for all requests, adds a label called RouteActionMethod and a label called status. This action method is the method name of the method you provided your routes file. This filter makes it possible to measure the latency for all your routes and the status of the response for this route. It thus combines all the above filters into one. This filter is not compatible with the lagom framework, since it does not provide the RouteActionMethod.
Example:
GET /metrics play.prometheus.controllers.PrometheusController.getMetrics
The RouteActionMethod for the above example would be getMetrics
See the documentation of play
You should make a filters class:
import javax.inject.Inject
import play.api.http.DefaultHttpFilters
import play.prometheus.filters.LatencyFilter
import play.prometheus.filters.StatusCounterFilter
class MyFilters @Inject() (
latencyFilter: LatencyFilter,
statusCounterFilter: StatusCounterFilter
) extends DefaultHttpFilters(latencyFilter, statusCounterFilter)
And the enable this filter in the application.conf
play.http.filters=com.example.MyFilters
The project also provides a prometheus controller with a get metric method. If you add the following to your routes file:
GET /metrics play.prometheus.controllers.PrometheusController.getMetrics
You should be able to immediately get the metrics