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 若不對看啓動日誌
配置好數據源:
繪製圖表
預覽全部圖表
整個過程也很簡單,也耗了很多時間。在此作個筆記。