-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exports dropwizard-metrics to prometheus format
Signed-off-by: Max Thonagel <12283268+thoniTUB@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/bakdata/conquery/metrics/prometheus/PrometheusBundle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.bakdata.conquery.metrics.prometheus; | ||
|
||
import com.bakdata.conquery.models.config.ConqueryConfig; | ||
import io.dropwizard.core.ConfiguredBundle; | ||
import io.dropwizard.core.setup.Bootstrap; | ||
import io.dropwizard.core.setup.Environment; | ||
import io.prometheus.client.CollectorRegistry; | ||
import io.prometheus.client.dropwizard.DropwizardExports; | ||
import io.prometheus.metrics.exporter.servlet.jakarta.PrometheusMetricsServlet; | ||
import io.prometheus.metrics.simpleclient.bridge.SimpleclientCollector; | ||
import org.eclipse.jetty.servlet.ServletHolder; | ||
|
||
public class PrometheusBundle implements ConfiguredBundle<ConqueryConfig> { | ||
|
||
@Override | ||
public void initialize(Bootstrap<?> bootstrap) { | ||
// Init simple_client https://www.robustperception.io/exposing-dropwizard-metrics-to-prometheus/ | ||
CollectorRegistry.defaultRegistry.register(new DropwizardExports(bootstrap.getMetricRegistry())); | ||
// Init client_java bridge: https://prometheus.github.io/client_java/migration/simpleclient/ | ||
SimpleclientCollector.builder().register(); | ||
} | ||
|
||
@Override | ||
public void run(ConqueryConfig configuration, Environment environment) throws Exception { | ||
|
||
environment.getAdminContext().addServlet(new ServletHolder(new PrometheusMetricsServlet()), "/metrics-prometheus"); | ||
} | ||
} |