App Metrics監控需要安裝InfluxDB時序數據庫和Grafana可視化分析工具
1.安裝InfluxDB
下載地址:https://portal.influxdata.com/downloads/#influxdb
我這里下載的是Windows版本的。
解壓influxdb,編輯influxdb.conf,配置相關路徑
[meta] # Where the metadata/raft database is stored dir = "D:/influxdb/meta" [data] # The directory where the TSM storage engine stores TSM files. dir = "D:/influxdb/data" # The directory where the TSM storage engine stores WAL files. wal-dir = "D:/influxdb/wal"
配置http,第一次配置先將權限auth-enabled配置為false
[http] # Determines whether HTTP endpoint is enabled. enabled = true # Determines whether the Flux query endpoint is enabled. # flux-enabled = false # Determines whether the Flux query logging is enabled. # flux-log-enabled = false # The bind address used by the HTTP service. bind-address = ":8086" # Determines whether user authentication is enabled over HTTP/HTTPS. auth-enabled = false
用命令行進入當前influxdb目錄,執行命令
influxd -config influxdb.conf
另開一個控制台命令行進入influxdb目錄設置用戶名和密碼,運行命令:influx,連接到influx服務器
創建用戶命令:
create user "use_name" with password 'user_password'
#創建用戶並添加管理員權限
create user "admin" with password '123456' with all privileges
顯示所有用戶命令
show users
刪除用戶命令
drop user "user_name"
其他命令:
# 給普通用戶授予管理員權限 GRANT ALL PRIVILEGES TO "user_name" # 給用戶指定數據庫操作權限 GRANT [READ,WRITE,ALL] ON <database_name> TO <username> GRANT ALL ON test TO "user_name" # 撤回用戶的管理員權限 REVOKE ALL PRIVILEGES FROM "user_name" # 查看用戶權限 show grants for "user_ame" # 修改密碼 set password for "user_name" = '123456789'
influxdb相關操作:https://www.jianshu.com/p/d9a16b42aa9f
然后將權限auth-enabled配置為true,關閉influxd命令的控制台,重新啟動influxdb。
控制台命令行登錄influxdb:
influx -host 127.0.0.1 -port 8086 -username "admin" -password "123456"
使用命令創建數據庫:
CREATE DATABASE "AppMetricsDemo"
創建數據庫可以使用數據庫連接工具InfluxDBStudio,
InfluxDBStudio下載地址:https://github.com/CymaticLabs/InfluxDBStudio/releases
使用InfluxDBStudio連接數據庫:
2.安裝Grafana
Grafana下載地址:https://grafana.com/get
下載開源版本的壓縮包,或者Windows安裝程序。
解壓后運行grafana-server.exe
瀏覽器打開web版:http://localhost:3000
下載App Metrics的json監控配置文件,下載地址:https://grafana.com/grafana/dashboards/2140/revisions
然后導入App Metrics的Web Monitoring json配置文件
導入成功后就顯示了實時監控的界面
配置數據源,選擇Data Sources ->Add data source,選擇InfluxDB
如果儀表盤沒有數據源,則把儀表盤的數據源復制到datasource回車
3.在項目中添加App Metrics