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.

Prometheus metrics from collector server

See original GitHub issue

Hi,

I’m looking into javamelody’s collector server and I’d like to know if there’s a way to obtain prometheus metrics from the collector server, similar to how we can query http://host/monitoring?format=prometheus. When I try to call http://collector-host/javamelody?format=prometheus, I get a 500 error java.lang.IllegalStateException: WRITER, (javamelody server 1.81).

The collector server is very useful when you use intermitent applications, and prometheus is a good time-series database to persist the centralized data from the collector server; if this isn’t possible, is there an alternative I could use to expose the javamelody collector server data to grafana?

Thank you for the good work!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Barbierocommented, Feb 14, 2020

my testing environment:

  • JavaMelody collect server WAR 1.81.0
  • Java: AdoptOpenJDK 11

Run as: java -server -jar -Djavamelody.storage-directory=/home/path/to/javamelody/storage javamelody-collector-server-1.81.0.war --httpPort=8090

Two instances of Spring Boot v1.5.22 with javamelody 1.72.0(latest for spring boot 1.5), which are registering themselves under the application name “backend”, running through AdoptOpenJDK 8

URL for javamelody is being accessed as http://localhost:8090/javamelody?format=prometheus&application=backend

Exception thrown:

fev 14, 2020 8:12:36 AM org.eclipse.jetty.util.log.JavaUtilLog warn
ADVERTÊNCIA: /javamelody
java.lang.IllegalStateException: WRITER
	at org.eclipse.jetty.server.Response.getOutputStream(Response.java:691)
	at net.bull.javamelody.internal.web.HtmlController.getWriter(HtmlController.java:131)
	at net.bull.javamelody.internal.web.MonitoringController.getWriter(MonitoringController.java:304)
	at net.bull.javamelody.internal.web.CollectorController.createWriterFromOutputStream(CollectorController.java:512)
	at net.bull.javamelody.internal.web.CollectorController.writeMessage(CollectorController.java:492)
	at net.bull.javamelody.internal.web.CollectorController.doMonitoring(CollectorController.java:178)
	at net.bull.javamelody.CollectorServlet.doGet(CollectorServlet.java:102)
	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:686)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:533)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:428)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:370)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
	at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at winstone.BoundedExecutorService$1.run(BoundedExecutorService.java:77)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

In order to register my spring-boot applications with the collector server, I use the following component, which waits until the server is up and running to try to register itself(apologies for pt-BR comments):

@Component
@ConditionalOnProperty(JavaMelodyCollectServerRegistrar.PROPERTY_JAVAMELODY_SERVER_URL)
public class JavaMelodyCollectServerRegistrar implements ApplicationListener<ApplicationReadyEvent> {
	private static final Logger LOGGER = LoggerFactory.getLogger(JavaMelodyCollectServerRegistrar.class);

	static final String PROPERTY_JAVAMELODY_SERVER_URL = "accountfy.javamelody.url";
	private static final String PROPERTY_JAVAMELODY_APPLICATION_NAME = "accountfy.javamelody.applicationName";

	@Value("${" + PROPERTY_JAVAMELODY_SERVER_URL + "}")
	private String javaMelodyUrl;

	@Value("${" + PROPERTY_JAVAMELODY_APPLICATION_NAME + "}")
	private String javaMelodyAppName;

	@Value("${server.port}")
	private String serverPort;

	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		String selfUrl = "";
		try {
			// Para registrar a aplicação no javamelody, precisamos de um ip para
			// comunicação.
			// O que é problemático quando consideramos que no k8s, pods têm IPs
			// intermitentes e variáveis.
			// Por isso vamos perguntar direto para o Java qual o nosso IP.
			String hostAddr = InetAddress.getLocalHost().getHostAddress();
			selfUrl = MessageFormat.format("http://{0}:{1}", hostAddr, serverPort);

			URL collectServerUrl = new URL(javaMelodyUrl);
			URL applicationNodeUrl = new URL(selfUrl);

			LOGGER.info("Registrando servidor \"{}\" de monitoramento com JavaMelody, URL: {} ; URL local: {}",
					javaMelodyAppName, collectServerUrl.toExternalForm(), applicationNodeUrl.toExternalForm());

			net.bull.javamelody.MonitoringFilter.registerApplicationNodeInCollectServer(javaMelodyAppName,
					collectServerUrl, applicationNodeUrl);
		} catch (UnknownHostException e) {
			LOGGER.error("Erro registrando monitoramento: Host desconhecido", e);
		} catch (MalformedURLException ex) {
			LOGGER.error("Erro registrando monitoramento: URL(s) malformada(s). Servidor: {} ; App: {}", javaMelodyUrl,
					selfUrl);
		}
	}

	@PreDestroy
	public void onDestroy() {
		LOGGER.info("Desregistrando do servidor do javamelody");
		try {
			net.bull.javamelody.MonitoringFilter.unregisterApplicationNodeInCollectServer();
		} catch (IOException e) {
			LOGGER.error("Erro ao desregistrar a aplicação do javamelody", e);
		}
	}
}

(in this instance, javaMelodyUrl = “http://localhost:8090” and javaMelodyAppName = “backend”)

Do note that I can access other information just fine. Also, this error occurs when the javamelody collector server is of the same version as the spring-boot counterparts (ie. 1.72.0). Using Chrome v80

Is it possible that the old versions from my servers are having trouble?

0reactions
evernatcommented, Feb 16, 2020

Enhancement registered in the issue above. Closing this one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to collect Prometheus metrics with the OpenTelemetry ...
Here, we will look into how we can scrape Prometheus metrics with the OpenTelemetry Collector and send them to a remote write destination ......
Read more >
Writing exporters - Prometheus.io
For example, the mdadm collector hand-parses a file and exposes metrics created specifically for that collector, so we may as well get the...
Read more >
stolostron/metrics-collector: Prometheus push federation
Metrics Collector implements a client to "scrape" or collect data from OpenShift Promethus and performs a push fedration to a Thanos instance hosted...
Read more >
OpenTelemetry Collector Prometheus [full guide with code]
You can use OpenTelemetry Collector to pull Prometheus metrics using ... It can process billions of spans and metrics on a single server...
Read more >
Guide To The Prometheus Node Exporter - OpsRamp
Most Kubernetes clusters expose cluster-level server metrics and ... You can review a list of all existing collectors for the Prometheus Node Exporter...
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