Table of Contents |
---|
Description
Rancher 2 already incorporates Prometheus and Grafana for metrics and alerts.
By default it incorporates a set of metrics and Dashboards from CaaS itself (Clusters with their nodes, workloads (, allowing to reach down to POD level) and internal Rancher services.
But you can also use Rancher’s Prometheus and Grafana to monitor business metrics of the microservices deployed in Rancher.
In Spring Boot applications, it is very easy to monitor these metrics using Spring Boot Actuator and Micrometer.
To do that:
Prepare applications with the metrics to be monitored:
Incorporate the Spring boot Actuator and Micrometer starter into your project’s dependencies:
In the code, use Micrometer components to record the business metrics you need. You can see them here: https://micrometer.io/docs/concepts or get a faster idea here: https://www.baeldung.com/micrometer. In summary, you have Counters for incremental values, Gauges for simple values, Timers or Long Timers to measure times of events and their occurrences, and Distribution SumariesSummaries, which are similar to Timers but to measure events that are not of time. As an example, you can create a controller that uses a counter to measure the number of requests that are made, and a Gauge and a Timer that make up random values:
In the configuration, specify to the Spring Actuator, that you are exposing the Prometheus’s endpoint for Spring Actuator. With this, the Prometheus server can question your application.
Verify that, with this configuration, the Prometheus endpoint is exposed and your metrics appear.
Enable monitoring in Rancher 2:
The next point is to integrate your monitoring service with Rancher 2. To do this, you must enable monitoring in your project.
Note: Cluster-level monitoring is different than Project-level one, using different Prometheus and Grafana services (created by Rancher 2). Thus, having Cluster monitoring enabled is not synonymous with having it enabled at Project level, which is what you need to monitor your business metrics.
The steps to integrate your application in monitoring are:
Enable the monitoring of your project in Rancher. Select your Project:
Under Tools > Monitoring, enable monitoring:
This creates a new namespace in your project with the Prometheus and Grafana services necessary for the monitoring.
Specify in the applications where you have a Prometheus endpoint exposing business metrics, using the url of that endpoint. To do this, when you enable monitoring, a new entry (under Advanced Options) has been added to the options of your workloads (applications), to register this endpoint there:
Use the metrics:
If you select the Apps tab, you will see that a new monitoring application has been created.
If you access it, you will see that, among other information, it provides the Prometheus and Grafana urls that monitor your project:
So that, if you enter the Prometheus, you can already search and see your metrics:
And if you enter the Grafana (default password admin/admin, but it forces you to change it when entering), you can use these metrics to create a Dashboard: