Closing metricsconfigs.txt
This commit is contained in:
parent
ce1d6b8460
commit
75727840df
|
@ -139,38 +139,39 @@ public class JMXFetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> getInternalMetricFiles() {
|
private static List<String> getInternalMetricFiles() {
|
||||||
try {
|
final InputStream metricConfigsStream = JMXFetch.class.getResourceAsStream("metricconfigs.txt");
|
||||||
final InputStream metricConfigsStream =
|
if (metricConfigsStream == null) {
|
||||||
JMXFetch.class.getResourceAsStream("metricconfigs.txt");
|
log.debug("metricconfigs not found. returning empty set");
|
||||||
if (metricConfigsStream == null) {
|
return Collections.emptyList();
|
||||||
log.debug("metricconfigs not found. returning empty set");
|
}
|
||||||
return Collections.emptyList();
|
|
||||||
} else {
|
|
||||||
final String configs = IOUtils.toString(metricConfigsStream, StandardCharsets.UTF_8);
|
|
||||||
final String[] split = configs.split("\n");
|
|
||||||
final List<String> result = new ArrayList<>(split.length);
|
|
||||||
final SortedSet<String> integrationName = new TreeSet<>();
|
|
||||||
for (final String config : split) {
|
|
||||||
integrationName.clear();
|
|
||||||
integrationName.add(config.replace(".yaml", ""));
|
|
||||||
if (Config.get().isJmxFetchIntegrationEnabled(integrationName, false)) {
|
|
||||||
final URL resource = JMXFetch.class.getResource("metricconfigs/" + config);
|
|
||||||
|
|
||||||
// jar!/ means a file internal to a jar, only add the part after if it exists
|
try {
|
||||||
final String path = resource.getPath();
|
final String configs = IOUtils.toString(metricConfigsStream, StandardCharsets.UTF_8);
|
||||||
final int filenameIndex = path.indexOf("jar!/");
|
final String[] split = configs.split("\n");
|
||||||
if (filenameIndex != -1) {
|
final List<String> result = new ArrayList<>(split.length);
|
||||||
result.add(path.substring(filenameIndex + 5));
|
final SortedSet<String> integrationName = new TreeSet<>();
|
||||||
} else {
|
for (final String config : split) {
|
||||||
result.add(path.substring(1));
|
integrationName.clear();
|
||||||
}
|
integrationName.add(config.replace(".yaml", ""));
|
||||||
|
if (Config.get().isJmxFetchIntegrationEnabled(integrationName, false)) {
|
||||||
|
final URL resource = JMXFetch.class.getResource("metricconfigs/" + config);
|
||||||
|
|
||||||
|
// jar!/ means a file internal to a jar, only add the part after if it exists
|
||||||
|
final String path = resource.getPath();
|
||||||
|
final int filenameIndex = path.indexOf("jar!/");
|
||||||
|
if (filenameIndex != -1) {
|
||||||
|
result.add(path.substring(filenameIndex + 5));
|
||||||
|
} else {
|
||||||
|
result.add(path.substring(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
log.debug("error reading metricconfigs. returning empty set", e);
|
log.debug("error reading metricconfigs. returning empty set", e);
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(metricConfigsStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue