Skip to content

Commit

Permalink
[pinpoint-apm#10776] Use micrometer to collect some metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ga-ram committed Apr 19, 2024
1 parent dab251a commit 5122c3d
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1430,4 +1430,13 @@ profiler.kotlin.coroutines.record.cancel=false
###########################################################
profiler.resilience4j.enable=true
profiler.resilience4j.trace.circuit-breaker=true
profiler.resilience4j.mark.error.circuit-breaker=false
profiler.resilience4j.mark.error.circuit-breaker=false

###########################################################
# Open telemetry metrics
###########################################################
profiler.micrometer.otlp.enabled=true
profiler.micrometer.otlp.url=http://127.0.0.1:15200/opentelemetry
profiler.micrometer.otlp.step=30s
profiler.micrometer.otlp.batchSize=50

Original file line number Diff line number Diff line change
Expand Up @@ -1453,4 +1453,12 @@ profiler.kotlin.coroutines.record.cancel=false
###########################################################
profiler.resilience4j.enable=true
profiler.resilience4j.trace.circuit-breaker=true
profiler.resilience4j.mark.error.circuit-breaker=false
profiler.resilience4j.mark.error.circuit-breaker=false

###########################################################
# Open telemetry metrics
###########################################################
profiler.micrometer.otlp.enabled=true
profiler.micrometer.otlp.url=http://127.0.0.1:15200/opentelemetry
profiler.micrometer.otlp.step=30s
profiler.micrometer.otlp.batchSize=50
6 changes: 5 additions & 1 deletion agent-module/profiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@
</exclusion>
</exclusions>
</dependency>-->

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-otlp</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.navercorp.pinpoint.profiler.context.monitor.config;

import com.navercorp.pinpoint.common.config.Value;

import com.navercorp.pinpoint.common.util.StringUtils;
public class DefaultMonitorConfig implements MonitorConfig {

public static final int DEFAULT_AGENT_STAT_COLLECTION_INTERVAL_MS = 5 * 1000;
Expand Down Expand Up @@ -49,6 +49,50 @@ public class DefaultMonitorConfig implements MonitorConfig {
@Value("${profiler.jvm.stat.collect.detailed.metrics}")
private boolean profilerJvmStatCollectDetailedMetrics = false;

@Value("${profiler.micrometer.otlp.enabled}")
private boolean micrometerEnable = false;

@Value("${profiler.micrometer.otlp.url}")
private String micrometerUrl;

@Value("${profiler.micrometer.otlp.step}")
private String micrometerStep;

@Value("${profiler.micrometer.otlp.batchSize}")
private String micrometerBatchSize;

@Value("${pinpoint.applicationName}")
private String applicationName;

@Value("${pinpoint.agentId}")
private String agentId;

public DefaultMonitorConfig() {
if (StringUtils.isEmpty(agentId)) {
agentId = System.getProperty("pinpoint.agentId");
}
if (StringUtils.isEmpty(applicationName)) {
applicationName = System.getProperty("pinpoint.applicationName");
}
}

@Override
public boolean isMicrometerEnable() { return micrometerEnable; }

@Override
public String getMicrometerUrl() { return micrometerUrl; }

@Override
public String getMicrometerStep() { return micrometerStep; }

@Override
public String getMicrometerBatchSize() { return micrometerBatchSize; }

@Override
public String getApplicationName() { return applicationName; }

public String getAgentId() { return agentId;}

@Override
public int getProfileJvmStatCollectIntervalMs() {
return profileJvmStatCollectIntervalMs;
Expand Down Expand Up @@ -118,6 +162,12 @@ public String toString() {
", profileJvmStatCollectIntervalMs=" + profileJvmStatCollectIntervalMs +
", profileJvmStatBatchSendCount=" + profileJvmStatBatchSendCount +
", profilerJvmStatCollectDetailedMetrics=" + profilerJvmStatCollectDetailedMetrics +
", micrometerEnable=" + micrometerEnable +
", micrometerUrl=" + micrometerUrl +
", micrometerStep=" + micrometerStep +
", micrometerBatchSize=" + micrometerBatchSize +
", micrometerHostName=" + agentId +
", micrometerHostGroupName=" + applicationName +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ public interface MonitorConfig {

int getCompletedUriStatDataLimitSize();

boolean isMicrometerEnable();

String getMicrometerUrl();

String getMicrometerStep();

String getMicrometerBatchSize();

String getApplicationName();

String getAgentId();

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.metric.AgentStatMetricSnapshot;
import com.navercorp.pinpoint.profiler.monitor.metric.MetricType;
import com.navercorp.pinpoint.profiler.monitor.micrometer.MicrometerCollectingJob;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -105,6 +106,11 @@ public DefaultAgentStatMonitor(@StatDataSender DataSender<MetricType> dataSender
runnableList.add(uriStatCollectingJob);
}

if (monitorConfig.isMicrometerEnable()) {
new MicrometerCollectingJob(monitorConfig.getMicrometerUrl(), monitorConfig.getMicrometerStep(),
monitorConfig.getMicrometerBatchSize(), monitorConfig.getApplicationName(), monitorConfig.getAgentId());
}

this.statMonitorJob = new StatMonitorJob(runnableList);

preLoadClass(agentId, agentStartTimestamp, agentStatCollector);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2017 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.micrometer;

import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.binder.jvm.*;
import io.micrometer.core.instrument.binder.system.DiskSpaceMetrics;
import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.registry.otlp.OtlpConfig;
import io.micrometer.registry.otlp.OtlpMeterRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.util.Properties;

public class MicrometerCollectingJob {

private final Logger logger = LogManager.getLogger(this.getClass());

private final OtlpMeterRegistry meterRegistry;

public MicrometerCollectingJob(String micrometerUrl, String micrometerStep, String micrometerBatchSize, String applicationName, String agentId) {
this.meterRegistry = new OtlpMeterRegistry(getOtlpConfig(micrometerUrl, micrometerStep, micrometerBatchSize, "", applicationName, agentId), Clock.SYSTEM);
bindMetrics();
}

private void bindMetrics() {
// jvm
new ClassLoaderMetrics().bindTo(meterRegistry);
new JvmCompilationMetrics().bindTo(meterRegistry);
new JvmGcMetrics().bindTo(meterRegistry);
new JvmHeapPressureMetrics().bindTo(meterRegistry);
new JvmInfoMetrics().bindTo(meterRegistry);
new JvmMemoryMetrics().bindTo(meterRegistry);
new JvmThreadMetrics().bindTo(meterRegistry);

// system
new DiskSpaceMetrics(new File("/")).bindTo(meterRegistry); // add other paths with user input?
new FileDescriptorMetrics().bindTo(meterRegistry);
new ProcessorMetrics().bindTo(meterRegistry);
new UptimeMetrics().bindTo(meterRegistry);
}

private OtlpConfig getOtlpConfig(String micrometerUrl, String micrometerStep, String micrometerBatchSize,
String serviceName, String applicationName, String agentId) {
Properties propertiesConfig = new Properties();
propertiesConfig.put("otlp.url", micrometerUrl);
propertiesConfig.put("otlp.step", String.valueOf(micrometerStep));
propertiesConfig.put("otlp.batchSize", String.valueOf(micrometerBatchSize));
propertiesConfig.put("otlp.resourceAttributes", "service.namespace=" + serviceName + ",service.name=" + applicationName + ",pinpoint.agentId=" + agentId);
OtlpConfig otlpConfig = (key -> (String) propertiesConfig.get(key));
return otlpConfig;
}
}

0 comments on commit 5122c3d

Please sign in to comment.