This is an automated email from the ASF dual-hosted git repository.
dlmarion pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/2.1 by this push:
new b2040352a2 Optionally enable metrics for log4j2 or logback logging
impls (#5025)
b2040352a2 is described below
commit b2040352a2b6663df031ec5809a57a36bdab0cc2
Author: Dave Marion <[email protected]>
AuthorDate: Thu Oct 31 16:00:51 2024 -0400
Optionally enable metrics for log4j2 or logback logging impls (#5025)
Closes #4922
---
.../org/apache/accumulo/core/conf/Property.java | 6 ++++
.../accumulo/server/metrics/MetricsInfoImpl.java | 34 ++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/core/src/main/java/org/apache/accumulo/core/conf/Property.java
b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
index 2cae14b189..87a3ceb12d 100644
--- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java
+++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java
@@ -314,6 +314,12 @@ public enum Property {
"Enables additional JVM metrics collection and reporting using
Micrometer. Requires "
+ "property 'general.micrometer.enabled' to be set to 'true' to take
effect.",
"2.1.0"),
+ GENERAL_MICROMETER_LOG_METRICS("general.micrometer.log.metrics", "none",
PropertyType.STRING,
+ "Enables additional log metrics collection and reporting using
Micrometer. Requires "
+ + "property 'general.micrometer.enabled' to be set to 'true' to take
effect. Micrometer "
+ + "natively instruments Log4j2 and Logback. Valid values for this
property are 'none',"
+ + "'log4j2' or 'logback'.",
+ "2.1.4"),
GENERAL_MICROMETER_FACTORY("general.micrometer.factory",
"org.apache.accumulo.core.spi.metrics.LoggingMeterRegistryFactory",
PropertyType.CLASSNAMELIST,
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
index 5b765e747c..679c70cdae 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/metrics/MetricsInfoImpl.java
@@ -46,6 +46,8 @@ import
io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
+import io.micrometer.core.instrument.binder.logging.Log4j2Metrics;
+import io.micrometer.core.instrument.binder.logging.LogbackMetrics;
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.config.MeterFilter;
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
@@ -60,6 +62,9 @@ public class MetricsInfoImpl implements MetricsInfo {
// JvmGcMetrics are declared with AutoCloseable - keep reference to use with
close()
private JvmGcMetrics jvmGcMetrics;
+ // Log4j2Metrics and LogbackMetrics are declared with AutoCloseable - keep
reference to use with
+ // close()
+ private AutoCloseable logMetrics;
private final boolean metricsEnabled;
@@ -116,6 +121,7 @@ public class MetricsInfoImpl implements MetricsInfo {
LOG.info("Metrics not initialized, metrics are disabled.");
return;
}
+
if (commonTags != null) {
LOG.warn("metrics registry has already been initialized");
return;
@@ -167,6 +173,26 @@ public class MetricsInfoImpl implements MetricsInfo {
new JvmThreadMetrics().bindTo(Metrics.globalRegistry);
}
+ String loggingMetrics =
context.getConfiguration().get(Property.GENERAL_MICROMETER_LOG_METRICS);
+ switch (loggingMetrics) {
+ case "none":
+ LOG.info("Log metrics are disabled.");
+ break;
+ case "log4j2":
+ Log4j2Metrics l2m = new Log4j2Metrics();
+ l2m.bindTo(Metrics.globalRegistry);
+ logMetrics = l2m;
+ break;
+ case "logback":
+ LogbackMetrics lb = new LogbackMetrics();
+ lb.bindTo(Metrics.globalRegistry);
+ logMetrics = lb;
+ break;
+ default:
+ LOG.info("Log metrics misconfigured, valid values for {} are 'none',
'log4j2' or 'logback'",
+ Property.GENERAL_MICROMETER_LOG_METRICS.getKey());
+ }
+
LOG.info("Metrics initialization. Register producers: {}", producers);
producers.forEach(p -> p.registerMetrics(Metrics.globalRegistry));
}
@@ -211,6 +237,14 @@ public class MetricsInfoImpl implements MetricsInfo {
jvmGcMetrics = null;
}
+ if (logMetrics != null) {
+ try {
+ logMetrics.close();
+ } catch (Exception e) {
+ LOG.info("Exception when closing log metrics", e);
+ }
+ }
+
Metrics.globalRegistry.close();
}