Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 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.cpman; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.concurrent.TimeUnit; |
| 20 | |
| 21 | /** |
| 22 | * Database for storing a metric. |
| 23 | */ |
| 24 | public interface MetricsDatabase { |
| 25 | /** |
| 26 | * Returns the metric name of this database. |
| 27 | * |
| 28 | * @return metric name |
| 29 | */ |
| 30 | String metricName(); |
| 31 | |
| 32 | /** |
| 33 | * Update metric value by specifying metric type. |
| 34 | * |
| 35 | * @param metricType metric type (e.g., load, usage, etc.) |
| 36 | * @param value metric value |
| 37 | */ |
| 38 | void updateMetric(String metricType, double value); |
| 39 | |
| 40 | /** |
| 41 | * Update metric value by specifying metric type in a certain time. |
| 42 | * |
| 43 | * @param metricType metric type (e.g., load, usage, etc.) |
| 44 | * @param value metric value |
| 45 | * @param time update time in seconds |
| 46 | */ |
| 47 | void updateMetric(String metricType, double value, long time); |
| 48 | |
| 49 | /** |
| 50 | * Update metric values of a collection of metric types. |
| 51 | * |
| 52 | * @param metrics a collection of metrics which consists of a pair of |
| 53 | * metric type and metric value |
| 54 | * @param time update time in seconds |
| 55 | */ |
| 56 | void updateMetrics(Map<String, Double> metrics, long time); |
| 57 | |
| 58 | /** |
| 59 | * Update metric values of a collection of metric types. |
| 60 | * |
| 61 | * @param metrics a collection of metrics which consists of a pair of |
| 62 | * metric type and metric value |
| 63 | */ |
| 64 | void updateMetrics(Map<String, Double> metrics); |
| 65 | |
| 66 | /** |
| 67 | * Returns most recent metric value of a given metric type. |
| 68 | * |
| 69 | * @param metricType metric type |
| 70 | * @return metric value |
| 71 | */ |
| 72 | double recentMetric(String metricType); |
| 73 | |
| 74 | /** |
| 75 | * Return most recent metric values of a given metric type for a given period. |
| 76 | * |
| 77 | * @param metricType metric type |
| 78 | * @param duration duration |
| 79 | * @param unit time unit |
| 80 | * @return a collection of metric value |
| 81 | */ |
| 82 | double[] recentMetrics(String metricType, int duration, TimeUnit unit); |
| 83 | |
| 84 | /** |
| 85 | * Returns minimum metric value of a given metric type. |
| 86 | * |
| 87 | * @param metricType metric type |
| 88 | * @return metric value |
| 89 | */ |
| 90 | double minMetric(String metricType); |
| 91 | |
| 92 | /** |
| 93 | * Returns maximum metric value of a given metric type. |
| 94 | * |
| 95 | * @param metricType metric type |
| 96 | * @return metric value |
| 97 | */ |
| 98 | double maxMetric(String metricType); |
| 99 | |
| 100 | /** |
| 101 | * Returns a collection of metric values of a given metric type for a day. |
| 102 | * |
| 103 | * @param metricType metric type |
| 104 | * @return a collection of metric value |
| 105 | */ |
| 106 | double[] metrics(String metricType); |
| 107 | |
| 108 | /** |
| 109 | * Returns a collection of metric values of a given metric type for |
| 110 | * a given period. |
| 111 | * |
| 112 | * @param metricType metric type |
| 113 | * @param startTime start time |
| 114 | * @param endTime end time |
| 115 | * @return a collection of metric value |
| 116 | */ |
| 117 | double[] metrics(String metricType, long startTime, long endTime); |
| 118 | |
| 119 | /** |
| 120 | * A builder of MetricsDatabase. |
| 121 | */ |
| 122 | interface Builder { |
| 123 | |
| 124 | /** |
| 125 | * Sets the metric name. |
| 126 | * |
| 127 | * @param metricName metric name |
| 128 | * @return builder object |
| 129 | */ |
| 130 | Builder withMetricName(String metricName); |
| 131 | |
| 132 | /** |
| 133 | * Add a new metric to be monitored. |
| 134 | * |
| 135 | * @param metricType control metric type |
| 136 | */ |
| 137 | Builder addMetricType(String metricType); |
| 138 | |
| 139 | /** |
| 140 | * Builds a MetricDatabase instance. |
| 141 | * |
| 142 | * @return MetricDatabase instance |
| 143 | */ |
| 144 | MetricsDatabase build(); |
| 145 | } |
| 146 | } |