io.prometheus.client.dropwizard.DropwizardExports Java Examples
The following examples show how to use
io.prometheus.client.dropwizard.DropwizardExports.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaDropwizard.java From java_examples with Apache License 2.0 | 6 votes |
public static void main( String[] args ) throws Exception { // Increment the counter. counter.inc(); // Hook the Dropwizard registry into the Prometheus registry // via the DropwizardExports collector. CollectorRegistry.defaultRegistry.register(new DropwizardExports(metrics)); // Expose Prometheus metrics. Server server = new Server(1234); ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics"); // Add metrics about CPU, JVM memory etc. DefaultExports.initialize(); // Start the webserver. server.start(); server.join(); }
Example #2
Source File: Metrics.java From dcos-commons with Apache License 2.0 | 6 votes |
/** * Appends endpoint servlets to the provided {@code context} which will serve codahale-style and prometheus-style * metrics. */ public static void configureMetricsEndpoints( ServletContextHandler context, String codahaleMetricsEndpoint, String prometheusEndpoint) { // Metrics ServletHolder codahaleMetricsServlet = new ServletHolder("default", new com.codahale.metrics.servlets.MetricsServlet(METRICS)); context.addServlet(codahaleMetricsServlet, codahaleMetricsEndpoint); // Prometheus CollectorRegistry collectorRegistry = new CollectorRegistry(); collectorRegistry.register(new DropwizardExports(METRICS)); ServletHolder prometheusServlet = new ServletHolder("prometheus", new io.prometheus.client.exporter.MetricsServlet(collectorRegistry)); context.addServlet(prometheusServlet, prometheusEndpoint); }
Example #3
Source File: TaskApp.java From osgi-best-practices with Apache License 2.0 | 5 votes |
@Activate public TaskApp( @Reference TaskService taskService, @Reference CollectorRegistry registry ) { MetricRegistry metricRegistry = new MetricRegistry(); taskResource = new TaskResource(taskService, metricRegistry); registry.register(new DropwizardExports(metricRegistry)); }
Example #4
Source File: MetricsConfiguration.java From Spring-5.0-Projects with MIT License | 5 votes |
@Override public void onStartup(ServletContext servletContext) { if (jHipsterProperties.getMetrics().getPrometheus().isEnabled()) { String endpoint = jHipsterProperties.getMetrics().getPrometheus().getEndpoint(); log.debug("Initializing prometheus metrics exporting via {}", endpoint); CollectorRegistry.defaultRegistry.register(new DropwizardExports(metricRegistry)); servletContext .addServlet("prometheusMetrics", new MetricsServlet(CollectorRegistry.defaultRegistry)) .addMapping(endpoint); } }
Example #5
Source File: MetricsConfiguration.java From prebid-server-java with Apache License 2.0 | 5 votes |
@PostConstruct public void startPrometheusServer() { logger.info("Starting Prometheus Server on port {0,number,#}", prometheusPort); final Router router = Router.router(vertx); router.route("/metrics").handler(new MetricsHandler()); CollectorRegistry.defaultRegistry.register(new DropwizardExports(metricRegistry)); contextRunner.<HttpServer>runOnServiceContext(promise -> vertx.createHttpServer().requestHandler(router).listen(prometheusPort, promise)); logger.info("Successfully started Prometheus Server"); }
Example #6
Source File: MetricsConfiguration.java From ehcache3-samples with Apache License 2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) { if (jHipsterProperties.getMetrics().getPrometheus().isEnabled()) { String endpoint = jHipsterProperties.getMetrics().getPrometheus().getEndpoint(); log.debug("Initializing prometheus metrics exporting via {}", endpoint); CollectorRegistry.defaultRegistry.register(new DropwizardExports(metricRegistry)); servletContext .addServlet("prometheusMetrics", new MetricsServlet(CollectorRegistry.defaultRegistry)) .addMapping(endpoint); } }
Example #7
Source File: MetricsPrometheusReporterModule.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 5 votes |
@Override protected void configure() { addConfigBeans(); bind(DropwizardExports.class).toProvider(DropwizardExportsProvider.class); bind(CollectorRegistry.class).toProvider(CollectorRegistryProvider.class); bind(PushGateway.class).toProvider(PushGatewayProvider.class); addPeriodical(PushGatewayPeriodical.class); addRestResource(MetricsResource.class); }
Example #8
Source File: DropwizardExportsProviderTest.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 5 votes |
@Test public void getReturnsDropwizardExportsWithDropwizardMetrics() throws Exception { final MetricRegistry registry = new MetricRegistry(); registry.histogram("test.histogram"); final DropwizardExports dropwizardExports = new DropwizardExports(registry); final List<Collector.MetricFamilySamples> samples = dropwizardExports.collect(); assertEquals(1, samples.size()); final Collector.MetricFamilySamples element = samples.get(0); assertEquals("test_histogram", element.name); assertEquals(Collector.Type.SUMMARY, element.type); }
Example #9
Source File: CollectorRegistryProviderTest.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 5 votes |
@Test public void getReturnsCollectorRegistryWithDropwizardMetrics() throws Exception { final MetricRegistry registry = new MetricRegistry(); final Counter counter = registry.counter("test.counter"); counter.inc(42L); final DropwizardExports dropwizardExports = new DropwizardExports(registry); final CollectorRegistryProvider provider = new CollectorRegistryProvider(dropwizardExports); final CollectorRegistry collectorRegistry = provider.get(); assertEquals(new Double(42.0d), collectorRegistry.getSampleValue("test_counter")); }
Example #10
Source File: MetricsServlet.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Inject public MetricsServlet(final MetricRegistry registry) { super(registry); // JVM metrics are no longer automatically added in codahale-metrics registry.register(name("jvm", "vm"), new JvmAttributeGaugeSet()); registry.register(name("jvm", "memory"), new MemoryUsageGaugeSet()); registry.register(name("jvm", "buffers"), new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer())); registry.register(name("jvm", "fd_usage"), new FileDescriptorRatioGauge()); registry.register(name("jvm", "thread-states"), new ThreadStatesGaugeSet()); registry.register(name("jvm", "garbage-collectors"), new GarbageCollectorMetricSet()); // Export to Prometheus new DropwizardExports(registry).register(); }
Example #11
Source File: Metrics.java From dremio-oss with Apache License 2.0 | 4 votes |
/** * Creates a custom Prometheus Collector registry, registers * the dropwizard metrics with this registry, and attaches * it to a MetricsServlet, which is returned to the caller. */ public static Servlet createMetricsServlet() { CollectorRegistry registry = new CollectorRegistry(); registry.register(new DropwizardExports(RegistryHolder.REGISTRY)); return new MetricsServlet(registry); }
Example #12
Source File: PrometheusBootstrapper.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@PostConstruct public void init() { CollectorRegistry.defaultRegistry.clear(); new DropwizardExports(metricRegistry).register(); new DiscordExports(discordMetricsRegistry, lavaAudioService).register(); }
Example #13
Source File: WrapperMetricsServlet.java From sling-whiteboard with Apache License 2.0 | 4 votes |
@Override public void init() throws ServletException { super.init(); this.exports = new DropwizardExports(metrics); CollectorRegistry.defaultRegistry.register(this.exports); }
Example #14
Source File: DropwizardExportsProvider.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 4 votes |
@Override public DropwizardExports get() { return new DropwizardExports(metricRegistry); }
Example #15
Source File: CollectorRegistryProvider.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 4 votes |
@Inject public CollectorRegistryProvider(DropwizardExports dropwizardExports) { this.dropwizardExports = requireNonNull(dropwizardExports); }