diff --git a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java index 0dac2391..13930d93 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java @@ -196,12 +196,18 @@ public synchronized void doScrape(MBeanReceiver receiver) throws Exception { // Method is synchronized to avoid multiple scrapes running concurrently // and let one of them refresh the cache in the middle of the scrape. - MBeanServerConnection beanConn = getMBeanServerConnection(); + try { + MBeanServerConnection beanConn = getMBeanServerConnection(); - for (ObjectName objectName : cache.mBeanNames) { - long start = System.nanoTime(); - scrapeBean(receiver, beanConn, objectName); - LOGGER.log(FINE, "TIME: %d ns for %s", System.nanoTime() - start, objectName); + for (ObjectName objectName : cache.mBeanNames) { + long start = System.nanoTime(); + scrapeBean(receiver, beanConn, objectName); + LOGGER.log(FINE, "TIME: %d ns for %s", System.nanoTime() - start, objectName); + } + } finally { + // reconnect to resolve connection issues + // TODO: should it make a single retry with a new connection? + _beanConn = null; } }