influxdb java maven,springboot2输出metrics到influxdb

本文主要研究一下如何将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 influx

create database springboot

rest接口创建

curl -i -X POST http://192.168.99.100:8086/query --data-urlencode "q=CREATE DATABASE springboot"

返回

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}]}

或者直接配置文件指定auto-create-db=true,就无需额外创建

查看

命令行查看

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

查看具体指标

> 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

注意这里表名要加引号

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,然后进行配置即可。

doc

转载至链接:https://my.oschina.net/go4it/blog/1831547

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值