MyPerf4J3.4+Influxdb2.7+grafana10.0 access method monitoring

MyPerf4J’s official access document: https://github.com/LinShunKang/MyPerf4J.

One MyPerf4J configuration

# For all configurations of MyPerf4J, please refer to: https://github.com/LinShunKang/MyPerf4J/wiki/Configuration

#Configure the name of the monitoring application
app_name = MyApp

debug=true

################################################ #############################
# Metrics Configuration #
################################################ #############################

# Configure MetricsExporter type
# log.stdout: Output to stdout.log in standard format structure
# log.standard: Output to disk in standard format structure
# log.influxdb: Output to disk in InfluxDB LineProtocol format
# http.influxdb: sent to InfluxDB server in InfluxDB LineProtocol format, additional influxdb configuration needs to be added
metrics.exporter = http.influxdb

# Configure the file path of various monitoring indicator logs
# If metrics.exporter is configured as log.influxdb, it is recommended to configure all metrics.log.* paths to be the same to facilitate Telegraf collection
metrics.log.method = /data/logs/MyPerf4J/metrics.log
metrics.log.class_loading = /data/logs/MyPerf4J/metrics.log
metrics.log.gc = /data/logs/MyPerf4J/metrics.log
metrics.log.memory = /data/logs/MyPerf4J/metrics.log
metrics.log.buff_pool = /data/logs/MyPerf4J/metrics.log
metrics.log.thread = /data/logs/MyPerf4J/metrics.log
metrics.log.file_desc = /data/logs/MyPerf4J/metrics.log
metrics.log.compilation = /data/logs/MyPerf4J/metrics.log


################################################ #############################
# Filter Configuration #
################################################ #############################

# Configure the packages that need to be monitored. You can configure multiple packages, separated by English ';'
# com.demo.p1 represents all packages and classes prefixed with com.demo.p1
# [] represents the concept of a collection: for example, com.demo.[p1,p2,p3] represents all packages and classes prefixed with com.demo.p1, com.demo.p2 and com.demo.p3, etc. Priced at com.demo.p1;com.demo.p2;com.demo.p3
# * represents a wildcard: can refer to zero or more characters, for example, com.*.demo.*
filter.packages.include = cn.perf4j.demo;com.midea.*;

# Configure packages that do not need to be monitored. You can configure multiple packages, separated by English ';'
filter.packages.exclude = cn.perf4j.demo.dao.DemoDAOImpl


################################################ #############################
# InfluxDB Configuration #
################################################ #############################
influxdb.version=2.7.1
influxdb.orgName=root
influxdb.host = 127.0.0.1
influxdb.port = 8086
influxdb.database = MyPerf4J
influxdb.username=root
influxdb.password = 12345678
influxdb.conn_timeout = 3000
influxdb.read_timeout = 5000
  1. Configure metrics.exporter to http.influxdb, be careful not to include a colon after it. I copied the colon after it and checked it for a long time.
  2. influxdb.database must be configured as MyPerf4J, otherwise grafana will have to change a lot.
  3. debug = true, easy to troubleshoot problems

Two Application Configuration

Add two configurations to the application startup parameters

-javaagent:/Users/**/work/develop_tools/MyPerf4J-ASM-3.4.0-SNAPSHOT/MyPerf4J-ASM-3.4.0-SNAPSHOT.jar
-DMyPerf4JPropFile=/Users/**/work/develop_tools/MyPerf4J-ASM-3.4.0-SNAPSHOT/MyPerf4J.properties

Start the application and use respStatus to determine whether the interaction with influxDB is successful.

