Skip to content

Commit

Permalink
Reset connection if scrape failed
Browse files Browse the repository at this point in the history
Signed-off-by: Max Melentyev <[email protected]>
  • Loading branch information
max-melentyev committed Oct 24, 2024
1 parent 32fae25 commit b5119ad
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions collector/src/main/java/io/prometheus/jmx/JmxScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit b5119ad

Please sign in to comment.