In the previous steps, we have explored how to send logs to a centralized server so that activity across multiple services can be viewed on the same screen. In this step, we are going to set up metrics from the petstore to send it to InfluxDB and then subsequently viewed from Chronograf UI.
To start InfluxDB, Chronograf and Kapacitor, a docker-compose file will be used from the light-docker repository.
Now let’s start all services defined in the docker-compose-metrics.yml
docker-compose -f docker-compose-metrics.yml up
First, let’s make sure that InfluxDB and Chronograf can be accessed.
Make sure Chronograf admin page is shown up and connect to the metrics database.
You need to change the URL from http://localhost:8086 to http://influxdb:8086 and set the database name to metrics.
The user is root, and the password is root as well.
Once both Influxdb and Chronograf are up and running, let’s stop the open API petstore container by issuing “docker ps” on another terminal to find out the container_id of the petstore. Note: several docker containers are running, so double check you have picked the right container_id.
Now run the following command to stop the example petstore
docker stop [container_id of petstore]
In the next step, we will start the same container with an externalized metrics config so that the server can connect to the Influxdb container to report the metrics.
To make it simple, we are going to use docker-compose from light-config-test.
There is a folder at ~/networknt/light-config-test/light-example-4j/rest/openapi/petstore/metrics with security.yml and metrics.yml
Go to http://localhost:8888/ and select metrics database and select “SHOW MEASUREMENTS”. You will find several measurements created. Some of them are for the API view, and some of them are for the client view.
You can use Grafana to connect to InfluxDB and create dashboards on Grafana to visualize the metrics in production.
In this step, we have enabled metrics so that we can have a centralized metrics connection at runtime.