11package datadog .trace .agent .jmxfetch ;
22
3+ import static org .datadog .jmxfetch .AppConfig .ACTION_COLLECT ;
4+
35import com .google .common .collect .ImmutableList ;
46import datadog .trace .api .Config ;
57import java .io .IOException ;
1618import org .apache .commons .io .IOUtils ;
1719import org .datadog .jmxfetch .App ;
1820import org .datadog .jmxfetch .AppConfig ;
21+ import org .datadog .jmxfetch .reporter .ReporterFactory ;
1922
2023@ Slf4j
2124public class JMXFetch {
@@ -38,6 +41,14 @@ private static void run(final Config config) {
3841 return ;
3942 }
4043
44+ if (!log .isDebugEnabled ()
45+ && System .getProperty ("org.slf4j.simpleLogger.log.org.datadog.jmxfetch" ) == null ) {
46+ // Reduce noisiness of jmxfetch logging.
47+ System .setProperty ("org.slf4j.simpleLogger.log.org.datadog.jmxfetch" , "warn" );
48+ }
49+
50+ final String jmxFetchConfigDir = config .getJmxFetchConfigDir ();
51+ final List <String > jmxFetchConfigs = config .getJmxFetchConfigs ();
4152 final List <String > internalMetricsConfigs = getInternalMetricFiles ();
4253 final List <String > metricsConfigs = config .getJmxFetchMetricsConfigs ();
4354 final Integer checkPeriod = config .getJmxFetchCheckPeriod ();
@@ -48,7 +59,9 @@ private static void run(final Config config) {
4859 final String logLevel = getLogLevel ();
4960
5061 log .info (
51- "JMXFetch config: {} {} {} {} {} {} {} {}" ,
62+ "JMXFetch config: {} {} {} {} {} {} {} {} {} {}" ,
63+ jmxFetchConfigDir ,
64+ jmxFetchConfigs ,
5265 internalMetricsConfigs ,
5366 metricsConfigs ,
5467 checkPeriod ,
@@ -57,17 +70,24 @@ private static void run(final Config config) {
5770 reporter ,
5871 logLocation ,
5972 logLevel );
60- final AppConfig appConfig =
61- AppConfig .create (
62- DEFAULT_CONFIGS ,
63- internalMetricsConfigs ,
64- metricsConfigs ,
65- checkPeriod ,
66- refreshBeansPeriod ,
67- globalTags ,
68- reporter ,
69- logLocation ,
70- logLevel );
73+
74+ final AppConfig .AppConfigBuilder configBuilder =
75+ AppConfig .builder ()
76+ .action (ImmutableList .of (ACTION_COLLECT ))
77+ .confdDirectory (jmxFetchConfigDir )
78+ .yamlFileList (jmxFetchConfigs )
79+ .targetDirectInstances (true )
80+ .instanceConfigResources (DEFAULT_CONFIGS )
81+ .metricConfigResources (internalMetricsConfigs )
82+ .metricConfigFiles (metricsConfigs )
83+ .refreshBeansPeriod (refreshBeansPeriod )
84+ .globalTags (globalTags )
85+ .reporter (ReporterFactory .getReporter (reporter ));
86+
87+ if (checkPeriod != null ) {
88+ configBuilder .checkPeriod (checkPeriod );
89+ }
90+ final AppConfig appConfig = configBuilder .build ();
7191
7292 final Thread thread =
7393 new Thread (
@@ -131,7 +151,7 @@ private static List<String> getInternalMetricFiles() {
131151 for (final String config : split ) {
132152 integrationName .clear ();
133153 integrationName .add (config .replace (".yaml" , "" ));
134- if (Config .integrationEnabled (integrationName , false )) {
154+ if (Config .jmxFetchIntegrationEnabled (integrationName , false )) {
135155 final URL resource = JMXFetch .class .getResource ("metricconfigs/" + config );
136156 result .add (resource .getPath ().split ("\\ .jar!/" )[1 ]);
137157 }
0 commit comments