[case24]springboot2 outputs metrics to influxdb

  springboot

Order

This article mainly studies how to output metrics of springboot2 to influxdb.

maven

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-influx</artifactId>
        </dependency>

Configuration

management:
  metrics:
    export:
      influx:
        enabled: true
        db: springboot
        uri: http://192.168.99.100:8086
#        user-name:
#        password:
        connect-timeout: 1s
        read-timeout: 10s
        auto-create-db: true
        step: 1m
        num-threads: 2
        consistency: one
        compressed: true
        batch-size: 10000

influx

docker run -d --name influx -p 8086:8086 influxdb

Create database after startup

  • Command line creation
docker exec -it influx influx
create database springboot
  • Rest interface creation
curl -i -X POST http://192.168.99.100:8086/query --data-urlencode "q=CREATE DATABASE springboot"

Return

HTTP/1.1 200 OK
Content-Type: application/json
Request-Id: f3ce7449-7227-11e8-8002-000000000000
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.5.3
X-Request-Id: f3ce7449-7227-11e8-8002-000000000000
Date: Sun, 17 Jun 2018 12:14:15 GMT
Transfer-Encoding: chunked

{"results":[{"statement_id":0}]}

Or the direct configuration file specifies auto-create-db=true, no additional creation is required

examine

  • Command line view
docker exec -it influx influx
> use springboot
> show MEASUREMENTS
name: measurements
name
----
jvm.buffer.count
jvm.buffer.memory.used
jvm.buffer.total.capacity
jvm.classes.loaded
jvm.classes.unloaded
jvm.gc.live.data.size
jvm.gc.max.data.size
jvm.gc.memory.allocated
jvm.gc.memory.promoted
jvm.gc.pause
jvm.memory.committed
jvm.memory.max
jvm.memory.used
jvm.threads.daemon
jvm.threads.live
jvm.threads.peak
logback.events
process.cpu.usage
process.files.max
process.files.open
process.start.time
process.uptime
system.cpu.count
system.cpu.usage
system.load.average.1m

Look at specific indicators

> show series from "http.server.requests"
key
---
http.server.requests,exception=None,method=GET,metric_type=histogram,status=200,uri=/actuator/health
> select * from "http.server.requests"
name: http.server.requests
time                count exception mean      method metric_type status sum       upper     uri
----                ----- --------- ----      ------ ----------- ------ ---       -----     ---
1529238292912000000 0     None      0         GET    histogram   200    0         72.601487 /actuator/health
1529238352888000000 2     None      39.154634 GET    histogram   200    78.309267 72.601487 /actuator/health
1529238412886000000 0     None      0         GET    histogram   200    0         72.601487 /actuator/health
1529238472885000000 0     None      0         GET    histogram   200    0         0         /actuator/health
1529238532882000000 0     None      0         GET    histogram   200    0         0         /actuator/health
1529238592879000000 0     None      0         GET    histogram   200    0         0         /actuator/health

Note that the table name should be quoted here.

  • Rest interface view
curl -G 'http://192.168.99.100:8086/query?pretty=true' --data-urlencode "db=springboot" --data-urlencode "q=SELECT \"*\" FROM \"http.server.requests\""
{
    "results": [
        {
            "statement_id": 0
        }
    ]
}

Summary

Springboot2 uses micrometer as a metrics component, which provides support for influxdb. All it needs to do is introduce micrometer-registry-influx and configure it.

doc