Yuta HIGUCHI | a22f69f | 2014-11-24 22:25:17 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Yuta HIGUCHI | a22f69f | 2014-11-24 22:25:17 -0800 | [diff] [blame] | 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 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 17 | package org.onosproject.core; |
Yuta HIGUCHI | a22f69f | 2014-11-24 22:25:17 -0800 | [diff] [blame] | 18 | |
| 19 | import org.onlab.metrics.MetricsComponent; |
| 20 | import org.onlab.metrics.MetricsFeature; |
| 21 | import org.onlab.metrics.MetricsService; |
| 22 | |
| 23 | import com.codahale.metrics.Timer; |
| 24 | |
| 25 | /** |
| 26 | * Collection of utility methods used for providing Metrics. |
| 27 | */ |
| 28 | public interface MetricsHelper { |
| 29 | |
| 30 | /** |
| 31 | * Returns MetricService instance. |
| 32 | * |
| 33 | * @return MetricService instance |
| 34 | */ |
Sho SHIMIZU | e2952e4 | 2015-09-11 17:11:21 -0700 | [diff] [blame] | 35 | MetricsService metricsService(); |
Yuta HIGUCHI | a22f69f | 2014-11-24 22:25:17 -0800 | [diff] [blame] | 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 | } |