question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NoSuchMethodError error on CollectorRegistry.filteredMetricFamilySamples when collecting DefaultExports

See original GitHub issue

I am attempting to collect default exports in addition to a few metrics, but adding DefaultExports.initialize() results in the error below. Removing that line will produce the metrics I am collecting (see as an example a basic counter.)

Stacktrace:

java.lang.NoSuchMethodError: io.prometheus.client.CollectorRegistry.filteredMetricFamilySamples(Ljava/util/Set;)Ljava/util/Enumeration;
	at io.prometheus.client.exporter.MetricsServlet.doGet(MetricsServlet.java:43)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:681)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:449)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1084)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:376)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1018)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:451)
	at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:252)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:266)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:240)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527)
	at java.lang.Thread.run(Thread.java:748)

Here is sample code to replicate:

import java.net.InetSocketAddress;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import mlab.dataviz.metrics.HTTPRootHandler;
import io.prometheus.client.Counter;

public class Metrics implements Runnable {
	private static final Logger LOG = LoggerFactory.getLogger(Runner.class);

	private InetSocketAddress port;
	private Counter requestsCounter;

	public Metrics() {
		// start prometheus collection server on port 9090
		this.port = new InetSocketAddress(9090);

		// track number of server boots, so we have a sense of how much these are
		// failing.
		this.bootCounter = Counter.build().name("simple_counter")
				.help("Simple Counter")
				.register();

		this.bootCounter.inc();
	}

	@Override
	public void run() {

		Server server = new Server(this.port);

		ServerConnector connector = new ServerConnector(server);

		connector.setPort(9090);
		connector.setHost("localhost");

		ServletContextHandler context = new ServletContextHandler();
		context.setContextPath("/");
		server.setHandler(context);

		// Add root servlet (outputs hello world.)
		context.addServlet(new ServletHolder(new HTTPRootHandler()), "/");
		
		// Add metrics servlet
		context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");

		// Add metrics about CPU, JVM memory etc.
		DefaultExports.initialize();

		try {
			// Start the webserver.
			server.start();
			server.join();
		} catch (Exception e) {
			e.printStackTrace();
			LOG.error(e.getLocalizedMessage());
		}
	}
}

In another class:

       public static void main(String[] args) throws InterruptedException {
		// Prometheus http server
		Metrics m = new Metrics();
		Thread metricsThread = new Thread(m);
		metricsThread.start();
      }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brian-brazilcommented, Nov 13, 2017

You should always use consistent versions of the various parts of the simpleclient, 0.0.10 is quite old compared to the rest.

In addition, the node exporter should already expose all you need to track reboots.

0reactions
iroscommented, Nov 13, 2017

Ah you are correct. Thank you so much for catching that. Hopefully this will be useful to someone else. Closing. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

CollectorRegistry (Prometheus Java Suite 0.15.0 API)
Enumeration of metrics where sampleNameFilter.test(name) returns true for each name in Collector.MetricFamilySamples.getNames() .
Read more >
io.prometheus.client.exporter.common.TextFormat.write004 ...
try (OutputStreamWriter writer = new OutputStreamWriter(stream)) { TextFormat.write004(writer, collectorRegistry.metricFamilySamples());
Read more >
Why is SpringBoot upgrade from 2.3.0 to 2.5.0 failing to start ...
From the caused by it looks like Micrometer dependecny is missing or not the correct version, you need to add it to pom.xml...
Read more >
Writing client libraries - Prometheus.io
In addition ENCOURAGED means that a feature is desirable for a library to have, but it's okay if ... Collectors get registered with...
Read more >
Error in Kafka startup with the JMX exporter - java.lang ...
Solved: Hi All, I'm trying to integrate Prometheus to collect Kafka metrics. I'm getting error in starting up - 176547.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found