Closing metricsconfigs.txt
This commit is contained in:
parent
ce1d6b8460
commit
75727840df
|
@ -139,38 +139,39 @@ public class JMXFetch {
|
|||
}
|
||||
|
||||
private static List<String> getInternalMetricFiles() {
|
||||
try {
|
||||
final InputStream metricConfigsStream =
|
||||
JMXFetch.class.getResourceAsStream("metricconfigs.txt");
|
||||
if (metricConfigsStream == null) {
|
||||
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);
|
||||
final InputStream metricConfigsStream = JMXFetch.class.getResourceAsStream("metricconfigs.txt");
|
||||
if (metricConfigsStream == null) {
|
||||
log.debug("metricconfigs not found. returning empty set");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
try {
|
||||
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
|
||||
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) {
|
||||
log.debug("error reading metricconfigs. returning empty set", e);
|
||||
return Collections.emptyList();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(metricConfigsStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue