Committed by
Gerrit Code Review
[ONOS-4128] Backup metrics of MetricsService to Graphite monitoring server
- Separate individual app - Initial implementation of metric service reporter - Add unit test Change-Id: I8f89b4dba2f6b7f311f147b776faa7d5160098e0
Showing
6 changed files
with
633 additions
and
0 deletions
apps/graphitemetrics/features.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
18 | + <feature name="${project.artifactId}" version="${project.version}" | ||
19 | + description="${project.description}"> | ||
20 | + <feature>onos-api</feature> | ||
21 | + <bundle>mvn:${project.groupId}/onos-app-graphite/${project.version}</bundle> | ||
22 | + <bundle>mvn:io.dropwizard.metrics/metrics-core/3.1.2</bundle> | ||
23 | + <bundle>mvn:io.dropwizard.metrics/metrics-graphite/3.1.2</bundle> | ||
24 | + </feature> | ||
25 | +</features> |
apps/graphitemetrics/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ you may not use this file except in compliance with the License. | ||
7 | + ~ You may obtain a copy of the License at | ||
8 | + ~ | ||
9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + ~ | ||
11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
20 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + | ||
22 | + <parent> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <artifactId>onos-apps</artifactId> | ||
25 | + <version>1.6.0-SNAPSHOT</version> | ||
26 | + <relativePath>../pom.xml</relativePath> | ||
27 | + </parent> | ||
28 | + | ||
29 | + <artifactId>onos-app-graphite</artifactId> | ||
30 | + <packaging>bundle</packaging> | ||
31 | + | ||
32 | + <description>Performance metric service reporter and retriever for graphite</description> | ||
33 | + | ||
34 | + <properties> | ||
35 | + <onos.app.name>org.onosproject.graphitemetrics</onos.app.name> | ||
36 | + <onos.app.title>Graphite Report and Query App</onos.app.title> | ||
37 | + <onos.app.category>Monitoring</onos.app.category> | ||
38 | + <onos.app.url>http://onosproject.org</onos.app.url> | ||
39 | + <metrics.version>3.1.2</metrics.version> | ||
40 | + </properties> | ||
41 | + | ||
42 | + <dependencies> | ||
43 | + <dependency> | ||
44 | + <groupId>org.osgi</groupId> | ||
45 | + <artifactId>org.osgi.compendium</artifactId> | ||
46 | + </dependency> | ||
47 | + <dependency> | ||
48 | + <groupId>org.onosproject</groupId> | ||
49 | + <artifactId>onlab-misc</artifactId> | ||
50 | + </dependency> | ||
51 | + <dependency> | ||
52 | + <groupId>org.onosproject</groupId> | ||
53 | + <artifactId>onos-cli</artifactId> | ||
54 | + <version>${project.version}</version> | ||
55 | + </dependency> | ||
56 | + <dependency> | ||
57 | + <groupId>org.apache.karaf.shell</groupId> | ||
58 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
59 | + </dependency> | ||
60 | + <dependency> | ||
61 | + <groupId>org.apache.felix</groupId> | ||
62 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
63 | + </dependency> | ||
64 | + <dependency> | ||
65 | + <groupId>io.dropwizard.metrics</groupId> | ||
66 | + <artifactId>metrics-core</artifactId> | ||
67 | + <version>${metrics.version}</version> | ||
68 | + </dependency> | ||
69 | + <dependency> | ||
70 | + <groupId>io.dropwizard.metrics</groupId> | ||
71 | + <artifactId>metrics-graphite</artifactId> | ||
72 | + <version>${metrics.version}</version> | ||
73 | + </dependency> | ||
74 | + <dependency> | ||
75 | + <groupId>org.onosproject</groupId> | ||
76 | + <artifactId>onos-api</artifactId> | ||
77 | + <version>${project.version}</version> | ||
78 | + <classifier>tests</classifier> | ||
79 | + <scope>test</scope> | ||
80 | + </dependency> | ||
81 | + <dependency> | ||
82 | + <groupId>org.onosproject</groupId> | ||
83 | + <artifactId>onlab-junit</artifactId> | ||
84 | + <scope>test</scope> | ||
85 | + </dependency> | ||
86 | + <dependency> | ||
87 | + <groupId>org.easymock</groupId> | ||
88 | + <artifactId>easymock</artifactId> | ||
89 | + <scope>test</scope> | ||
90 | + </dependency> | ||
91 | + <dependency> | ||
92 | + <groupId>org.onosproject</groupId> | ||
93 | + <artifactId>onos-api</artifactId> | ||
94 | + <version>${project.version}</version> | ||
95 | + <classifier>tests</classifier> | ||
96 | + <scope>test</scope> | ||
97 | + </dependency> | ||
98 | + </dependencies> | ||
99 | + | ||
100 | +</project> |
apps/graphitemetrics/src/main/java/org/onosproject/graphitemetrics/GraphiteMetricsReporter.java
0 → 100644
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.graphitemetrics; | ||
17 | + | ||
18 | + | ||
19 | +import com.codahale.metrics.MetricRegistry; | ||
20 | +import com.codahale.metrics.graphite.Graphite; | ||
21 | +import com.codahale.metrics.graphite.GraphiteReporter; | ||
22 | +import org.apache.commons.lang.StringUtils; | ||
23 | +import org.apache.felix.scr.annotations.Activate; | ||
24 | +import org.apache.felix.scr.annotations.Component; | ||
25 | +import org.apache.felix.scr.annotations.Deactivate; | ||
26 | +import org.apache.felix.scr.annotations.Modified; | ||
27 | +import org.apache.felix.scr.annotations.Property; | ||
28 | +import org.apache.felix.scr.annotations.Reference; | ||
29 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
30 | +import org.onlab.util.Tools; | ||
31 | +import org.onosproject.core.ApplicationId; | ||
32 | +import org.onosproject.core.CoreService; | ||
33 | +import org.onlab.metrics.MetricsService; | ||
34 | +import org.onosproject.cfg.ComponentConfigService; | ||
35 | +import org.osgi.service.component.ComponentContext; | ||
36 | +import org.slf4j.Logger; | ||
37 | +import java.net.InetSocketAddress; | ||
38 | +import java.util.Dictionary; | ||
39 | +import java.util.concurrent.TimeUnit; | ||
40 | + | ||
41 | +import static org.slf4j.LoggerFactory.getLogger; | ||
42 | + | ||
43 | +/** | ||
44 | + * A metric report that reports all metrics value to graphite monitoring server. | ||
45 | + */ | ||
46 | +@Component(immediate = true) | ||
47 | +public class GraphiteMetricsReporter { | ||
48 | + | ||
49 | + private final Logger log = getLogger(getClass()); | ||
50 | + | ||
51 | + private static final TimeUnit REPORT_TIME_UNIT = TimeUnit.MINUTES; | ||
52 | + private static final int DEFAULT_REPORT_PERIOD = 1; | ||
53 | + | ||
54 | + private static final String DEFAULT_METRIC_NAMES = "default"; | ||
55 | + private static final String DEFAULT_ADDRESS = "localhost"; | ||
56 | + private static final int DEFAULT_PORT = 2003; | ||
57 | + private static final String DEFAULT_METRIC_NAME_PREFIX = "onos"; | ||
58 | + | ||
59 | + | ||
60 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
61 | + protected CoreService coreService; | ||
62 | + | ||
63 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
64 | + protected MetricsService metricsService; | ||
65 | + | ||
66 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
67 | + protected ComponentConfigService cfgService; | ||
68 | + | ||
69 | + @Property(name = "monitorAll", boolValue = true, | ||
70 | + label = "Enable to monitor all of metrics stored in metric registry default is true") | ||
71 | + protected boolean monitorAll = true; | ||
72 | + | ||
73 | + @Property(name = "metricNames", value = DEFAULT_METRIC_NAMES, | ||
74 | + label = "Names of metric to be monitored; default metric names are 'default'") | ||
75 | + protected String metricNames = DEFAULT_METRIC_NAMES; | ||
76 | + | ||
77 | + @Property(name = "address", value = DEFAULT_ADDRESS, | ||
78 | + label = "IP address of graphite monitoring server; default is localhost") | ||
79 | + protected String address = DEFAULT_ADDRESS; | ||
80 | + | ||
81 | + @Property(name = "port", intValue = DEFAULT_PORT, | ||
82 | + label = "Port number of graphite monitoring server; default is 2003") | ||
83 | + protected int port = DEFAULT_PORT; | ||
84 | + | ||
85 | + @Property(name = "reportPeriod", intValue = DEFAULT_REPORT_PERIOD, | ||
86 | + label = "Reporting period of graphite monitoring server; default is 1") | ||
87 | + protected int reportPeriod = DEFAULT_REPORT_PERIOD; | ||
88 | + | ||
89 | + @Property(name = "metricNamePrefix", value = DEFAULT_METRIC_NAME_PREFIX, | ||
90 | + label = "Prefix of metric name for graphite back-end server; default is 'onos'") | ||
91 | + protected String metricNamePrefix = DEFAULT_METRIC_NAME_PREFIX; | ||
92 | + | ||
93 | + | ||
94 | + private ApplicationId appId; | ||
95 | + private Graphite graphite; | ||
96 | + private GraphiteReporter graphiteReporter; | ||
97 | + | ||
98 | + @Activate | ||
99 | + public void activate() { | ||
100 | + cfgService.registerProperties(getClass()); | ||
101 | + appId = coreService.registerApplication("org.onosproject.metrics.reporter"); | ||
102 | + | ||
103 | + startReport(); | ||
104 | + log.info("Started"); | ||
105 | + } | ||
106 | + | ||
107 | + @Deactivate | ||
108 | + public void deactivate() { | ||
109 | + cfgService.unregisterProperties(getClass(), false); | ||
110 | + | ||
111 | + stopReport(); | ||
112 | + log.info("Stopped"); | ||
113 | + } | ||
114 | + | ||
115 | + @Modified | ||
116 | + public void modified(ComponentContext context) { | ||
117 | + readComponentConfiguration(context); | ||
118 | + | ||
119 | + // Restarts reporting | ||
120 | + stopReport(); | ||
121 | + startReport(); | ||
122 | + } | ||
123 | + | ||
124 | + public void startReport() { | ||
125 | + try { | ||
126 | + graphite = new Graphite(new InetSocketAddress(address, port)); | ||
127 | + | ||
128 | + MetricRegistry metricRegistry = metricsService.getMetricRegistry(); | ||
129 | + | ||
130 | + graphiteReporter = GraphiteReporter.forRegistry(filter(metricRegistry)) | ||
131 | + .prefixedWith(metricNamePrefix) | ||
132 | + .convertRatesTo(TimeUnit.SECONDS) | ||
133 | + .convertDurationsTo(TimeUnit.MILLISECONDS) | ||
134 | + .build(graphite); | ||
135 | + | ||
136 | + graphiteReporter.start(reportPeriod, REPORT_TIME_UNIT); | ||
137 | + log.info("Start to report metrics to graphite."); | ||
138 | + } catch (Exception e) { | ||
139 | + log.error("Fail to connect to given graphite server! : " + e.getMessage()); | ||
140 | + } | ||
141 | + } | ||
142 | + | ||
143 | + public void stopReport() { | ||
144 | + graphiteReporter.stop(); | ||
145 | + graphite = null; | ||
146 | + graphiteReporter = null; | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Filters the metrics to only include a set of the given metrics. | ||
151 | + * | ||
152 | + * @param metricRegistry original metric registry | ||
153 | + * @return filtered metric registry | ||
154 | + */ | ||
155 | + protected MetricRegistry filter(MetricRegistry metricRegistry) { | ||
156 | + if (!monitorAll) { | ||
157 | + final MetricRegistry filtered = new MetricRegistry(); | ||
158 | + metricRegistry.getNames().stream().filter(name -> | ||
159 | + containsName(name, metricNames)).forEach(name -> | ||
160 | + filtered.register(name, metricRegistry.getMetrics().get(name))); | ||
161 | + return filtered; | ||
162 | + } else { | ||
163 | + return metricRegistry; | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Looks up whether the metric name contains the given prefix keywords. | ||
169 | + * Note that the keywords are separated with comma as delimiter | ||
170 | + * | ||
171 | + * @param full the original metric name that to be compared with | ||
172 | + * @param prefixes the prefix keywords that are matched against with the metric name | ||
173 | + * @return boolean value that denotes whether the metric name starts with the given prefix | ||
174 | + */ | ||
175 | + protected boolean containsName(String full, String prefixes) { | ||
176 | + String[] prefixArray = StringUtils.split(prefixes, ","); | ||
177 | + for (String prefix : prefixArray) { | ||
178 | + if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) { | ||
179 | + return true; | ||
180 | + } | ||
181 | + } | ||
182 | + return false; | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Extracts properties from the component configuration context. | ||
187 | + * | ||
188 | + * @param context the component context | ||
189 | + */ | ||
190 | + private void readComponentConfiguration(ComponentContext context) { | ||
191 | + Dictionary<?, ?> properties = context.getProperties(); | ||
192 | + | ||
193 | + Boolean newMonitorAll = Tools.isPropertyEnabled(properties, "monitorAll"); | ||
194 | + if (newMonitorAll == null) { | ||
195 | + log.info("Monitor all metrics is not configured, " + | ||
196 | + "using current value of {}", monitorAll); | ||
197 | + } else { | ||
198 | + monitorAll = newMonitorAll; | ||
199 | + log.info("Configured. Monitor all metrics is {}, ", | ||
200 | + monitorAll ? "enabled" : "disabled"); | ||
201 | + } | ||
202 | + | ||
203 | + String newMetricNames = Tools.get(properties, "metricNames"); | ||
204 | + metricNames = newMetricNames != null ? newMetricNames : DEFAULT_METRIC_NAMES; | ||
205 | + log.info("Configured. Metric name is {}", metricNames); | ||
206 | + | ||
207 | + String newAddress = Tools.get(properties, "address"); | ||
208 | + address = newAddress != null ? newAddress : DEFAULT_ADDRESS; | ||
209 | + log.info("Configured. Graphite monitoring server address is {}", address); | ||
210 | + | ||
211 | + Integer newPort = Tools.getIntegerProperty(properties, "port"); | ||
212 | + if (newPort == null) { | ||
213 | + port = DEFAULT_PORT; | ||
214 | + log.info("Graphite port is not configured, default value is {}", port); | ||
215 | + } else { | ||
216 | + port = newPort; | ||
217 | + log.info("Configured. Graphite port is configured to {}", port); | ||
218 | + } | ||
219 | + | ||
220 | + Integer newReportPeriod = Tools.getIntegerProperty(properties, "reportPeriod"); | ||
221 | + if (newReportPeriod == null) { | ||
222 | + reportPeriod = DEFAULT_REPORT_PERIOD; | ||
223 | + log.info("Report period of graphite server is not configured, " + | ||
224 | + "default value is {}", reportPeriod); | ||
225 | + } else { | ||
226 | + reportPeriod = newReportPeriod; | ||
227 | + log.info("Configured. Report period of graphite server" + | ||
228 | + " is configured to {}", reportPeriod); | ||
229 | + } | ||
230 | + | ||
231 | + String newMetricNamePrefix = Tools.get(properties, "metricNamePrefix"); | ||
232 | + metricNamePrefix = newMetricNamePrefix != null ? | ||
233 | + newMetricNamePrefix : DEFAULT_METRIC_NAME_PREFIX; | ||
234 | + | ||
235 | + } | ||
236 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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 | + | ||
17 | +/** | ||
18 | + * Application that provides capability to report metrics to and from | ||
19 | + * graphite monitoring server. | ||
20 | + */ | ||
21 | +package org.onosproject.graphitemetrics; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/graphitemetrics/src/test/java/org/onosproject/graphitemetrics/GraphiteMetricsReporterTest.java
0 → 100644
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.graphitemetrics; | ||
17 | + | ||
18 | +import com.codahale.metrics.Counter; | ||
19 | +import com.codahale.metrics.Gauge; | ||
20 | +import com.codahale.metrics.Histogram; | ||
21 | +import com.codahale.metrics.Meter; | ||
22 | +import com.codahale.metrics.Metric; | ||
23 | +import com.codahale.metrics.MetricFilter; | ||
24 | +import com.codahale.metrics.MetricRegistry; | ||
25 | +import com.codahale.metrics.Timer; | ||
26 | +import com.google.common.collect.ImmutableSet; | ||
27 | +import org.junit.Before; | ||
28 | +import org.junit.Test; | ||
29 | +import org.onlab.metrics.MetricsComponent; | ||
30 | +import org.onlab.metrics.MetricsFeature; | ||
31 | +import org.onlab.metrics.MetricsService; | ||
32 | +import org.onosproject.cfg.ComponentConfigAdapter; | ||
33 | +import org.onosproject.core.CoreServiceAdapter; | ||
34 | + | ||
35 | +import java.util.Map; | ||
36 | + | ||
37 | +import static org.junit.Assert.assertFalse; | ||
38 | +import static org.junit.Assert.assertTrue; | ||
39 | +import static org.junit.Assert.assertNotNull; | ||
40 | + | ||
41 | +/** | ||
42 | + * Unit test for metrics reporter of graphite. | ||
43 | + */ | ||
44 | +public class GraphiteMetricsReporterTest { | ||
45 | + | ||
46 | + private GraphiteMetricsReporter gmr; | ||
47 | + | ||
48 | + private static final String METRIC_NAME1 = "consistentMap.onos-app-ids.putIfAbsent"; | ||
49 | + private static final String METRIC_NAME2 = "consistentMap.onos-hosts.entrySet"; | ||
50 | + private static final String METRIC_NAME3 = "clusterCommunication.endpoint.*"; | ||
51 | + private static final String METRIC_NAME4 = "atomicCounter.onos-app-id-counter.*"; | ||
52 | + | ||
53 | + private static final String PREFIXES1 = "consistentMap"; | ||
54 | + private static final String PREFIXES2 = "topology"; | ||
55 | + private static final String PREFIXES3 = "consistentMap.onos-app-ids"; | ||
56 | + private static final String PREFIXES4 = "consistentMap, clusterCommunication, atomicCounter"; | ||
57 | + | ||
58 | + /** | ||
59 | + * Sets up graphite metrics reporter instance. | ||
60 | + */ | ||
61 | + @Before | ||
62 | + public void setUp() { | ||
63 | + gmr = new GraphiteMetricsReporter(); | ||
64 | + gmr.coreService = new CoreServiceAdapter(); | ||
65 | + gmr.cfgService = new ComponentConfigAdapter(); | ||
66 | + gmr.metricsService = new TestMetricsService(); | ||
67 | + gmr.activate(); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Tears down graphite metrics reporter instance. | ||
72 | + */ | ||
73 | + public void tearDown() { | ||
74 | + gmr.deactivate(); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Tests whether the containsName method can always return the correct result | ||
79 | + * with the given metric name and a set of prefixes. | ||
80 | + */ | ||
81 | + @Test | ||
82 | + public void testContainsName() { | ||
83 | + assertTrue(gmr.containsName(METRIC_NAME1, PREFIXES1)); | ||
84 | + assertTrue(gmr.containsName(METRIC_NAME1, PREFIXES3)); | ||
85 | + assertTrue(gmr.containsName(METRIC_NAME1, PREFIXES4)); | ||
86 | + assertTrue(gmr.containsName(METRIC_NAME2, PREFIXES4)); | ||
87 | + assertTrue(gmr.containsName(METRIC_NAME3, PREFIXES4)); | ||
88 | + assertTrue(gmr.containsName(METRIC_NAME4, PREFIXES4)); | ||
89 | + assertFalse(gmr.containsName(METRIC_NAME1, PREFIXES2)); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Tests whether the filter method can always return the correct result. | ||
94 | + */ | ||
95 | + @Test | ||
96 | + public void testFilter() { | ||
97 | + MetricRegistry filtered; | ||
98 | + MetricRegistry full = new MetricRegistry(); | ||
99 | + full.meter(METRIC_NAME1); | ||
100 | + full.meter(METRIC_NAME2); | ||
101 | + full.meter(METRIC_NAME3); | ||
102 | + full.meter(METRIC_NAME4); | ||
103 | + | ||
104 | + gmr.monitorAll = true; | ||
105 | + filtered = gmr.filter(full); | ||
106 | + | ||
107 | + assertTrue(filtered.getNames() | ||
108 | + .containsAll(ImmutableSet.of(METRIC_NAME1, METRIC_NAME2, | ||
109 | + METRIC_NAME3, METRIC_NAME4))); | ||
110 | + | ||
111 | + gmr.monitorAll = false; | ||
112 | + gmr.metricNames = PREFIXES1; | ||
113 | + filtered = gmr.filter(full); | ||
114 | + | ||
115 | + assertTrue(filtered.getNames() | ||
116 | + .containsAll(ImmutableSet.of(METRIC_NAME1, METRIC_NAME2))); | ||
117 | + assertFalse(filtered.getNames() | ||
118 | + .containsAll(ImmutableSet.of(METRIC_NAME3, METRIC_NAME4))); | ||
119 | + | ||
120 | + gmr.metricNames = PREFIXES2; | ||
121 | + filtered = gmr.filter(full); | ||
122 | + | ||
123 | + assertFalse(filtered.getNames().containsAll(ImmutableSet.of(METRIC_NAME1))); | ||
124 | + | ||
125 | + gmr.metricNames = PREFIXES3; | ||
126 | + filtered = gmr.filter(full); | ||
127 | + | ||
128 | + assertTrue(filtered.getNames().containsAll(ImmutableSet.of(METRIC_NAME1))); | ||
129 | + assertFalse(filtered.getNames().containsAll(ImmutableSet.of(METRIC_NAME2))); | ||
130 | + | ||
131 | + gmr.metricNames = PREFIXES4; | ||
132 | + filtered = gmr.filter(full); | ||
133 | + | ||
134 | + assertTrue(filtered.getNames() | ||
135 | + .containsAll(ImmutableSet.of(METRIC_NAME1, METRIC_NAME2, | ||
136 | + METRIC_NAME3, METRIC_NAME4))); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Tests whether the methods of MetricsService receives null value parameter. | ||
141 | + */ | ||
142 | + private class TestMetricsService implements MetricsService { | ||
143 | + | ||
144 | + @Override | ||
145 | + public MetricsComponent registerComponent(String name) { | ||
146 | + assertNotNull("Component name is null.", name); | ||
147 | + return null; | ||
148 | + } | ||
149 | + | ||
150 | + @Override | ||
151 | + public MetricRegistry getMetricRegistry() { | ||
152 | + return null; | ||
153 | + } | ||
154 | + | ||
155 | + @Override | ||
156 | + public Counter createCounter(MetricsComponent component, | ||
157 | + MetricsFeature feature, String metricName) { | ||
158 | + assertNotNull("MetricsComponent is null.", component); | ||
159 | + assertNotNull("MetricsFeature is null.", feature); | ||
160 | + assertNotNull("Metric name is null.", metricName); | ||
161 | + return null; | ||
162 | + } | ||
163 | + | ||
164 | + @Override | ||
165 | + public Histogram createHistogram(MetricsComponent component, | ||
166 | + MetricsFeature feature, String metricName) { | ||
167 | + assertNotNull("MetricsComponent is null.", component); | ||
168 | + assertNotNull("MetricsFeature is null.", feature); | ||
169 | + assertNotNull("Metric name is null.", metricName); | ||
170 | + return null; | ||
171 | + } | ||
172 | + | ||
173 | + @Override | ||
174 | + public Timer createTimer(MetricsComponent component, | ||
175 | + MetricsFeature feature, String metricName) { | ||
176 | + assertNotNull("MetricsComponent is null.", component); | ||
177 | + assertNotNull("MetricsFeature is null.", feature); | ||
178 | + assertNotNull("Metric name is null.", metricName); | ||
179 | + return null; | ||
180 | + } | ||
181 | + | ||
182 | + @Override | ||
183 | + public Meter createMeter(MetricsComponent component, | ||
184 | + MetricsFeature feature, String metricName) { | ||
185 | + assertNotNull("MetricsComponent is null.", component); | ||
186 | + assertNotNull("MetricsFeature is null.", feature); | ||
187 | + assertNotNull("Metric name is null.", metricName); | ||
188 | + return null; | ||
189 | + } | ||
190 | + | ||
191 | + @Override | ||
192 | + public <T extends Metric> T registerMetric(MetricsComponent component, | ||
193 | + MetricsFeature feature, String metricName, T metric) { | ||
194 | + assertNotNull("MetricsComponent is null.", component); | ||
195 | + assertNotNull("MetricsFeature is null.", feature); | ||
196 | + assertNotNull("Metric name is null.", metricName); | ||
197 | + assertNotNull("Metric is null.", metric); | ||
198 | + return null; | ||
199 | + } | ||
200 | + | ||
201 | + @Override | ||
202 | + public boolean removeMetric(MetricsComponent component, | ||
203 | + MetricsFeature feature, String metricName) { | ||
204 | + assertNotNull("MetricsComponent is null.", component); | ||
205 | + assertNotNull("MetricsFeature is null.", feature); | ||
206 | + assertNotNull("Metric name is null.", metricName); | ||
207 | + return false; | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public Map<String, Timer> getTimers(MetricFilter filter) { | ||
212 | + assertNotNull("MetricFilter is null.", filter); | ||
213 | + return null; | ||
214 | + } | ||
215 | + | ||
216 | + @Override | ||
217 | + public Map<String, Gauge> getGauges(MetricFilter filter) { | ||
218 | + assertNotNull("MetricFilter is null.", filter); | ||
219 | + return null; | ||
220 | + } | ||
221 | + | ||
222 | + @Override | ||
223 | + public Map<String, Counter> getCounters(MetricFilter filter) { | ||
224 | + assertNotNull("MetricFilter is null.", filter); | ||
225 | + return null; | ||
226 | + } | ||
227 | + | ||
228 | + @Override | ||
229 | + public Map<String, Meter> getMeters(MetricFilter filter) { | ||
230 | + assertNotNull("MetricFilter is null.", filter); | ||
231 | + return null; | ||
232 | + } | ||
233 | + | ||
234 | + @Override | ||
235 | + public Map<String, Histogram> getHistograms(MetricFilter filter) { | ||
236 | + assertNotNull("MetricFilter is null.", filter); | ||
237 | + return null; | ||
238 | + } | ||
239 | + | ||
240 | + @Override | ||
241 | + public Map<String, Metric> getMetrics() { | ||
242 | + return null; | ||
243 | + } | ||
244 | + | ||
245 | + @Override | ||
246 | + public void removeMatching(MetricFilter filter) { | ||
247 | + assertNotNull("MetricFilter is null.", filter); | ||
248 | + } | ||
249 | + } | ||
250 | +} |
... | @@ -70,6 +70,7 @@ | ... | @@ -70,6 +70,7 @@ |
70 | <module>openstackinterface</module> | 70 | <module>openstackinterface</module> |
71 | <module>influxdbmetrics</module> | 71 | <module>influxdbmetrics</module> |
72 | <module>gangliametrics</module> | 72 | <module>gangliametrics</module> |
73 | + <module>graphitemetrics</module> | ||
73 | </modules> | 74 | </modules> |
74 | 75 | ||
75 | <properties> | 76 | <properties> | ... | ... |
-
Please register or login to post a comment