Jian Li
Committed by Gerrit Code Review

[ONOS-4176] Extract InfluxDB access config in a separate service

With existing implementation, influxDB access related configuration
should be done in both reporter and retriever which may cause
potential inconsistency. With this commit, both reporter and
retriever refer to access configuration from InfluxDbMetricsConfig
so that we do not need to configure access parameters two times.

Change-Id: I25159abb24e46d9593ef71224da3f79e3687d36c
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.influxdbmetrics;
17 +
18 +import com.codahale.metrics.MetricRegistry;
19 +import com.izettle.metrics.influxdb.InfluxDbHttpSender;
20 +import com.izettle.metrics.influxdb.InfluxDbReporter;
21 +import org.apache.commons.lang.StringUtils;
22 +import org.apache.felix.scr.annotations.Activate;
23 +import org.apache.felix.scr.annotations.Component;
24 +import org.apache.felix.scr.annotations.Deactivate;
25 +import org.apache.felix.scr.annotations.Modified;
26 +import org.apache.felix.scr.annotations.Property;
27 +import org.apache.felix.scr.annotations.Reference;
28 +import org.apache.felix.scr.annotations.ReferenceCardinality;
29 +import org.apache.felix.scr.annotations.Service;
30 +import org.onlab.metrics.MetricsService;
31 +import org.onlab.util.Tools;
32 +import org.onosproject.cfg.ComponentConfigService;
33 +import org.onosproject.cluster.ClusterService;
34 +import org.onosproject.cluster.ControllerNode;
35 +import org.onosproject.core.CoreService;
36 +import org.osgi.service.component.ComponentContext;
37 +import org.slf4j.Logger;
38 +
39 +import java.util.Dictionary;
40 +import java.util.concurrent.TimeUnit;
41 +
42 +import static org.slf4j.LoggerFactory.getLogger;
43 +
44 +/**
45 + * A Metric reporter that reports all metrics value to influxDB server.
46 + */
47 +@Component(immediate = true)
48 +@Service
49 +public class DefaultInfluxDbMetricsReporter implements InfluxDbMetricsReporter {
50 + private final Logger log = getLogger(getClass());
51 +
52 + private static final int REPORT_PERIOD = 1;
53 + private static final TimeUnit REPORT_TIME_UNIT = TimeUnit.MINUTES;
54 +
55 + private static final String DEFAULT_PROTOCOL = "http";
56 + private static final String DEFAULT_METRIC_NAMES = "default";
57 + private static final String SEPARATOR = ":";
58 + private static final int DEFAULT_CONN_TIMEOUT = 1000;
59 + private static final int DEFAULT_READ_TIMEOUT = 1000;
60 +
61 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 + protected CoreService coreService;
63 +
64 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 + protected MetricsService metricsService;
66 +
67 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 + protected ComponentConfigService cfgService;
69 +
70 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 + protected ClusterService clusterService;
72 +
73 + @Property(name = "monitorAll", boolValue = true,
74 + label = "Enable to monitor all of metrics stored in metric registry " +
75 + "default is true")
76 + protected boolean monitorAll = true;
77 +
78 + @Property(name = "metricNames", value = DEFAULT_METRIC_NAMES,
79 + label = "Names of metric to be monitored in third party monitoring " +
80 + "server; default metric names are 'default'")
81 + protected String metricNames = DEFAULT_METRIC_NAMES;
82 +
83 + protected String address;
84 + protected int port;
85 + protected String database;
86 + protected String username;
87 + protected String password;
88 +
89 + private InfluxDbReporter influxDbReporter;
90 + private InfluxDbHttpSender influxDbHttpSender;
91 +
92 + @Activate
93 + public void activate() {
94 + cfgService.registerProperties(getClass());
95 + coreService.registerApplication("org.onosproject.influxdbmetrics");
96 +
97 + log.info("Started");
98 + }
99 +
100 + @Deactivate
101 + public void deactivate() {
102 + cfgService.unregisterProperties(getClass(), false);
103 +
104 + log.info("Stopped");
105 + }
106 +
107 + @Modified
108 + public void modified(ComponentContext context) {
109 + readComponentConfiguration(context);
110 + restartReport();
111 + }
112 +
113 + @Override
114 + public void startReport() {
115 + try {
116 + influxDbHttpSender = new InfluxDbHttpSender(DEFAULT_PROTOCOL, address,
117 + port, database, username + SEPARATOR + password, REPORT_TIME_UNIT,
118 + DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
119 + MetricRegistry mr = metricsService.getMetricRegistry();
120 + influxDbReporter = InfluxDbReporter.forRegistry(addHostPrefix(filter(mr)))
121 + .convertRatesTo(TimeUnit.SECONDS)
122 + .convertDurationsTo(TimeUnit.MILLISECONDS)
123 + .build(influxDbHttpSender);
124 + influxDbReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT);
125 + log.info("Start to report metrics to influxDB.");
126 + } catch (Exception e) {
127 + log.error("Fail to connect to given influxDB server!");
128 + }
129 + }
130 +
131 + @Override
132 + public void stopReport() {
133 + influxDbReporter.stop();
134 + influxDbHttpSender = null;
135 + influxDbReporter = null;
136 + log.info("Stop reporting metrics to influxDB.");
137 + }
138 +
139 + @Override
140 + public void restartReport() {
141 + stopReport();
142 + startReport();
143 + }
144 +
145 + @Override
146 + public void config(String address, int port, String database,
147 + String username, String password) {
148 + this.address = address;
149 + this.port = port;
150 + this.database = database;
151 + this.username = username;
152 + this.password = password;
153 + }
154 +
155 + /**
156 + * Filters the metrics to only include a set of the given metrics.
157 + *
158 + * @param metricRegistry original metric registry
159 + * @return filtered metric registry
160 + */
161 + protected MetricRegistry filter(MetricRegistry metricRegistry) {
162 + if (!monitorAll) {
163 + final MetricRegistry filtered = new MetricRegistry();
164 + metricRegistry.getNames().stream().filter(name ->
165 + containsName(name, metricNames)).forEach(name ->
166 + filtered.register(name, metricRegistry.getMetrics().get(name)));
167 + return filtered;
168 + } else {
169 + return metricRegistry;
170 + }
171 + }
172 +
173 + /**
174 + * Appends node IP prefix to all performance metrics.
175 + *
176 + * @param metricRegistry original metric registry
177 + * @return prefix added metric registry
178 + */
179 + protected MetricRegistry addHostPrefix(MetricRegistry metricRegistry) {
180 + MetricRegistry moddedRegistry = new MetricRegistry();
181 + ControllerNode node = clusterService.getLocalNode();
182 + String prefix = node.id().id() + ".";
183 + metricRegistry.getNames().stream().forEach(name ->
184 + moddedRegistry.register(prefix + name, metricRegistry.getMetrics().get(name)));
185 +
186 + return moddedRegistry;
187 + }
188 +
189 + /**
190 + * Looks up whether the metric name contains the given prefix keywords.
191 + * Note that the keywords are separated with comma as delimiter.
192 + *
193 + * @param full the original metric name that to be compared with
194 + * @param prefixes the prefix keywords that are matched against with the metric name
195 + * @return boolean value that denotes whether the metric name starts with the given prefix
196 + */
197 + protected boolean containsName(String full, String prefixes) {
198 + String[] prefixArray = StringUtils.split(prefixes, ",");
199 + for (String prefix : prefixArray) {
200 + if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) {
201 + return true;
202 + }
203 + }
204 + return false;
205 + }
206 +
207 + /**
208 + * Extracts properties from the component configuration context.
209 + *
210 + * @param context the component context
211 + */
212 + private void readComponentConfiguration(ComponentContext context) {
213 + Dictionary<?, ?> properties = context.getProperties();
214 +
215 + String metricNameStr = Tools.get(properties, "metricNames");
216 + metricNames = metricNameStr != null ? metricNameStr : DEFAULT_METRIC_NAMES;
217 + log.info("Configured. Metric name is {}", metricNames);
218 +
219 + Boolean monitorAllEnabled = Tools.isPropertyEnabled(properties, "monitorAll");
220 + if (monitorAllEnabled == null) {
221 + log.info("Monitor all metrics is not configured, " +
222 + "using current value of {}", monitorAll);
223 + } else {
224 + monitorAll = monitorAllEnabled;
225 + log.info("Configured. Monitor all metrics is {}",
226 + monitorAll ? "enabled" : "disabled");
227 + }
228 + }
229 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.influxdbmetrics;
17 +
18 +import org.apache.felix.scr.annotations.Activate;
19 +import org.apache.felix.scr.annotations.Component;
20 +import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Modified;
22 +import org.apache.felix.scr.annotations.Property;
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.onlab.util.Tools;
26 +import org.onosproject.cfg.ComponentConfigService;
27 +import org.onosproject.core.CoreService;
28 +import org.osgi.service.component.ComponentContext;
29 +import org.slf4j.Logger;
30 +
31 +import java.util.Dictionary;
32 +
33 +import static org.slf4j.LoggerFactory.getLogger;
34 +
35 +/**
36 + * A configuration service for InfluxDB metrics.
37 + * Both InfluxDbMetrics Reporter and Retriever rely on this configuration service.
38 + */
39 +@Component(immediate = true)
40 +public class InfluxDbMetricsConfig {
41 +
42 + private final Logger log = getLogger(getClass());
43 +
44 + private static final String DEFAULT_ADDRESS = "localhost";
45 + private static final int DEFAULT_PORT = 8086;
46 +
47 + private static final String DEFAULT_DATABASE = "onos";
48 + private static final String DEFAULT_USERNAME = "onos";
49 + private static final String DEFAULT_PASSWORD = "onos.password";
50 +
51 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 + protected CoreService coreService;
53 +
54 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 + protected InfluxDbMetricsReporter influxDbMetricsReporter;
56 +
57 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 + protected ComponentConfigService cfgService;
59 +
60 + @Property(name = "address", value = DEFAULT_ADDRESS,
61 + label = "IP address of influxDB server; default is localhost")
62 + protected String address = DEFAULT_ADDRESS;
63 +
64 + @Property(name = "port", intValue = DEFAULT_PORT,
65 + label = "Port number of influxDB server; default is 8086")
66 + protected int port = DEFAULT_PORT;
67 +
68 + @Property(name = "database", value = DEFAULT_DATABASE,
69 + label = "Database name of influxDB server; default is onos")
70 + protected String database = DEFAULT_DATABASE;
71 +
72 + @Property(name = "username", value = DEFAULT_USERNAME,
73 + label = "Username of influxDB server; default is onos")
74 + protected String username = DEFAULT_USERNAME;
75 +
76 + @Property(name = "password", value = DEFAULT_PASSWORD,
77 + label = "Password of influxDB server; default is onos.password")
78 + protected String password = DEFAULT_PASSWORD;
79 +
80 + @Activate
81 + public void activate() {
82 + cfgService.registerProperties(getClass());
83 +
84 + coreService.registerApplication("org.onosproject.influxdbmetrics");
85 +
86 + configReporter(influxDbMetricsReporter);
87 + influxDbMetricsReporter.startReport();
88 +
89 + log.info("Started");
90 + }
91 +
92 + @Deactivate
93 + public void deactivate() {
94 + cfgService.unregisterProperties(getClass(), false);
95 +
96 + influxDbMetricsReporter.stopReport();
97 + log.info("Stopped");
98 + }
99 +
100 + @Modified
101 + public void modified(ComponentContext context) {
102 + readComponentConfiguration(context);
103 +
104 + configReporter(influxDbMetricsReporter);
105 + influxDbMetricsReporter.restartReport();
106 + }
107 +
108 + private void configReporter(InfluxDbMetricsReporter reporter) {
109 + reporter.config(address, port, database, username, password);
110 + }
111 +
112 + /**
113 + * Extracts properties from the component configuration context.
114 + *
115 + * @param context the component context
116 + */
117 + private void readComponentConfiguration(ComponentContext context) {
118 + Dictionary<?, ?> properties = context.getProperties();
119 +
120 + String addressStr = Tools.get(properties, "address");
121 + address = addressStr != null ? addressStr : DEFAULT_ADDRESS;
122 + log.info("Configured. InfluxDB server address is {}", address);
123 +
124 + String databaseStr = Tools.get(properties, "database");
125 + database = databaseStr != null ? databaseStr : DEFAULT_DATABASE;
126 + log.info("Configured. InfluxDB server database is {}", database);
127 +
128 + String usernameStr = Tools.get(properties, "username");
129 + username = usernameStr != null ? usernameStr : DEFAULT_USERNAME;
130 + log.info("Configured. InfluxDB server username is {}", username);
131 +
132 + String passwordStr = Tools.get(properties, "password");
133 + password = passwordStr != null ? passwordStr : DEFAULT_PASSWORD;
134 + log.info("Configured. InfluxDB server password is {}", password);
135 +
136 + Integer portConfigured = Tools.getIntegerProperty(properties, "port");
137 + if (portConfigured == null) {
138 + port = DEFAULT_PORT;
139 + log.info("InfluxDB port is not configured, default value is {}", port);
140 + } else {
141 + port = portConfigured;
142 + log.info("Configured. InfluxDB port is configured to {}", port);
143 + }
144 + }
145 +}
...@@ -15,251 +15,34 @@ ...@@ -15,251 +15,34 @@
15 */ 15 */
16 package org.onosproject.influxdbmetrics; 16 package org.onosproject.influxdbmetrics;
17 17
18 -import com.codahale.metrics.MetricRegistry;
19 -import com.izettle.metrics.influxdb.InfluxDbHttpSender;
20 -import com.izettle.metrics.influxdb.InfluxDbReporter;
21 -import org.apache.commons.lang.StringUtils;
22 -import org.apache.felix.scr.annotations.Activate;
23 -import org.apache.felix.scr.annotations.Component;
24 -import org.apache.felix.scr.annotations.Deactivate;
25 -import org.apache.felix.scr.annotations.Modified;
26 -import org.apache.felix.scr.annotations.Property;
27 -import org.apache.felix.scr.annotations.Reference;
28 -import org.apache.felix.scr.annotations.ReferenceCardinality;
29 -import org.onlab.metrics.MetricsService;
30 -import org.onlab.util.Tools;
31 -import org.onosproject.cfg.ComponentConfigService;
32 -import org.onosproject.cluster.ClusterService;
33 -import org.onosproject.cluster.ControllerNode;
34 -import org.onosproject.core.ApplicationId;
35 -import org.onosproject.core.CoreService;
36 -import org.osgi.service.component.ComponentContext;
37 -import org.slf4j.Logger;
38 -
39 -import java.util.Dictionary;
40 -import java.util.concurrent.TimeUnit;
41 -
42 -import static org.slf4j.LoggerFactory.getLogger;
43 -
44 /** 18 /**
45 - * A Metric reporter that reports all metrics value to influxDB server. 19 + * A Metric reporter interface for reporting all metrics to influxDB server.
46 */ 20 */
47 -@Component(immediate = true) 21 +public interface InfluxDbMetricsReporter {
48 -public class InfluxDbMetricsReporter {
49 - private final Logger log = getLogger(getClass());
50 -
51 - private static final int REPORT_PERIOD = 1;
52 - private static final TimeUnit REPORT_TIME_UNIT = TimeUnit.MINUTES;
53 -
54 - private static final String DEFAULT_PROTOCOL = "http";
55 - private static final String DEFAULT_ADDRESS = "localhost";
56 - private static final int DEFAULT_PORT = 8086;
57 - private static final String DEFAULT_METRIC_NAMES = "default";
58 - private static final String DEFAULT_DATABASE = "onos";
59 - private static final String DEFAULT_USERNAME = "onos";
60 - private static final String DEFAULT_PASSWORD = "onos.password";
61 - private static final String SEPARATOR = ":";
62 - private static final int DEFAULT_CONN_TIMEOUT = 1000;
63 - private static final int DEFAULT_READ_TIMEOUT = 1000;
64 -
65 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 - protected CoreService coreService;
67 -
68 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
69 - protected MetricsService metricsService;
70 -
71 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
72 - protected ComponentConfigService cfgService;
73 -
74 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 - protected ClusterService clusterService;
76 -
77 - @Property(name = "monitorAll", boolValue = true,
78 - label = "Enable to monitor all of metrics stored in metric registry " +
79 - "default is true")
80 - protected boolean monitorAll = true;
81 -
82 - @Property(name = "metricNames", value = DEFAULT_METRIC_NAMES,
83 - label = "Names of metric to be monitored in third party monitoring " +
84 - "server; default metric names are 'default'")
85 - protected String metricNames = DEFAULT_METRIC_NAMES;
86 -
87 - @Property(name = "address", value = DEFAULT_ADDRESS,
88 - label = "IP address of influxDB server; " +
89 - "default is localhost")
90 - protected String address = DEFAULT_ADDRESS;
91 -
92 - @Property(name = "port", intValue = DEFAULT_PORT,
93 - label = "Port number of influxDB server; " +
94 - "default is 8086")
95 - protected int port = DEFAULT_PORT;
96 -
97 - @Property(name = "database", value = DEFAULT_DATABASE,
98 - label = "Database name of influxDB server; " +
99 - "default is onos")
100 - protected String database = DEFAULT_DATABASE;
101 -
102 - @Property(name = "username", value = DEFAULT_USERNAME,
103 - label = "Username of influxDB server; default is onos")
104 - protected String username = DEFAULT_USERNAME;
105 -
106 - @Property(name = "password", value = DEFAULT_PASSWORD,
107 - label = "Password of influxDB server; default is onos.password")
108 - protected String password = DEFAULT_PASSWORD;
109 -
110 - private ApplicationId appId;
111 - private InfluxDbReporter influxDbReporter;
112 - private InfluxDbHttpSender influxDbHttpSender;
113 -
114 - @Activate
115 - public void activate() {
116 - cfgService.registerProperties(getClass());
117 - appId = coreService.registerApplication("org.onosproject.influxdbmetrics");
118 -
119 - startReport();
120 - log.info("Started");
121 - }
122 -
123 - @Deactivate
124 - public void deactivate() {
125 - cfgService.unregisterProperties(getClass(), false);
126 -
127 - stopReport();
128 - log.info("Stopped");
129 - }
130 -
131 - @Modified
132 - public void modified(ComponentContext context) {
133 - readComponentConfiguration(context);
134 - restartReport();
135 - }
136 -
137 - protected void startReport() {
138 - try {
139 - influxDbHttpSender = new InfluxDbHttpSender(DEFAULT_PROTOCOL, address,
140 - port, database, username + SEPARATOR + password, REPORT_TIME_UNIT,
141 - DEFAULT_CONN_TIMEOUT, DEFAULT_READ_TIMEOUT);
142 - MetricRegistry mr = metricsService.getMetricRegistry();
143 - influxDbReporter = InfluxDbReporter.forRegistry(addHostPrefix(filter(mr)))
144 - .convertRatesTo(TimeUnit.SECONDS)
145 - .convertDurationsTo(TimeUnit.MILLISECONDS)
146 - .build(influxDbHttpSender);
147 - influxDbReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT);
148 - log.info("Start to report metrics to influxDB.");
149 - } catch (Exception e) {
150 - log.error("Fail to connect to given influxDB server!");
151 - }
152 - }
153 -
154 - protected void stopReport() {
155 - influxDbReporter.stop();
156 - influxDbHttpSender = null;
157 - influxDbReporter = null;
158 - log.info("Stop reporting metrics to influxDB.");
159 - }
160 -
161 - protected void restartReport() {
162 - stopReport();
163 - startReport();
164 - }
165 22
166 /** 23 /**
167 - * Filters the metrics to only include a set of the given metrics. 24 + * Starts to report metrics to InfluxDB server.
168 - *
169 - * @param metricRegistry original metric registry
170 - * @return filtered metric registry
171 */ 25 */
172 - protected MetricRegistry filter(MetricRegistry metricRegistry) { 26 + void startReport();
173 - if (!monitorAll) {
174 - final MetricRegistry filtered = new MetricRegistry();
175 - metricRegistry.getNames().stream().filter(name ->
176 - containsName(name, metricNames)).forEach(name ->
177 - filtered.register(name, metricRegistry.getMetrics().get(name)));
178 - return filtered;
179 - } else {
180 - return metricRegistry;
181 - }
182 - }
183 27
184 /** 28 /**
185 - * Appends node IP prefix to all performance metrics. 29 + * Stops reporting metrics.
186 - *
187 - * @param metricRegistry original metric registry
188 - * @return prefix added metric registry
189 */ 30 */
190 - protected MetricRegistry addHostPrefix(MetricRegistry metricRegistry) { 31 + void stopReport();
191 - MetricRegistry moddedRegistry = new MetricRegistry();
192 - ControllerNode node = clusterService.getLocalNode();
193 - String prefix = node.id().id() + ".";
194 - metricRegistry.getNames().stream().forEach(name ->
195 - moddedRegistry.register(prefix + name, metricRegistry.getMetrics().get(name)));
196 -
197 - return moddedRegistry;
198 - }
199 32
200 /** 33 /**
201 - * Looks up whether the metric name contains the given prefix keywords. 34 + * Restarts metrics reporter.
202 - * Note that the keywords are separated with comma as delimiter.
203 - *
204 - * @param full the original metric name that to be compared with
205 - * @param prefixes the prefix keywords that are matched against with the metric name
206 - * @return boolean value that denotes whether the metric name starts with the given prefix
207 */ 35 */
208 - protected boolean containsName(String full, String prefixes) { 36 + void restartReport();
209 - String[] prefixArray = StringUtils.split(prefixes, ",");
210 - for (String prefix : prefixArray) {
211 - if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) {
212 - return true;
213 - }
214 - }
215 - return false;
216 - }
217 37
218 /** 38 /**
219 - * Extracts properties from the component configuration context. 39 + * Configures default parameters for influx database metrics reporter.
220 * 40 *
221 - * @param context the component context 41 + * @param address IP address of influxDB server
42 + * @param port Port number of influxDB server
43 + * @param database Database name of influxDB server
44 + * @param username Username of influxDB server
45 + * @param password Password of influxDB server
222 */ 46 */
223 - private void readComponentConfiguration(ComponentContext context) { 47 + void config(String address, int port, String database, String username, String password);
224 - Dictionary<?, ?> properties = context.getProperties();
225 -
226 - String addressStr = Tools.get(properties, "address");
227 - address = addressStr != null ? addressStr : DEFAULT_ADDRESS;
228 - log.info("Configured. InfluxDB server address is {}", address);
229 -
230 - String metricNameStr = Tools.get(properties, "metricNames");
231 - metricNames = metricNameStr != null ? metricNameStr : DEFAULT_METRIC_NAMES;
232 - log.info("Configured. Metric name is {}", metricNames);
233 -
234 - String databaseStr = Tools.get(properties, "database");
235 - database = databaseStr != null ? databaseStr : DEFAULT_DATABASE;
236 - log.info("Configured. InfluxDB server database is {}", database);
237 -
238 - String usernameStr = Tools.get(properties, "username");
239 - username = usernameStr != null ? usernameStr : DEFAULT_USERNAME;
240 - log.info("Configured. InfluxDB server username is {}", username);
241 -
242 - String passwordStr = Tools.get(properties, "password");
243 - password = passwordStr != null ? passwordStr : DEFAULT_PASSWORD;
244 - log.info("Configured. InfluxDB server password is {}", password);
245 -
246 - Integer portConfigured = Tools.getIntegerProperty(properties, "port");
247 - if (portConfigured == null) {
248 - port = DEFAULT_PORT;
249 - log.info("InfluxDB port is not configured, default value is {}", port);
250 - } else {
251 - port = portConfigured;
252 - log.info("Configured. InfluxDB port is configured to {}", port);
253 - }
254 -
255 - Boolean monitorAllEnabled = Tools.isPropertyEnabled(properties, "monitorAll");
256 - if (monitorAllEnabled == null) {
257 - log.info("Monitor all metrics is not configured, " +
258 - "using current value of {}", monitorAll);
259 - } else {
260 - monitorAll = monitorAllEnabled;
261 - log.info("Configured. Monitor all metrics is {}",
262 - monitorAll ? "enabled" : "disabled");
263 - }
264 - }
265 } 48 }
......
...@@ -38,14 +38,14 @@ import java.util.Map; ...@@ -38,14 +38,14 @@ import java.util.Map;
38 */ 38 */
39 public class InfluxDbMetricsReporterTest { 39 public class InfluxDbMetricsReporterTest {
40 40
41 - private InfluxDbMetricsReporter influxReporter; 41 + private DefaultInfluxDbMetricsReporter influxReporter;
42 42
43 /** 43 /**
44 * Sets up the services required by influxDB metrics reporter. 44 * Sets up the services required by influxDB metrics reporter.
45 */ 45 */
46 @Before 46 @Before
47 public void setUp() { 47 public void setUp() {
48 - influxReporter = new InfluxDbMetricsReporter(); 48 + influxReporter = new DefaultInfluxDbMetricsReporter();
49 influxReporter.coreService = new CoreServiceAdapter(); 49 influxReporter.coreService = new CoreServiceAdapter();
50 influxReporter.cfgService = new ComponentConfigAdapter(); 50 influxReporter.cfgService = new ComponentConfigAdapter();
51 influxReporter.clusterService = new ClusterServiceAdapter(); 51 influxReporter.clusterService = new ClusterServiceAdapter();
......