blob: 7c9a715f52a0100d01f2f8e30fc590a6e214d322 [file] [log] [blame]
Yuta HIGUCHIa22f69f2014-11-24 22:25:17 -08001/*
2 * Copyright 2014 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
17package org.onlab.onos.core;
18
19import org.onlab.metrics.MetricsComponent;
20import org.onlab.metrics.MetricsFeature;
21import org.onlab.metrics.MetricsService;
22
23import com.codahale.metrics.Timer;
24
25/**
26 * Collection of utility methods used for providing Metrics.
27 */
28public interface MetricsHelper {
29
30 /**
31 * Returns MetricService instance.
32 *
33 * @return MetricService instance
34 */
35 abstract MetricsService metricsService();
36
37
38 /**
39 * Creates a Timer instance with given name.
40 *
41 * @param component component name
42 * @param feature feature name
43 * @param name timer name
44 * @return Timer instance
45 */
46 default Timer createTimer(String component, String feature, String name) {
47 final MetricsService metricsService = metricsService();
48 if (metricsService != null) {
49 MetricsComponent c = metricsService.registerComponent(component);
50 MetricsFeature f = c.registerFeature(feature);
51 return metricsService.createTimer(c, f, name);
52 }
53 return null;
54 }
55
56}