Skip to content
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
38 changes: 20 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 @@ -193,6 +205,8 @@ private void reloadConfig() {

try {
Map<String, Object> newYamlConfig = new Yaml().load(fr);
// TODO: call config.Close() on the old config. But need to make sure that it's
// not used by other threads.
config = loadConfig(newYamlConfig);
config.lastUpdate = configFile.lastModified();
configReloadSuccess.inc();
Expand Down Expand Up @@ -716,18 +730,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 +738,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