You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2023/08/29 22:48:25 UTC
[sling-whiteboard] 03/05: metrics-prometheus: add basic documentation
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit ea1e6fee78215fe661af0486187b7e2b6472503b
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Wed Aug 30 00:22:29 2023 +0200
metrics-prometheus: add basic documentation
---
metrics-prometheus/README.md | 10 ++++++++++
.../metrics/prometheus/impl/DefaultJvmMetricsRegistrar.java | 3 +++
.../sling/metrics/prometheus/impl/WrapperMetricsServlet.java | 7 +++++++
3 files changed, 20 insertions(+)
diff --git a/metrics-prometheus/README.md b/metrics-prometheus/README.md
new file mode 100644
index 00000000..5e4e4176
--- /dev/null
+++ b/metrics-prometheus/README.md
@@ -0,0 +1,10 @@
+[](https://sling.apache.org)
+
+# Apache Sling Commons Metrics Prometheus
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
+This bundle exposes the collected metrics under the `/metrics` path and provides the following features:
+
+- exports JVM metrics by default
+- supports multiple `MetricRegistry` instances
\ No newline at end of file
diff --git a/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/DefaultJvmMetricsRegistrar.java b/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/DefaultJvmMetricsRegistrar.java
index b84f16d7..9ac10c17 100644
--- a/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/DefaultJvmMetricsRegistrar.java
+++ b/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/DefaultJvmMetricsRegistrar.java
@@ -21,6 +21,9 @@ import org.osgi.service.component.annotations.Component;
import io.prometheus.client.hotspot.DefaultExports;
+/**
+ * Registers the default JVM metrics with the default registry
+ */
@Component(immediate = true)
public class DefaultJvmMetricsRegistrar {
diff --git a/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/WrapperMetricsServlet.java b/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/WrapperMetricsServlet.java
index 9fe7ce62..a9902e88 100644
--- a/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/WrapperMetricsServlet.java
+++ b/metrics-prometheus/src/main/java/org/apache/sling/metrics/prometheus/impl/WrapperMetricsServlet.java
@@ -48,6 +48,13 @@ import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
import io.prometheus.client.exporter.MetricsServlet;
+/**
+ * Exports metrics taking into account multiple registry instances
+ *
+ * <p>For historical reasons, Sling and Oak have their own metrics registry implementations. This
+ * may occur for other applications as well so we take care to gracefully handle multiple child
+ * registries.</p>
+ */
@HttpWhiteboardServletPattern("/metrics")
@HttpWhiteboardContextSelect("(osgi.http.whiteboard.context.name=org.osgi.service.http)")
@Component(service = Servlet.class)