Comments (5)
I figure out to integrate dropwizard metrics.
-
add the client libs to your
pom.xml
:<dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient</artifactId> <version>0.0.13</version> </dependency> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_servlet</artifactId> <version>0.0.13</version> </dependency> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient_dropwizard</artifactId> <version>0.0.13</version> </dependency>
-
register a new "AdminServlet" in the Dropwizard Application:
public class DropwizardApplication extends Application<MyConfiguration> { public static void main(String[] args) throws Exception { new DropwizardApplication().run(args); } @Override public void run(SearcherConfiguration configuration, Environment environment) throws Exception { CollectorRegistry collectorRegistry = new CollectorRegistry(); collectorRegistry.register(new DropwizardExports(environment.metrics())); environment.admin() .addServlet("prometheusMetrics", new MetricsServlet(collectorRegistry)) .addMapping("/prometheusMetrics"); } }
-
add a new job in the
prometheus.yml
with the optionmetrics_path: '/prometheusMetrics'
I hope it helps as quick start.
from client_java.
I am using ryantenney/metrics-spring and wanted to do the same thing, since the /metrics endpoint from Spring is not compatible with Prometheus.
The following works for me and I hope it helps others.
import com.codahale.metrics.MetricRegistry;
import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.dropwizard.DropwizardExports;
import io.prometheus.client.exporter.MetricsServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
@Configuration
public class SpringMetricsConfiguration extends MetricsConfigurerAdapter {
@Autowired
private CollectorRegistry collectorRegistry;
@Bean
public CollectorRegistry collectorRegistry() {
return new CollectorRegistry();
}
@Bean
@DependsOn("collectorRegistry")
public ServletRegistrationBean metricsServletRegistrationBean() {
return new ServletRegistrationBean(new MetricsServlet(collectorRegistry()),
"/prometheusMetrics");
}
@Override
public void configureReporters(MetricRegistry metricRegistry) {
collectorRegistry.register(new DropwizardExports(metricRegistry));
}
}
In the log line you will see something like:
2017-01-25 16:26:28.840 INFO 12663 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'metricsServlet' to [/prometheusMetrics]
And the endpoint will show something like:
GET http://localhost:8080/prometheusMetrics
returns
# HELP gauge_response_v1_graphql Generated from Dropwizard metric import (metric=gauge.response.v1.graphql, type=org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices$SimpleGauge)
# TYPE gauge_response_v1_graphql gauge
gauge_response_v1_graphql 3.0
# HELP counter_status_200_v1_graphql Generated from Dropwizard metric import (metric=counter.status.200.v1.graphql, type=com.codahale.metrics.Counter)
# TYPE counter_status_200_v1_graphql gauge
counter_status_200_v1_graphql 15.0
...
from client_java.
@dopuskh3 An example in the class javadoc would be useful.
from client_java.
I am using ryantenney/metrics-spring and wanted to do the same thing, since the /metrics endpoint from Spring is not compatible with Prometheus.
The following works for me and I hope it helps others.import com.codahale.metrics.MetricRegistry; import com.ryantenney.metrics.spring.config.annotation.MetricsConfigurerAdapter; import io.prometheus.client.CollectorRegistry; import io.prometheus.client.dropwizard.DropwizardExports; import io.prometheus.client.exporter.MetricsServlet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; @Configuration public class SpringMetricsConfiguration extends MetricsConfigurerAdapter { @Autowired private CollectorRegistry collectorRegistry; @Bean public CollectorRegistry collectorRegistry() { return new CollectorRegistry(); } @Bean @DependsOn("collectorRegistry") public ServletRegistrationBean metricsServletRegistrationBean() { return new ServletRegistrationBean(new MetricsServlet(collectorRegistry()), "/prometheusMetrics"); } @Override public void configureReporters(MetricRegistry metricRegistry) { collectorRegistry.register(new DropwizardExports(metricRegistry)); } }
Hi @wdittmer-mp , what if I want to change that into web.xml because I'm not using spring boot
from client_java.
3. metrics_path
I am using the described here example of @flecno on DW application, but rate/mean metrics are not converted to Prometheus metrics:
Example of DW metric on my application
io.dropwizard.jetty.MutableServletContextHandler.get-requests: { count: 6, max: 0.051000000000000004, mean: 0.005, min: 0.005, p50: 0.005, p75: 0.005, p95: 0.005, p98: 0.005, p99: 0.005, p999: 0.005, stddev: 1.9847832426318228e-11, m15_rate: 0.0015359302165743655, m1_rate: 0.015991117074136592, m5_rate: 0.0033247502747734284, mean_rate: 0.0013169171410327021, duration_units: "seconds", rate_units: "calls/second" },
The converted Prometheus metrics
# HELP io_dropwizard_jetty_MutableServletContextHandler_get_requests Generated from Dropwizard metric import (metric=io.dropwizard.jetty.MutableServletContextHandler.get-requests, type=com.codahale.metrics.Timer) TYPE io_dropwizard_jetty_MutableServletContextHandler_get_requests summary io_dropwizard_jetty_MutableServletContextHandler_get_requests{quantile="0.5",} 0.009000000000000001 io_dropwizard_jetty_MutableServletContextHandler_get_requests{quantile="0.75",} 0.013000000000000001 io_dropwizard_jetty_MutableServletContextHandler_get_requests{quantile="0.95",} 0.013000000000000001 io_dropwizard_jetty_MutableServletContextHandler_get_requests{quantile="0.98",} 0.013000000000000001 io_dropwizard_jetty_MutableServletContextHandler_get_requests{quantile="0.99",} 0.013000000000000001 io_dropwizard_jetty_MutableServletContextHandler_get_requests{quantile="0.999",} 0.013000000000000001 io_dropwizard_jetty_MutableServletContextHandler_get_requests_count 5.0
No stddev: 1.9847832426318228e-11, m15_rate: 0.0015359302165743655, m1_rate: 0.015991117074136592, m5_rate: 0.0033247502747734284, mean_rate: 0.0013169171410327021,
are propogated. Is it fo reason?
from client_java.
Related Issues (20)
- Endpoint actuator/prometheus not working on macOS HOT 1
- Publish a BOM again
- Implement latest changes in the Prometheus Protobuf format
- [httpserver exporter] No option to specify a wait time for ongoing requests when closing the server HOT 3
- Explicit Exception for Duplicate Labels during Scrape HOT 1
- Stress test failure in DropwizardExportsTest HOT 2
- Stress test failure in SlidingWindowTest HOT 1
- dropwizard5 MapperConfig doesn't rename the metric? HOT 4
- How to remove all metrics in the defaultRegistry HOT 5
- Failing while building simpleclient_httpserver version parent-0.15.0 using mvn clean install HOT 4
- log4j2 instrumentation support for 1.X?
- Flaky test - SlidingWindowTest
- Filter parameter causes HTTP Status 400 – Bad Request HOT 1
- info required for compatible version with openjdk21 HOT 2
- Counts in ClassicHistogramBuckets cannot be negative. HOT 1
- StatefulMetric clear() invocation causes noLabels increase to stop reporting on collect()
- Integrating Native Histograms with Spring 2.7.x and Prometheus client_java 1.3.1: Challenges in Writing Native Histograms to Response Object
- Inconsistencies between PrometheusNaming.sanitizeMetricName() methods
- UnknownDataPointSnapshot constructor ignores labels
- [FeatureRequest] Restore MetricsFilter in the servlet modules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from client_java.