Skip to content

Commit

Permalink
[#10299] Adding network information for Pinpoint system metric
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Sep 6, 2023
1 parent 608d75a commit f0dae6d
Show file tree
Hide file tree
Showing 12 changed files with 677 additions and 5 deletions.
11 changes: 11 additions & 0 deletions agent/src/main/resources/profiles/local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -1379,3 +1379,14 @@ profiler.kotlin.coroutines.record.threadName=false
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
#Recommend that you use it in the development environment and not in the production environment.
profiler.kotlin.coroutines.record.cancel=false

###########################################################
# Network Metric #
###########################################################
profiler.network.metric.enable=false
profiler.network.metric.enable.protocolstats=false
profiler.network.metric.collector.ip=${profiler.collector.ip}
profiler.network.metric.collector.port=15200
# if you want to specify host group name (default: application name)
#profiler.network.metric.hostgroupname=
profiler.network.metric.collect.interval=10000
11 changes: 11 additions & 0 deletions agent/src/main/resources/profiles/release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -1402,3 +1402,14 @@ profiler.kotlin.coroutines.record.threadName=false
#This is important information to check whether the developer's intention and the behavior of the coroutine match.
#Recommend that you use it in the development environment and not in the production environment.
profiler.kotlin.coroutines.record.cancel=false

###########################################################
# Network Metric #
###########################################################
profiler.network.metric.enable=false
profiler.network.metric.enable.protocolstats=false
profiler.network.metric.collector.ip=${profiler.collector.ip}
profiler.network.metric.collector.port=15200
# if you want to specify host group name (default: application name)
#profiler.network.metric.hostgroupname=
profiler.network.metric.collect.interval=10000
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,76 @@ mappings:
- name: "active"
matchingRule: ANY_ONE
- name: "waiting"
matchingRule: ANY_ONE
matchingRule: ANY_ONE

- definitionId: "networkInterfaceInfo"
name: "network_interface"
title: "network interface information"
grouping: "TAG"
unit: "count"
fields:
- name: "rx_packets"
matchingRule: PASSED_ALL
- name: "rx_errors"
matchingRule: PASSED_ALL
- name: "rx_drops"
matchingRule: PASSED_ALL
- name: "tx_packets"
matchingRule: PASSED_ALL
- name: "tx_errors"
matchingRule: PASSED_ALL
- name: "tx_collisions"
matchingRule: PASSED_ALL

- definitionId: "networkInterfaceBytes"
name: "network_interface"
title: "network rx & tx"
grouping: "TAG"
unit: "byte"
fields:
- name: "rx_bytes"
matchingRule: PASSED_ALL
- name: "tx_bytes"
matchingRule: PASSED_ALL

- definitionId: "tcpStats"
name: "tcp_stats"
title: "TCP"
grouping: "TAG"
unit: "count"
fields:
- name: "conn_established"
matchingRule: PASSED_ALL
- name: "conn_active"
matchingRule: PASSED_ALL
- name: "conn_passive"
matchingRule: PASSED_ALL
- name: "conn_failure"
matchingRule: PASSED_ALL
- name: "conn_reset"
matchingRule: PASSED_ALL
- name: "seg_sent"
matchingRule: PASSED_ALL
- name: "seg_received"
matchingRule: PASSED_ALL
- name: "seg_retransmitted"
matchingRule: PASSED_ALL
- name: "in_errors"
matchingRule: PASSED_ALL
- name: "out_resets"
matchingRule: PASSED_ALL

- definitionId: "udpStats"
name: "udp_stats"
title: "UDP"
grouping: "TAG"
unit: "count"
fields:
- name: "txd"
matchingRule: PASSED_ALL
- name: "rxd"
matchingRule: PASSED_ALL
- name: "noport"
matchingRule: PASSED_ALL
- name: "rx_error"
matchingRule: PASSED_ALL
5 changes: 5 additions & 0 deletions profiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.4.5</version>
</dependency>


<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@
import com.navercorp.pinpoint.profiler.metadata.ApiMetaDataService;
import com.navercorp.pinpoint.profiler.metadata.SqlMetaDataService;
import com.navercorp.pinpoint.profiler.metadata.StringMetaDataService;
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor;
import com.navercorp.pinpoint.profiler.monitor.DeadlockThreadRegistry;
import com.navercorp.pinpoint.profiler.monitor.DefaultAgentStatMonitor;
import com.navercorp.pinpoint.profiler.monitor.*;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeCollector;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ReuseResponseTimeCollector;
import com.navercorp.pinpoint.profiler.objectfactory.ObjectBinderFactory;
Expand Down Expand Up @@ -212,6 +209,7 @@ protected void configure() {
bind(DeadlockMonitor.class).toProvider(DeadlockMonitorProvider.class).in(Scopes.SINGLETON);
bind(AgentInfoSender.class).toProvider(AgentInfoSenderProvider.class).in(Scopes.SINGLETON);
bind(AgentStatMonitor.class).to(DefaultAgentStatMonitor.class).in(Scopes.SINGLETON);
bind(NetworkStatMonitor.class).to(DefaultNetworkStatMonitor.class).in(Scopes.SINGLETON);
}

private void bindTraceComponent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.navercorp.pinpoint.profiler.interceptor.registry.InterceptorRegistryBinder;
import com.navercorp.pinpoint.profiler.monitor.AgentStatMonitor;
import com.navercorp.pinpoint.profiler.monitor.DeadlockMonitor;
import com.navercorp.pinpoint.profiler.monitor.NetworkStatMonitor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -66,6 +67,7 @@ public class DefaultApplicationContext implements ApplicationContext {
private final DeadlockMonitor deadlockMonitor;
private final AgentInfoSender agentInfoSender;
private final AgentStatMonitor agentStatMonitor;
private final NetworkStatMonitor hwStatMonitor;

private final TraceContext traceContext;

Expand Down Expand Up @@ -131,6 +133,7 @@ public DefaultApplicationContext(AgentOption agentOption, ModuleFactory moduleFa
this.deadlockMonitor = injector.getInstance(DeadlockMonitor.class);
this.agentInfoSender = injector.getInstance(AgentInfoSender.class);
this.agentStatMonitor = injector.getInstance(AgentStatMonitor.class);
this.hwStatMonitor = injector.getInstance(NetworkStatMonitor.class);
}

private void lambdaFactorySetup(Instrumentation instrumentation, ClassFileTransformModuleAdaptor classFileTransformer, JavaModuleFactory javaModuleFactory) {
Expand Down Expand Up @@ -227,13 +230,15 @@ public void start() {
this.deadlockMonitor.start();
this.agentInfoSender.start();
this.agentStatMonitor.start();
this.hwStatMonitor.start();
}

@Override
public void close() {
this.agentInfoSender.stop();
this.agentStatMonitor.stop();
this.deadlockMonitor.stop();
this.hwStatMonitor.stop();

// Need to process stop
if (rpcModuleLifeCycle != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,26 @@ public class DefaultMonitorConfig implements MonitorConfig {

public static final int DEFAULT_AGENT_STAT_COLLECTION_INTERVAL_MS = 5 * 1000;
public static final int DEFAULT_NUM_AGENT_STAT_BATCH_SEND = 6;
public static final int DEFAULT_NETWORK_METRIC_COLLECTION_INTERVAL_MS = 10 * 1000;

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

@Value("${profiler.network.metric.enable}")
private boolean networkMetricEnable = false;
@Value("${profiler.network.metric.enable.protocolstats}")
private boolean protocolStatsEnable = false;
@Value("${profiler.network.metric.hostgroupname}")
private String hostGroupName;
@Value("${profiler.network.metric.collector.ip}")
private String metricCollectorIP;
@Value("${profiler.network.metric.collector.port:15200}")
private String metricCollectorPort;
@Value("${profiler.network.metric.collect.interval}")
private int networkMetricCollectIntervalMs = DEFAULT_NETWORK_METRIC_COLLECTION_INTERVAL_MS;

@Value("${profiler.uri.stat.enable}")
private boolean uriStatEnable = false;
@Value("${profiler.uri.stat.collect.http.method}")
Expand Down Expand Up @@ -70,6 +84,36 @@ public int getCustomMetricLimitSize() {
return customMetricLimitSize;
}

@Override
public boolean isNetworkMetricEnable() {
return networkMetricEnable;
}

@Override
public String getHostGroupName() {
return hostGroupName;
}

@Override
public String getMetricCollectorIP() {
return metricCollectorIP;
}

@Override
public String getMetricCollectorPort() {
return metricCollectorPort;
}

@Override
public int getNetworkMetricCollectIntervalMs() {
return networkMetricCollectIntervalMs;
}

@Override
public boolean isProtocolStatsEnable() {
return protocolStatsEnable;
}

@Override
public boolean isUriStatEnable() {
return uriStatEnable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public interface MonitorConfig {

int getCustomMetricLimitSize();

boolean isNetworkMetricEnable();

String getHostGroupName();

String getMetricCollectorIP();

String getMetricCollectorPort();

int getNetworkMetricCollectIntervalMs();

boolean isProtocolStatsEnable();

boolean isUriStatEnable();

boolean getUriStatCollectHttpMethod();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2023 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.profiler.monitor;

import com.google.inject.Inject;
import com.navercorp.pinpoint.common.profiler.concurrent.PinpointThreadFactory;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.profiler.context.module.ApplicationName;
import com.navercorp.pinpoint.profiler.context.monitor.config.DefaultMonitorConfig;
import com.navercorp.pinpoint.profiler.context.monitor.config.MonitorConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class DefaultNetworkStatMonitor implements NetworkStatMonitor {
private static final long MIN_COLLECTION_INTERVAL_MS = 1000 * 5;
private static final long MAX_COLLECTION_INTERVAL_MS = 1000 * 10;
private static final long DEFAULT_COLLECTION_INTERVAL_MS = DefaultMonitorConfig.DEFAULT_NETWORK_METRIC_COLLECTION_INTERVAL_MS;

private final Logger logger = LogManager.getLogger(this.getClass());
private final long collectionIntervalMs;
private final StatMonitorJob statMonitorJob;
private final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, new PinpointThreadFactory("Pinpoint-hw-stat-monitor", true));
private final boolean isNetworkMetricEnable;

@Inject
public DefaultNetworkStatMonitor(@ApplicationName String applicationName,
MonitorConfig monitorConfig) {
long collectionIntervalMs = monitorConfig.getNetworkMetricCollectIntervalMs();

if (collectionIntervalMs < MIN_COLLECTION_INTERVAL_MS) {
collectionIntervalMs = DEFAULT_COLLECTION_INTERVAL_MS;
}
if (collectionIntervalMs > MAX_COLLECTION_INTERVAL_MS) {
collectionIntervalMs = DEFAULT_COLLECTION_INTERVAL_MS;
}

this.collectionIntervalMs = collectionIntervalMs;
List<Runnable> runnableList = new ArrayList<>();
this.isNetworkMetricEnable = monitorConfig.isNetworkMetricEnable();

if (isNetworkMetricEnable && NetworkMetricCollectingJob.isSupported()) {
String hostGroupName = monitorConfig.getHostGroupName();
if (StringUtils.isEmpty(hostGroupName)) {
hostGroupName = applicationName;
}
Runnable oshiMetricCollectingJob = new NetworkMetricCollectingJob(hostGroupName,
monitorConfig.getMetricCollectorIP(), monitorConfig.getMetricCollectorPort(), monitorConfig.isProtocolStatsEnable());
runnableList.add(oshiMetricCollectingJob);
}
this.statMonitorJob = new StatMonitorJob(runnableList);

}
@Override
public void start() {
if (isNetworkMetricEnable) {
executor.scheduleAtFixedRate(statMonitorJob, this.collectionIntervalMs, this.collectionIntervalMs, TimeUnit.MILLISECONDS);
logger.info("HW stat monitor started");
} else {
logger.info("HW stat monitor disabled");
}
}

@Override
public void stop() {
if (isNetworkMetricEnable) {
statMonitorJob.close();
executor.shutdown();
try {
executor.awaitTermination(3000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
logger.info("HW stat monitor stopped");
}
}
}
Loading

0 comments on commit f0dae6d

Please # to comment.