Giter Club home page Giter Club logo

Comments (5)

flecno avatar flecno commented on August 24, 2024 21

I figure out to integrate dropwizard metrics.

  1. 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>
  2. 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");
        }
    }
  3. add a new job in the prometheus.yml with the option metrics_path: '/prometheusMetrics'

I hope it helps as quick start.

from client_java.

wdittmer-mp avatar wdittmer-mp commented on August 24, 2024 5

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.

brian-brazil avatar brian-brazil commented on August 24, 2024

@dopuskh3 An example in the class javadoc would be useful.

from client_java.

riskiana avatar riskiana commented on August 24, 2024

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.

alexterman avatar alexterman commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.