Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache JMX connection and MBeans names and attributes #1019

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions collector/src/main/java/io/prometheus/jmx/JmxCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,25 @@ private static class Config {
long lastUpdate = 0L;

MatchedRulesCache rulesCache;

private JmxScraper _jmxScraper;

JmxScraper jmxScraper() {
if (_jmxScraper == null) {
_jmxScraper =
new JmxScraper(
jmxUrl,
username,
password,
ssl,
includeObjectNames,
excludeObjectNames,
objectNameAttributeFilter);
}
return _jmxScraper;
}
}

private PrometheusRegistry prometheusRegistry;
private Config config;
private File configFile;
private long createTimeNanoSecs = System.nanoTime();
Expand All @@ -101,8 +117,6 @@ private static class Config {
private Gauge jmxScrapeError;
private Gauge jmxScrapeCachedBeans;

private final JmxMBeanPropertyCache jmxMBeanPropertyCache = new JmxMBeanPropertyCache();

public JmxCollector(File in) throws IOException, MalformedObjectNameException {
this(in, null);
}
Expand Down Expand Up @@ -130,8 +144,6 @@ public JmxCollector register() {
}

public JmxCollector register(PrometheusRegistry prometheusRegistry) {
this.prometheusRegistry = prometheusRegistry;

configReloadSuccess =
Counter.builder()
.name("jmx_config_reload_success_total")
Expand Down Expand Up @@ -716,18 +728,6 @@ public MetricSnapshots collect() {

Receiver receiver = new Receiver(config, stalenessTracker);

JmxScraper scraper =
new JmxScraper(
config.jmxUrl,
config.username,
config.password,
config.ssl,
config.includeObjectNames,
config.excludeObjectNames,
config.objectNameAttributeFilter,
receiver,
jmxMBeanPropertyCache);

long start = System.nanoTime();
double error = 0;

Expand All @@ -736,7 +736,7 @@ public MetricSnapshots collect() {
throw new IllegalStateException("JMXCollector waiting for startDelaySeconds");
}
try {
scraper.doScrape();
config.jmxScraper().doScrape(receiver);
} catch (Exception e) {
error = 1;
StringWriter sw = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public JmxMBeanPropertyCache() {
this.keyPropertiesPerBean = new ConcurrentHashMap<>();
}

public JmxMBeanPropertyCache(Set<ObjectName> mBeanNames) {
this();
for (ObjectName mBeanName : mBeanNames) {
getKeyPropertyList(mBeanName);
}
}

Map<ObjectName, LinkedHashMap<String, String>> getKeyPropertiesPerBean() {
return keyPropertiesPerBean;
}
Expand Down
Loading
Loading