Skip to content

Commit f0dae6d

Browse files
committed
[#10299] Adding network information for Pinpoint system metric
1 parent 608d75a commit f0dae6d

File tree

12 files changed

+677
-5
lines changed

12 files changed

+677
-5
lines changed

agent/src/main/resources/profiles/local/pinpoint.config

+11
Original file line numberDiff line numberDiff line change
@@ -1379,3 +1379,14 @@ profiler.kotlin.coroutines.record.threadName=false
13791379
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
13801380
#Recommend that you use it in the development environment and not in the production environment.
13811381
profiler.kotlin.coroutines.record.cancel=false
1382+
1383+
###########################################################
1384+
# Network Metric #
1385+
###########################################################
1386+
profiler.network.metric.enable=false
1387+
profiler.network.metric.enable.protocolstats=false
1388+
profiler.network.metric.collector.ip=${profiler.collector.ip}
1389+
profiler.network.metric.collector.port=15200
1390+
# if you want to specify host group name (default: application name)
1391+
#profiler.network.metric.hostgroupname=
1392+
profiler.network.metric.collect.interval=10000

agent/src/main/resources/profiles/release/pinpoint.config

+11
Original file line numberDiff line numberDiff line change
@@ -1402,3 +1402,14 @@ profiler.kotlin.coroutines.record.threadName=false
14021402
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
14031403
#Recommend that you use it in the development environment and not in the production environment.
14041404
profiler.kotlin.coroutines.record.cancel=false
1405+
1406+
###########################################################
1407+
# Network Metric #
1408+
###########################################################
1409+
profiler.network.metric.enable=false
1410+
profiler.network.metric.enable.protocolstats=false
1411+
profiler.network.metric.collector.ip=${profiler.collector.ip}
1412+
profiler.network.metric.collector.port=15200
1413+
# if you want to specify host group name (default: application name)
1414+
#profiler.network.metric.hostgroupname=
1415+
profiler.network.metric.collect.interval=10000

metric-module/metric/src/main/resources/pinot-web/telegraf-metric.yml

+73-1
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,76 @@ mappings:
115115
- name: "active"
116116
matchingRule: ANY_ONE
117117
- name: "waiting"
118-
matchingRule: ANY_ONE
118+
matchingRule: ANY_ONE
119+
120+
- definitionId: "networkInterfaceInfo"
121+
name: "network_interface"
122+
title: "network interface information"
123+
grouping: "TAG"
124+
unit: "count"
125+
fields:
126+
- name: "rx_packets"
127+
matchingRule: PASSED_ALL
128+
- name: "rx_errors"
129+
matchingRule: PASSED_ALL
130+
- name: "rx_drops"
131+
matchingRule: PASSED_ALL
132+
- name: "tx_packets"
133+
matchingRule: PASSED_ALL
134+
- name: "tx_errors"
135+
matchingRule: PASSED_ALL
136+
- name: "tx_collisions"
137+
matchingRule: PASSED_ALL
138+
139+
- definitionId: "networkInterfaceBytes"
140+
name: "network_interface"
141+
title: "network rx & tx"
142+
grouping: "TAG"
143+
unit: "byte"
144+
fields:
145+
- name: "rx_bytes"
146+
matchingRule: PASSED_ALL
147+
- name: "tx_bytes"
148+
matchingRule: PASSED_ALL
149+
150+
- definitionId: "tcpStats"
151+
name: "tcp_stats"
152+
title: "TCP"
153+
grouping: "TAG"
154+
unit: "count"
155+
fields:
156+
- name: "conn_established"
157+
matchingRule: PASSED_ALL
158+
- name: "conn_active"
159+
matchingRule: PASSED_ALL
160+
- name: "conn_passive"
161+
matchingRule: PASSED_ALL
162+
- name: "conn_failure"
163+
matchingRule: PASSED_ALL
164+
- name: "conn_reset"
165+
matchingRule: PASSED_ALL
166+
- name: "seg_sent"
167+
matchingRule: PASSED_ALL
168+
- name: "seg_received"
169+
matchingRule: PASSED_ALL
170+
- name: "seg_retransmitted"
171+
matchingRule: PASSED_ALL
172+
- name: "in_errors"
173+
matchingRule: PASSED_ALL
174+
- name: "out_resets"
175+
matchingRule: PASSED_ALL
176+
177+
- definitionId: "udpStats"
178+
name: "udp_stats"
179+
title: "UDP"
180+
grouping: "TAG"
181+
unit: "count"
182+
fields:
183+
- name: "txd"
184+
matchingRule: PASSED_ALL
185+
- name: "rxd"
186+
matchingRule: PASSED_ALL
187+
- name: "noport"
188+
matchingRule: PASSED_ALL
189+
- name: "rx_error"
190+
matchingRule: PASSED_ALL

profiler/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
<groupId>com.github.ben-manes.caffeine</groupId>
8585
<artifactId>caffeine</artifactId>
8686
</dependency>
87+
<dependency>
88+
<groupId>com.github.oshi</groupId>
89+
<artifactId>oshi-core</artifactId>
90+
<version>6.4.5</version>
91+
</dependency>
8792

8893

8994
<dependency>

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/ApplicationContextModule.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@
112112
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
113113
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService;
114114
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService;
115-
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
116-
import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor;
117-
import com.navercorp.pinpoint.profiler.monitor.DeadlockThreadRegistry;
118-
import com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor;
115+
import com.navercorp.pinpoint.profiler.monitor.*;
119116
import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeCollector;
120117
import com.navercorp.pinpoint.profiler.monitor.metric.response.ReuseResponseTimeCollector;
121118
import com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory;
@@ -212,6 +209,7 @@ protected void configure() {
212209
bind(DeadlockMonitor.class).toProvider(DeadlockMonitorProvider.class).in(Scopes.SINGLETON);
213210
bind(AgentInfoSender.class).toProvider(AgentInfoSenderProvider.class).in(Scopes.SINGLETON);
214211
bind(AgentStatMonitor.class).to(DefaultAgentStatMonitor.class).in(Scopes.SINGLETON);
212+
bind(NetworkStatMonitor.class).to(DefaultNetworkStatMonitor.class).in(Scopes.SINGLETON);
215213
}
216214

217215
private void bindTraceComponent() {

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/module/DefaultApplicationContext.java

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
4747
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
4848
import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor;
49+
import com.navercorp.pinpoint.profiler.monitor.NetworkStatMonitor;
4950
import org.apache.logging.log4j.LogManager;
5051
import org.apache.logging.log4j.Logger;
5152

@@ -66,6 +67,7 @@ public class DefaultApplicationContext implements ApplicationContext {
6667
private final DeadlockMonitor deadlockMonitor;
6768
private final AgentInfoSender agentInfoSender;
6869
private final AgentStatMonitor agentStatMonitor;
70+
private final NetworkStatMonitor hwStatMonitor;
6971

7072
private final TraceContext traceContext;
7173

@@ -131,6 +133,7 @@ public DefaultApplicationContext(AgentOption agentOption, ModuleFactory moduleFa
131133
this.deadlockMonitor = injector.getInstance(DeadlockMonitor.class);
132134
this.agentInfoSender = injector.getInstance(AgentInfoSender.class);
133135
this.agentStatMonitor = injector.getInstance(AgentStatMonitor.class);
136+
this.hwStatMonitor = injector.getInstance(NetworkStatMonitor.class);
134137
}
135138

136139
private void lambdaFactorySetup(Instrumentation instrumentation, ClassFileTransformModuleAdaptor classFileTransformer, JavaModuleFactory javaModuleFactory) {
@@ -227,13 +230,15 @@ public void start() {
227230
this.deadlockMonitor.start();
228231
this.agentInfoSender.start();
229232
this.agentStatMonitor.start();
233+
this.hwStatMonitor.start();
230234
}
231235

232236
@Override
233237
public void close() {
234238
this.agentInfoSender.stop();
235239
this.agentStatMonitor.stop();
236240
this.deadlockMonitor.stop();
241+
this.hwStatMonitor.stop();
237242

238243
// Need to process stop
239244
if (rpcModuleLifeCycle != null) {

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/DefaultMonitorConfig.java

+44
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ public class DefaultMonitorConfig implements MonitorConfig {
2222

2323
public static final int DEFAULT_AGENT_STAT_COLLECTION_INTERVAL_MS = 5 * 1000;
2424
public static final int DEFAULT_NUM_AGENT_STAT_BATCH_SEND = 6;
25+
public static final int DEFAULT_NETWORK_METRIC_COLLECTION_INTERVAL_MS = 10 * 1000;
2526

2627
@Value("${profiler.custommetric.enable}")
2728
private boolean customMetricEnable = false;
2829
@Value("${profiler.custommetric.limit.size}")
2930
private int customMetricLimitSize = 10;
3031

32+
@Value("${profiler.network.metric.enable}")
33+
private boolean networkMetricEnable = false;
34+
@Value("${profiler.network.metric.enable.protocolstats}")
35+
private boolean protocolStatsEnable = false;
36+
@Value("${profiler.network.metric.hostgroupname}")
37+
private String hostGroupName;
38+
@Value("${profiler.network.metric.collector.ip}")
39+
private String metricCollectorIP;
40+
@Value("${profiler.network.metric.collector.port:15200}")
41+
private String metricCollectorPort;
42+
@Value("${profiler.network.metric.collect.interval}")
43+
private int networkMetricCollectIntervalMs = DEFAULT_NETWORK_METRIC_COLLECTION_INTERVAL_MS;
44+
3145
@Value("${profiler.uri.stat.enable}")
3246
private boolean uriStatEnable = false;
3347
@Value("${profiler.uri.stat.collect.http.method}")
@@ -70,6 +84,36 @@ public int getCustomMetricLimitSize() {
7084
return customMetricLimitSize;
7185
}
7286

87+
@Override
88+
public boolean isNetworkMetricEnable() {
89+
return networkMetricEnable;
90+
}
91+
92+
@Override
93+
public String getHostGroupName() {
94+
return hostGroupName;
95+
}
96+
97+
@Override
98+
public String getMetricCollectorIP() {
99+
return metricCollectorIP;
100+
}
101+
102+
@Override
103+
public String getMetricCollectorPort() {
104+
return metricCollectorPort;
105+
}
106+
107+
@Override
108+
public int getNetworkMetricCollectIntervalMs() {
109+
return networkMetricCollectIntervalMs;
110+
}
111+
112+
@Override
113+
public boolean isProtocolStatsEnable() {
114+
return protocolStatsEnable;
115+
}
116+
73117
@Override
74118
public boolean isUriStatEnable() {
75119
return uriStatEnable;

profiler/src/main/java/com/navercorp/pinpoint/profiler/context/monitor/config/MonitorConfig.java

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ public interface MonitorConfig {
2727

2828
int getCustomMetricLimitSize();
2929

30+
boolean isNetworkMetricEnable();
31+
32+
String getHostGroupName();
33+
34+
String getMetricCollectorIP();
35+
36+
String getMetricCollectorPort();
37+
38+
int getNetworkMetricCollectIntervalMs();
39+
40+
boolean isProtocolStatsEnable();
41+
3042
boolean isUriStatEnable();
3143

3244
boolean getUriStatCollectHttpMethod();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2023 NAVER Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.navercorp.pinpoint.profiler.monitor;
17+
18+
import com.google.inject.Inject;
19+
import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory;
20+
import com.navercorp.pinpoint.common.util.StringUtils;
21+
import com.navercorp.pinpoint.profiler.context.module.ApplicationName;
22+
import com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig;
23+
import com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig;
24+
import org.apache.logging.log4j.LogManager;
25+
import org.apache.logging.log4j.Logger;
26+
27+
import java.util.ArrayList;
28+
import java.util.List;
29+
import java.util.concurrent.ScheduledExecutorService;
30+
import java.util.concurrent.ScheduledThreadPoolExecutor;
31+
import java.util.concurrent.TimeUnit;
32+
33+
public class DefaultNetworkStatMonitor implements NetworkStatMonitor {
34+
private static final long MIN_COLLECTION_INTERVAL_MS = 1000 * 5;
35+
private static final long MAX_COLLECTION_INTERVAL_MS = 1000 * 10;
36+
private static final long DEFAULT_COLLECTION_INTERVAL_MS = DefaultMonitorConfig.DEFAULT_NETWORK_METRIC_COLLECTION_INTERVAL_MS;
37+
38+
private final Logger logger = LogManager.getLogger(this.getClass());
39+
private final long collectionIntervalMs;
40+
private final StatMonitorJob statMonitorJob;
41+
private final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new PinpointThreadFactory("Pinpoint-hw-stat-monitor", true));
42+
private final boolean isNetworkMetricEnable;
43+
44+
@Inject
45+
public DefaultNetworkStatMonitor(@ApplicationName String applicationName,
46+
MonitorConfig monitorConfig) {
47+
long collectionIntervalMs = monitorConfig.getNetworkMetricCollectIntervalMs();
48+
49+
if (collectionIntervalMs < MIN_COLLECTION_INTERVAL_MS) {
50+
collectionIntervalMs = DEFAULT_COLLECTION_INTERVAL_MS;
51+
}
52+
if (collectionIntervalMs > MAX_COLLECTION_INTERVAL_MS) {
53+
collectionIntervalMs = DEFAULT_COLLECTION_INTERVAL_MS;
54+
}
55+
56+
this.collectionIntervalMs = collectionIntervalMs;
57+
List<Runnable> runnableList = new ArrayList<>();
58+
this.isNetworkMetricEnable = monitorConfig.isNetworkMetricEnable();
59+
60+
if (isNetworkMetricEnable && NetworkMetricCollectingJob.isSupported()) {
61+
String hostGroupName = monitorConfig.getHostGroupName();
62+
if (StringUtils.isEmpty(hostGroupName)) {
63+
hostGroupName = applicationName;
64+
}
65+
Runnable oshiMetricCollectingJob = new NetworkMetricCollectingJob(hostGroupName,
66+
monitorConfig.getMetricCollectorIP(), monitorConfig.getMetricCollectorPort(), monitorConfig.isProtocolStatsEnable());
67+
runnableList.add(oshiMetricCollectingJob);
68+
}
69+
this.statMonitorJob = new StatMonitorJob(runnableList);
70+
71+
}
72+
@Override
73+
public void start() {
74+
if (isNetworkMetricEnable) {
75+
executor.scheduleAtFixedRate(statMonitorJob, this.collectionIntervalMs, this.collectionIntervalMs, TimeUnit.MILLISECONDS);
76+
logger.info("HW stat monitor started");
77+
} else {
78+
logger.info("HW stat monitor disabled");
79+
}
80+
}
81+
82+
@Override
83+
public void stop() {
84+
if (isNetworkMetricEnable) {
85+
statMonitorJob.close();
86+
executor.shutdown();
87+
try {
88+
executor.awaitTermination(3000, TimeUnit.MILLISECONDS);
89+
} catch (InterruptedException e) {
90+
Thread.currentThread().interrupt();
91+
}
92+
logger.info("HW stat monitor stopped");
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)