Aeron Agent 是一个 Java 代理,用于提供 Aeron、Aeron Archive 和 Aeron Cluster 中发生的运行时低级日志信息。这些日志语句包括从高级管理员事件到大容量数据帧事件。
在调试 Archive 和 Cluster 问题时,Aeron Agent 的日志数据尤其有用。
一、Available logging options
Environment Variable | Options |
---|---|
aeron.event.log | 以逗号分隔的 DriverEventCodes 列表,或 admin 表示所有管理事件,或 all 表示所有事件(Comma separated list of DriverEventCodes , or admin for all admin events, or all for everything) |
aeron.event.archive.log | 以逗号分隔的 ArchiveEventCodes 列表,或all 表示所有事件(Comma separated list of ArchiveEventCodes , or all for everything) |
aeron.event.cluster.log | 以逗号分隔的ClusterEventCodes 列表,或all 表示所有事件(Comma separated list of ClusterEventCodes , or all for everything) |
此外,您还可以通过为 aeron.event.log.filename
赋值,将输出记录到文件中,而不是默认的 std out。
二、Attaching to a process on start(启动时附加到进程)
正如 Aeron Cookbook 示例中的启动脚本所示,在启动时将 Aeron Agent 附加到进程非常简单:
java --add-opens java.base/sun.nio.ch=ALL-UNNAMED \
-javaagent:/root/aeron/aeron-agent-1.42.0.jar \
-Djava.net.preferIPv4Stack=true \
-Daeron.event.log=admin \
-Daeron.event.archive.log=all \
-jar /root/jar/archive-backup-0.1-SNAPSHOT-all.jar
See GitHub for the full sample.
三、Dynamic Logging Agent
使用 Aeron 1.33.0+ 中添加的Dynamic Logging Agent,可以轻松地将代理附加到运行中的进程。
Steps:
- 在启动需要检测的 Aeron 进程之前,必须通过环境变量或 -D 参数(如
-Daeron.event.log=admin
)让 aeron 代理知道要捕获什么,从而定义需要捕获的事件。有关可用选项,请参见上文。(Before launching the Aeron process you want instrumented, you must define the events you are interested in capturing by letting aeron agent know what to capture either via environment variables or via-D
arguments, such as-Daeron.event.log=admin
. See above for the available options.) - 在要检测的进程已经运行的情况下,获取 PID(With the process to instrument already running, get the PID)
- 使用启动(
start
)命令启动io.aeron.agent.DynamicLoggingAgent
。(Launch theio.aeron.agent.DynamicLoggingAgent
with thestart
command.)
Sample command line
To start logging in a process with PID 42945:
java -cp /path-to/aeron-all-1.42.0.jar io.aeron.agent.DynamicLoggingAgent /path-to/aeron-agent-1.42.0.jar 42945 start
四、Sample output
最左侧 [ and ] 中的值是事件的时间戳,定义为当前时间戳(纳秒)除以 1,000,000,000。这意味着小数点前的值是以秒为单位的,因此从初始行项目 [76948.355606523] log started 2021-04-17 14:26:41.710-0400
可以推算出 [76958.678426732]
处的事件发生在 14:26:41.710 + 10.323s = 14:26:52.033
左右。10.323s
是 76948.355
和 76958.678
之间的差值。数据源是 System.nanoTime()
,它与wall time无关,只能用于相对时间。
这是一个集群节点(RFQ 示例)的示例片段,aeron.event.log
设置为all
。
[76948.355606523] log started 2021-04-17 14:26:41.710-0400
[76958.678426732] DRIVER: FRAME_IN [52/52]: 127.0.0.1:55443 SETUP 00000000 len 40 2073747220:101:905418016 905418016 @0 16777216 MTU 1408 TTL 0
[76958.685011759] DRIVER: CMD_OUT_AVAILABLE_IMAGE [147/147]: 2073747220:101 [57:48] [49] /var/folders/aeron-driver/images/49.logbuffer 127.0.0.1:55443
[76958.685099301] DRIVER: FRAME_OUT [48/48]: 127.0.0.1:55443 SM 00000000 len 36 2073747220:101:905418016 @0 131072 -4489607960779398291
[76958.686931252] DRIVER: FRAME_IN [44/44]: 127.0.0.1:55443 DATA 11000000 len 0 2073747220:101:905418016 @0
[76958.687164768] DRIVER: FRAME_IN [140/140]: 127.0.0.1:55443 DATA 11000000 len 98 2073747220:101:905418016 @0
[76958.694589747] DRIVER: CMD_IN_ADD_PUBLICATION [58/58]: 102 [7:50] aeron:udp?endpoint=localhost:57377
[76958.69499685] DRIVER: SEND_CHANNEL_CREATION [92/92]: UdpChannel - localData: 0.0.0.0/0.0.0.0:0, remoteData: localhost/127.0.0.1:57377, ttl: 0
[76958.697468817] DRIVER: CMD_OUT_PUBLICATION_READY [138/138]: -74825448:102 75 65 [50 50] /var/folders/aeron-driver/publications/50.logbuffer
[76958.697569264] DRIVER: FRAME_OUT [52/52]: 127.0.0.1:57377 SETUP 00000000 len 40 -74825448:102:728163187 728163187 @0 16777216 MTU 1408 TTL 0
[76958.758041065] DRIVER: FRAME_IN [48/48]: 127.0.0.1:57377 SM 00000000 len 36 -74825448:102:728163187 @0 131072 -985368778043801883
[76958.758666168] DRIVER: FRAME_OUT [44/44]: 127.0.0.1:57377 DATA 11000000 len 0 -74825448:102:728163187 @0
[76958.7652581] DRIVER: FRAME_OUT [108/108]: 127.0.0.1:57377 DATA 11000000 len 80 -74825448:102:728163187 @0
[76958.765445077] DRIVER: CMD_IN_ADD_PUBLICATION [58/58]: 102 [21:51] aeron:udp?endpoint=localhost:57377
[76958.765583608] DRIVER: CMD_OUT_PUBLICATION_READY [138/138]: -74825448:102 75 65 [51 50] /var/folders/aeron-driver/publications/50.logbuffer
[76958.773609799] DRIVER: FRAME_IN [108/108]: 127.0.0.1:55443 DATA 11000000 len 90 2073747220:101:905418016 @128
[76958.77373172] DRIVER: FRAME_IN [140/140]: 127.0.0.1:55443 DATA 11000000 len 102 2073747220:101:905418016 @224
[76958.775272352] DRIVER: FRAME_OUT [140/140]: 127.0.0.1:57377 DATA 11000000 len 118 -74825448:102:728163187 @96
[76958.777991182] DRIVER: FRAME_IN [108/108]: 127.0.0.1:55443 DATA 11000000 len 92 2073747220:101:905418016 @352
[76958.780923987] DRIVER: FRAME_OUT [140/140]: 127.0.0.1:57377 DATA 11000000 len 100 -74825448:102:728163187 @224
[76958.783483437] DRIVER: FRAME_IN [108/108]: 127.0.0.1:55443 DATA 11000000 len 88 2073747220:101:905418016 @448
[76958.786164552] DRIVER: FRAME_OUT [140/140]: 127.0.0.1:57377 DATA 11000000 len 104 -74825448:102:728163187 @352
[76958.788915601] DRIVER: FRAME_IN [76/76]: 127.0.0.1:55443 DATA 11000000 len 56 2073747220:101:905418016 @544
[76958.789200034] DRIVER: CMD_IN_REMOVE_PUBLICATION [24/24]: 50 [7:52]
[76958.789237205] DRIVER: CMD_OUT_ON_OPERATION_SUCCESS [8/8]: 52
[76958.790866084] DRIVER: CMD_IN_REMOVE_PUBLICATION [24/24]: 51 [21:53]
[76958.790904905] DRIVER: CMD_OUT_ON_OPERATION_SUCCESS [8/8]: 53
[76958.875888058] DRIVER: FRAME_OUT [48/48]: 127.0.0.1:55443 SM 00000000 len 36 2073747220:101:905418016 @0 131072 -4489607960779398291
[76958.886665327] DRIVER: FRAME_OUT [44/44]: 127.0.0.1:57377 DATA 11100000 len 0 -74825448:102:728163187 @480
[76958.987313678] DRIVER: FRAME_OUT [44/44]: 127.0.0.1:57377 DATA 11100000 len 0 -74825448:102:728163187 @480
[76959.076562784] DRIVER: FRAME_OUT [48/48]: 127.0.0.1:55443 SM 00000000 len 36 2073747220:101:905418016 @0 131072 -4489607960779398291
[76959.088009394] DRIVER: FRAME_OUT [44/44]: 127.0.0.1:57377 DATA 11100000 len 0 -74825448:102:728163187 @480
[76959.188642945] DRIVER: FRAME_OUT [44/44]: 127.0.0.1:57377 DATA 11100000 len 0 -74825448:102:728163187 @480