序
本文主要研究一下如何将springboot2的metrics输出到influxdb
maven
org.springframework.boot spring-boot-starter-actuator io.micrometer micrometer-registry-influx
配置
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
启动之后创建数据库
- 命令行创建
docker exec -it influx influxcreate database springboot
- rest接口创建
curl -i -X POST http://192.168.99.100:8086/query --data-urlencode "q=CREATE DATABASE springboot"
返回
HTTP/1.1 200 OKContent-Type: application/jsonRequest-Id: f3ce7449-7227-11e8-8002-000000000000X-Influxdb-Build: OSSX-Influxdb-Version: 1.5.3X-Request-Id: f3ce7449-7227-11e8-8002-000000000000Date: Sun, 17 Jun 2018 12:14:15 GMTTransfer-Encoding: chunked{"results":[{"statement_id":0}]}
或者直接配置文件指定auto-create-db=true,就无需额外创建
查看
- 命令行查看
docker exec -it influx influx> use springboot> show MEASUREMENTSname: measurementsname----jvm.buffer.countjvm.buffer.memory.usedjvm.buffer.total.capacityjvm.classes.loadedjvm.classes.unloadedjvm.gc.live.data.sizejvm.gc.max.data.sizejvm.gc.memory.allocatedjvm.gc.memory.promotedjvm.gc.pausejvm.memory.committedjvm.memory.maxjvm.memory.usedjvm.threads.daemonjvm.threads.livejvm.threads.peaklogback.eventsprocess.cpu.usageprocess.files.maxprocess.files.openprocess.start.timeprocess.uptimesystem.cpu.countsystem.cpu.usagesystem.load.average.1m
查看具体指标
> 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.requeststime count exception mean method metric_type status sum upper uri---- ----- --------- ---- ------ ----------- ------ --- ----- ---1529238292912000000 0 None 0 GET histogram 200 0 72.601487 /actuator/health1529238352888000000 2 None 39.154634 GET histogram 200 78.309267 72.601487 /actuator/health1529238412886000000 0 None 0 GET histogram 200 0 72.601487 /actuator/health1529238472885000000 0 None 0 GET histogram 200 0 0 /actuator/health1529238532882000000 0 None 0 GET histogram 200 0 0 /actuator/health1529238592879000000 0 None 0 GET histogram 200 0 0 /actuator/health
注意这里表名要加引号
- rest接口查看
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 } ]}
小结
springboot2使用micrometer作为metrics组件,其提供了对influxdb的支持,只需要引入micrometer-registry-influx,然后进行配置即可。