Skip to content

Commit b5119ad

Browse files
committed
Reset connection if scrape failed
Signed-off-by: Max Melentyev <max.melentyev@reddit.com>
1 parent 32fae25 commit b5119ad

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

collector/src/main/java/io/prometheus/jmx/JmxScraper.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,18 @@ public synchronized void doScrape(MBeanReceiver receiver) throws Exception {
196196
// Method is synchronized to avoid multiple scrapes running concurrently
197197
// and let one of them refresh the cache in the middle of the scrape.
198198

199-
MBeanServerConnection beanConn = getMBeanServerConnection();
199+
try {
200+
MBeanServerConnection beanConn = getMBeanServerConnection();
200201

201-
for (ObjectName objectName : cache.mBeanNames) {
202-
long start = System.nanoTime();
203-
scrapeBean(receiver, beanConn, objectName);
204-
LOGGER.log(FINE, "TIME: %d ns for %s", System.nanoTime() - start, objectName);
202+
for (ObjectName objectName : cache.mBeanNames) {
203+
long start = System.nanoTime();
204+
scrapeBean(receiver, beanConn, objectName);
205+
LOGGER.log(FINE, "TIME: %d ns for %s", System.nanoTime() - start, objectName);
206+
}
207+
} finally {
208+
// reconnect to resolve connection issues
209+
// TODO: should it make a single retry with a new connection?
210+
_beanConn = null;
205211
}
206212
}
207213

0 commit comments

Comments
 (0)