This is just an example of how to monitor a playframework application using:
- prometheus client
- prometheus
- grafana
To run everything you just need docker
.
Before running this command be aware that the docker files are quite heavy, so this could take a while
docker-compose up -d
....and everything should be up and running. Something similar to this image
Which means that we have now 4 running containers:
- Grafana
- CAdvisor
- Our play application
- Prometheus
The play application is available at http://localhost:9000/
.
The general idea is that the application has a count metric for a particular url
val requests = Counter.build()
.name("play_requests_total")
.help("Total requests.")
.register()
which gets increased each time a user navigates to /
@Singleton
class HomeController @Inject()(visitsCounter: IndexAccessCounter) extends Controller {
def index = Action {
visitsCounter.requests.inc()
Ok(views.html.index("Your new application is ready."))
}
}
Just in case, don't forget to add the following script to your build.sbt
javaOptions in Universal ++= Seq(
"-Dpidfile.path=/dev/null"
)
This is a workaroung as the application inside the container is no able to restart because the play app always has the same PID.
In order to verify that prometheus was able to connect to out application you can check http://localhost:9090/targets
Theoretically you should have:
- a target for our play application
- a target for prometheus itself
Before testing the integration between prometheus and grafana you can verify your metrics by going to http://localhost:9090/graph
.
You should be able to get something like this
The Dashboard is now available at http://localhost:3000
using the following credentials
- username: admin
- password: admin
The password is stored in the config.monitoring
env file.
Once logged in you need to:
Now we need to create the Prometheus Datasource in order to connect Grafana to Prometheus
- Go to Grafana Menu at the top left corner (looks like a fireball)
- Go to Data Sources
- Enter the following data
Import the file Grafana_Dashboard.json
Your resulting Dashboard should be similar to this
Don't forget to go to http://localhost:9000/
and check how your dashboards changes.