Skip to content

Commit

Permalink
Merge pull request #768 from elonzh/feat/prometheus-metrics
Browse files Browse the repository at this point in the history
feat: support export metrics as prometheus format
  • Loading branch information
kermitt2 committed Jun 7, 2021
2 parents 8355430 + ed3bf0d commit 06f2679
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ project(":grobid-service") {
implementation "io.dropwizard:dropwizard-auth:1.3.23"
implementation "org.apache.pdfbox:pdfbox:2.0.3"
implementation "javax.activation:activation:1.1.1"
implementation "io.prometheus:simpleclient_dropwizard:0.11.0"
implementation "io.prometheus:simpleclient_servlet:0.11.0"

testImplementation "io.dropwizard:dropwizard-testing:1.3.17"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.dropwizard.forms.MultiPartBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import io.prometheus.client.dropwizard.DropwizardExports;
import io.prometheus.client.exporter.MetricsServlet;
import org.apache.commons.lang3.ArrayUtils;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import org.grobid.service.GrobidServiceConfiguration;
Expand All @@ -18,6 +20,7 @@

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletRegistration;
import java.io.File;
import java.util.Arrays;
import java.util.EnumSet;
Expand Down Expand Up @@ -55,6 +58,9 @@ private List<? extends Module> getGuiceModules() {
@Override
public void run(GrobidServiceConfiguration configuration, Environment environment) {
LOGGER.info("Service config={}", configuration);
new DropwizardExports(environment.metrics()).register();
ServletRegistration.Dynamic registration = environment.admin().addServlet("Prometheus", new MetricsServlet());
registration.addMapping("/metrics/prometheus");
environment.jersey().setUrlPattern(RESOURCES + "/*");

String allowedOrigins = configuration.getGrobid().getCorsAllowedOrigins();
Expand Down

0 comments on commit 06f2679

Please sign in to comment.