Play 2.1
Filters aren't heavily documented yet, so I thought some might like to see an example of their use - we've just updated our management-and-metrics library at the Guardian ("
guardian-management") to use Play 2.1 Filters. The Filters framework makes it very easy for us to gather timing and http-status-code statistics on the responses we're passing back to the user. The filters are defined here:
They're extremely simple, perhaps the only thing worth watching out for is the use of
onFinalPlainResult() against the Scala 2.10 Future used by AsyncResult, ensuring we only time & count the response once it's fully completed.
The library includes an example of it's use in a example Play project:
The statistics are then available as a JSON endpoint on a separate port (eg localhost:18080/management/status, while your Play app might be running on port 9000). This makes it easy to keep the stats private, and also ensures that hitting the management & status urls won't increment the stats themselves. Finally, the stats are read by a monitoring service like
Graphite/
Ganglia.
best regards,
Roberto Tyley