SpringBoot应用对监控要求不是高,能够采用 SpringBootAdmin就能够搞定,可是若是须要长期,而且但愿后期能优化应用,提升平台抗风险性时,可使用InfluxDB保存应用的性能度量数据。mysql
InfluxDB能够支持海量数据存储正则表达式
Grafana能够显示不一样维度的数据spring
生成 SpringBoot Sample 项目地址 https://start.spring.io/sql
<!---收集各类性能指标插件--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!---经过此插件直接写数据到Influx DB--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-influx</artifactId> </dependency>
management: metrics: export: influx: enabled: true db: coursemetrics uri: http://localhost:8086 user-name: admin password: admin connect-timeout: 1s read-timeout: 10s auto-create-db: true step: 1m num-threads: 2 consistency: one compressed: true batch-size: 10000 ## 地址 uri: http://localhost:8086 ## InFluxDB 用户 user-name: admin (是否是须要配置具备管理角色的用户未测试) ## InFluxDB 密码 password: admin ## 配置参考 https://micrometer.io/docs/registry/influx
Telegraf插件是收集各个中间件性能指标插件 支持监控的产品有好多。
windows
本人没有搞懂怎么使用呢,很差意思!服务器
influxd.ext
## 经过搜索修改 [meta] # Where the metadata/raft database is stored dir = "D:/Program Files/influxdb-1.7.6-1/meta" [data] # The directory where the TSM storage engine stores TSM files. dir = "D:/Program Files/influxdb-1.7.6-1/data" # The directory where the TSM storage engine stores WAL files. wal-dir = "D:/Program Files/influxdb-1.7.6-1/wal" # log any sensitive data contained within a query. query-log-enabled = true [coordinator] # can help prevent run away queries. Setting the value to 0 disables the limit. query-timeout = "0s" [retention] # The interval of time when retention policy enforcement checks run. check-interval = "30m" [shard-precreation] # Determines whether shard pre-creation service is enabled. enabled = true # The interval of time when the check to pre-create new shards runs. check-interval = "10m" # The default period ahead of the endtime of a shard group that its successor # group is created. advance-period = "30m" [monitor] # Whether to record statistics internally. store-enabled = true # The destination database for recorded statistics store-database = "_internal" # The interval at which to record statistics store-interval = "10s" [http] # Determines whether HTTP endpoint is enabled. enabled = true # The bind address used by the HTTP service. bind-address = ":8086"
要说有什么特别的,倒没注意,就是搬运工spring-boot
重启 InfluxDB 服务器性能
经过influx命令进行管理,可使用以下命令建立数据库:测试
> CREATE DATABASE "testDB" > show databases //查询当前的全部数据库 > show databases name: databases --------------- name _internal testDB > use testDB //使用某个数据库
建库的操做能够发现很是相似于mysql下的操做。而在influxdb下没有细分的表的概念,influxdb下的表在插入数据库的时候自动会建立。能够经过SHOW measurements命令查看全部的表,这个相似于mysql下的show tables; 。
> INSERT cpu,host=serverA,region=us_west value=0.64 //在cpu表中插入相关的数据 > SELECT * FROM cpu ORDER BY time DESC LIMIT 3 //查询最近的三条数据 > SELECT * FROM /.*/ LIMIT 1 //正则表达式查询 > delete from cpu where time=1480235366557373922 //删除某条数据 > DROP MEASUREMENT "measurementName" //删除表
update更新语句没有,不过有alter命令,在influxdb中,删除操做用和更新基本不用到 。在针对数据保存策略方面,有一个特殊的删除方式,这个后面再提。
关于用户的操做以下:
#显示用户 SHOW USERS #建立用户 CREATE USER "username" WITH PASSWORD 'password' #建立管理员权限的用户 CREATE USER "username" WITH PASSWORD 'password' WITH ALL PRIVILEGES #删除用户 DROP USER "username"
简单的列一下,够用就行。具体请参考官网 InfluxDB官方文档
> show databases name: databases name ---- _internal courselog mydb coursemetrics >
Win 平台直接点击下一步,就OK。登录帐号 admin/admin,若不对去看看官方文档
访问地址:http://localhost:3000 若不对看启动日志
配置好数据源:
绘制图表
预览全部图表
整个过程也很简单,也耗了很多时间。在此作个笔记。