2023-10-20 09:55:00.147 [MyPerf4J] DEBUG [MyPerf4J-InfluxDbV2Client_0] InfluxDbV2Client.writeMetricsSync(): respStatus='204 No Content', reqBody=jvm_thread_metrics,AppName=MyApp,host=lvsheng1- Mac666.local TotalStarted=178i,Active=112i,Peak=112i,Daemon=81i,New=0i,Runnable=20i,Blocked=0i,Waiting=58i,TimedWaiting=34i,Terminated=0i 1697766840008000000
2023-10-20 09:55:00.172 [MyPerf4J] DEBUG [MyPerf4J-InfluxDbV2Client_0] InfluxDbV2Client.writeMetricsSync(): respStatus='204 No Content', reqBody=jvm_compilation_metrics,AppName=MyApp,host=lvsheng1-Mac666.local Time=606i,TotalTime=29697i 1697766840008000000
2023-10-20 09: 55: 00.197 [MyperF4J] Debug [MyperF4J-InfluxDBV2Client_0] Influxdbv2client.writeMetricssync (): Respstatus = \ '204 No Content ', Re RE qbody = jvm_file_descriptor_metrics, appName = MyApp, Host = lvSheng1-MAC666.Local OpenCount=416i,OpenPercent=4.0625 1697766840008000000
2023-10-20 09:55:00.226 [MyPerf4J] DEBUG [MyPerf4J-InfluxDbV2Client_0] InfluxDbV2Client.writeMetricsSync(): respStatus='204 No Content', reqBody=method_metrics,AppName=MyApp,ClassName=Scheduler,Method=Scheduler .run(),Type=General,Level=Others,host=lvsheng1-Mac666.local TotalTimePercent=0.0011666666666666668,RPS=0i,Avg=11.67,Min=3i,Max=39i,StdDev=13.19,Count=6i,TP50= 4i,TP90=39i,TP95=39i,TP99=39i,TP999=39i,TP9999=39i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=JvmInfo,Method=JvmInfo.getInstance(),Type=General,Level=Others,host=lvsheng1-Mac666.local TotalTimePercent=0.0,RPS=0i,Avg=0.00,Min=0i,Max =0i,StdDev=0.00,Count=1i,TP50=0i,TP90=0i,TP95=0i,TP99=0i,TP999=0i,TP9999=0i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=HttpUtils,Method=HttpUtils.post(String\,\ Object),Type=General,Level=Utils,host=lvsheng1-Mac666.local TotalTimePercent=5.833333333333334E-4,RPS=0i ,Avg=35.00,Min=35i,Max=35i,StdDev=0.00,Count=1i,TP50=35i,TP90=35i,TP95=35i,TP99=35i,TP999=35i,TP9999=35i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=InfluxdbUtils,Method=InfluxdbUtils.writeJVM(MBeanServer\,\ Vector\,\ Vector),Type=General,Level=Utils,host=lvsheng1-Mac666.local TotalTimePercent=4.0E -4,RPS=0i,Avg=4.00,Min=2i,Max=8i,StdDev=1.91,Count=6i,TP50=3i,TP90=8i,TP95=8i,TP99=8i,TP999=8i,TP9999=8i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=InfluxdbUtils,Method=InfluxdbUtils.handleCpuStatics(MBeanServer\,\ Vector),Type=General,Level=Utils,host=lvsheng1-Mac666.local TotalTimePercent=1.5E-4,RPS=0i ,Avg=1.50,Min=0i,Max=9i,StdDev=3.35,Count=6i,TP50=0i,TP90=9i,TP95=9i,TP99=9i,TP999=9i,TP9999=9i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=InfluxdbUtils,Method=InfluxdbUtils.formatSize(Object),Type=General,Level=Utils,host=lvsheng1-Mac666.local TotalTimePercent=0.0,RPS=2i,Avg=0.00,Min=0i, Max=0i,StdDev=0.00,Count=156i,TP50=0i,TP90=0i,TP95=0i,TP99=0i,TP999=0i,TP9999=0i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=InfluxdbUtils,Method=InfluxdbUtils.formatTime(Object\,\ boolean),Type=General,Level=Utils,host=lvsheng1-Mac666.local TotalTimePercent=0.0,RPS=0i,Avg= 0.00,Min=0i,Max=0i,StdDev=0.00,Count=6i,TP50=0i,TP90=0i,TP95=0i,TP99=0i,TP999=0i,TP9999=0i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=InfluxdbUtils,Method=InfluxdbUtils.formaStr(String),Type=General,Level=Utils,host=lvsheng1-Mac666.local TotalTimePercent=0.0,RPS=0i,Avg=0.00,Min=0i, Max=0i,StdDev=0.00,Count=36i,TP50=0i,TP90=0i,TP95=0i,TP99=0i,TP999=0i,TP9999=0i 1697766840014000000
method_metrics,AppName=MyApp,ClassName=HeartBeatHelper,Method=HeartBeatHelper.startHeartBeat(),Type=General,Level=Others,host=lvsheng1-Mac666.local TotalTimePercent=0.0,RPS=0i,Avg=0.00,Min=0i,Max =0i,StdDev=0.00,Count=1i,TP50=0i,TP90=0i,TP95=0i,TP99=0i,TP999=0i,TP9999=0i 1697766840014000000
2023-10-20 09:56:00.001 [MyPerf4J] DEBUG [MyPerf4J-LightWeightScheduler-1] LightWeightScheduler.runTask(ProfilingFileGenerator, 1697766900000) cost: 1ms

InfluxDB

After downloading the latest version, start influxdb. After logging in, you will be told a token. This token needs to be recorded. It is needed when configuring grafana.

Create a bucket with the ID MyPerf4J to store MyPerf4J monitoring data

grafana

Create InfluxDB data source, select Flux for QueryLanguage


Click Save & Test and the prompt will report this, indicating that the access is successful.

Then import the method monitoring disk https://grafana.com/grafana/dashboards/15672-myperf4j-influxdbv2-0-method/. When importing, select the influxdb data source you just created.

Method monitoring effect