Centos7 MyPerf4J安裝配置及可視化頁面

Centos7 MyPerf4J安裝配置及可視化頁面

一個針對高併發、低延遲應用設計的高性能 Java 性能監控和統計工具。 MyPerf4J 採用 JavaAgent 配置方式,透明化接入應用,對應用代碼徹底沒有侵入。java

參考:MyPerf4Jgit

1、特性

  • 高性能: 單線程支持每秒 1000 萬次 響應時間的記錄,每次記錄只花費 73 納秒
  • 無侵入: 採用 JavaAgent 方式,對應用程序徹底無侵入,無需修改應用代碼
  • 低內存: 採用內存複用的方式,整個生命週期只產生極少的臨時對象,不影響應用程序的 GC
  • 高精度: 採用納秒來計算響應時間
  • 高實時: 支持秒級監控,最低 1 秒

2、使用場景

  • 在開發環境中快速定位 Java 應用程序的性能瓶頸
  • 在生產環境中長期監控 Java 應用程序的性能指標

3、安裝

1. 打包

若是你使用的是JDK7或者更高版本,能夠嘗試直接下載MyPerf4J-ASM.jar 能夠忽略打包步驟github

git clone git@github.com:LinShunKang/MyPerf4J.git
mvn clean package
把 /MyPerf4J-develop/MyPerf4J-ASM/target/MyPerf4J-ASM-${MyPerf4J-version}.jar 重命名爲 MyPerf4J-ASM.jar

2. 配置

FlowProcessAgent配置文件:shell

#應用名稱
AppName=FlowProcessAgent

#MetricsProcessor類型,0:以標準格式化結構輸出到stdout.log 1:以標準格式化結構輸出到磁盤  2:以InfluxDB LineProtocol格式輸出到磁盤
MetricsProcessorType=2

#配置各個Metrics日誌的文件路徑,可不配置
MethodMetricsFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/method_metrics.log
ClassMetricsFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/class_metrics.log
GCMetricsFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/gc_metrics.log
MemMetricsFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/memory_metrics.log
BufPoolMetricsFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/buf_pool_metrics
ThreadMetricsFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/thread_metrics.log

#配置Record模式,可配置爲accurate/rough
RecorderMode=accurate

#配置時間片,單位爲ms,最小1s,最大600s
MilliTimeSlice=1000

#須要監控的package,可配置多個,用英文';'分隔
IncludePackages=quaqu.*

#是否展現方法參數類型
ShowMethodParams=true
#配置通用的方法響應時間閾值,單位爲 ms
ProfilingTimeThreshold = 1

配置說明vim

注意:使用Windows系統的,請修改路徑格式。bash

在 JVM 啓動參數里加上如下兩個參數:併發

  • -javaagent:/your/path/to/MyPerf4J-ASM.jar
  • -DMyPerf4JPropFile=/your/path/to/myPerf4J.properties

例如:ide

java -javaagent:/home/lwenhao/MyPerf4J/FlowProcessAgent/MyPerf4J-ASM.jar -DMyPerf4JPropFile=/home/lwenhao/MyPerf4J/FlowProcessAgent/FlowProcessAgent -jar FlowProcessAgent.jar

4、安裝配置InfluxDB

MyPerf4J 默認支持使用 InfluxDB 進行數據存儲高併發

  • MyPerf4J 向用戶指定的日誌文件中寫入 LineProtocol 格式的性能統計數據
  • 經過日誌收集器 Telegraf 從日誌文件中讀取數據並導入 InfluxDB 中。 具體步驟以下:
  • 配置 MetricsProcessorType=2
  • InfluxDB

1.安裝 InfluxDB

注意:安裝InfluxDB軟件包,須要root或具備管理員權限才能成功完成工具

新建/etc/yum.repos.d/influxdb.repo

