Metrics

To really get operational, we need metrics. Most production systems have metrics in one form or another. Thankfully, we don't have to start from scratch. There is a metric endpoint in Spring Boot Actuator. If we add this following setting to application.properties:

    endpoints.metrics.enabled=true

With this property setting, if we restart the application, we can get a quick read out on thing.

Assuming we have JSON Viewer installed, it's easy to surf to http://localhost:9000/application/metrics and get a listing on all sorts of metrics. We even have counters for every good/bad web hit, broken down on a per-page basis, as shown here:

    {
"names": [
"jvm.buffer.memory.used",
"jvm.memory.used",
"jvm.buffer.count",
"logback.events",
"process.uptime",
"jvm.memory.committed",
"jvm.buffer.total.capacity",
"jvm.memory.max",
"process.starttime",
"http.server.requests"
]
}

We can visit any one of these metrics by appending it's name to the metrics URL. For example, to view the http.server.requests, visit http://localhost:9000/application/metrics/http.server.requests:

    {
"name": "http.server.requests",
"measurements": [
{
"statistic": "TotalTime",
"value": 3.53531643E8
},
{
"statistic": "Count",
"value": 57.0
}
],
"availableTags": [
{
"tag": "exception",
"values": [
"none",
"none",
"none",
"none"
]
},
{
"tag": "method",
"values": [
"GET",
"GET",
"GET",
"GET"
]
},
{
"tag": "uri",
"values": [
"/application/metrics/{requiredMetricName}",
"/application/metrics/{requiredMetricName}",
"/application/metrics",
"/favicon.ico"
]
},
{
"tag": "status",
"values": [
"200",
"404",
"200",
"200"
]
}
]
}

This provides a basic framework of metrics to satisfy our manager's needs. It's important to understand that metrics gathered by Spring Boot Actuator aren't persistent across application restarts. To gather long-term data, we have to write them elsewhere (http://docs.spring.io/spring-boot/docs/2.0.0.M5/reference/htmlsingle/#production-ready-metrics).

If you have used Spring Boot 1.x, then this may look very different. That's because a newer, more sophisticated version of metrics has arrived-- Micrometer. It's currently in development, and may change quite a bit, so stay tuned at http://micrometer.io/, and be sure to follow @micrometerio on Twitter, as the ability to craft highly detailed and advanced metrics comes to Spring Boot.