[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key

安裝

yum install influxdb

配置環境變量

vim /etc/profile

添加:export INFLUXDB_CONFIG_PATH=/etc/influxdb/influxdb.conf

source .bash_profile

[root[@lwh](https://my.oschina.net/bnulwh) ~]# echo $INFLUXDB_CONFIG_PATH
/etc/influxdb/influxdb.conf

編輯/etc/influxdb/influxdb.conf

主要修改一下:

[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

  # The default realm sent back when issuing a basic auth challenge.
  realm = "InfluxDB"

  # Determines whether HTTP request logging is enabled.
  log-enabled = true

確保存儲數據和預寫日誌(WAL)的目錄對於運行該influxd服務的用戶是可寫的。 注意:當前是沒有密碼驗證的

啓動

systemctl start influxdb

檢查是否啓動

[root[@lwh](https://my.oschina.net/bnulwh) /]# influx
Connected to http://localhost:8086 version 1.7.4
InfluxDB shell version: 1.7.4
Enter an InfluxQL query
> show databases
name: databases
name
----
_internal
>

5、安裝配置Telegraf

telegrafv1.9

MyPerf4J 自己不訪問 InfluxDB,而是經過把統計數據寫入日誌文件中,經過 Telegraf 把統計數據導入 InfluxDB 中。

安裝

若是上面/etc/yum.repos.d/influxdb.repo文件已建立,則直接執行:

yum install telegraf

編輯/etc/telegraf/telegraf.conf

# Global tags can be specified here in key="value" format.
[global_tags]
  dc = ""

# Configuration for telegraf agent
[agent]
  ## Default data collection interval for all inputs
  interval = "1s"
  ## Rounds collection interval to 'interval'
  ## ie, if interval="10s" then always collect on :00, :10, :20, etc.
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  ## Default flushing interval for all outputs. You shouldn't set this below
  ## interval. Maximum flush_interval will be flush_interval + flush_jitter
  flush_interval = "1s"
  flush_jitter = "0s"
  precision = "ms"
  debug = false
  quiet = false
  logfile = "/var/log/telegraf/telegraf.log"
  ## Override default hostname, if empty use os.Hostname()
  hostname = ""
  ## If set to true, do no set the "host" tag in the telegraf agent.
  omit_hostname = false

[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "FlowProcessAgent"
  retention_policy = ""
  write_consistency = "any"
  timeout = "5s"

[[inputs.tail]]
  files = ["/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/gc_metrics.log","/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/class_metrics.log","/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/memory_metrics.log","/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/method_metrics.log","/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/thread_metrics.log","/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/buf_pool_metrics"]
  from_beginning = false
  pipe = false
  ## Method used to watch for file updates.  Can be either "inotify" or "poll".
  watch_method = "inotify"
  data_format = "influx"

注意:database、files的配置

啓動

systemctl start telegraf

/var/log/telegraf/telegraf.log

2019-03-01T08:36:14Z I! Loaded inputs: inputs.tail
2019-03-01T08:36:14Z I! Loaded aggregators: 
2019-03-01T08:36:14Z I! Loaded processors: 
2019-03-01T08:36:14Z I! Loaded outputs: influxdb
2019-03-01T08:36:14Z I! Tags enabled: dc= host=sinorail
2019-03-01T08:36:14Z I! [agent] Config: Interval:1s, Quiet:false, Hostname:"sinorail", Flush Interval:1s

啓動成功

6、安裝Grafana(可視化界面)

Grafana

新建/etc/yum.repos.d/grafana.repo

[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

安裝

yum install grafana

啓動

systemctl daemon-reload
service grafana-server start

訪問

http://192.168.1.222:3000/
  • 用戶名:admin
  • 密碼:admin

添加DB

添加JVM Dashboard

MyPerf4J-InfluxDB-JVM

輸入ID:8787

添加Method Dashboard

MyPerf4J-InfluxDB-Method

輸入ID:7766

注意:/home/lwenhao/MyPerf4J/FlowProcessAgent/logs/method_metrics.log沒有內容,因此這裏沒有數據

相關文章
相關標籤/搜索