Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jian Li | 4614890 | 2016-01-29 13:33:50 -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 | 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 | /** |
Jian Li | daf55ea | 2016-04-04 20:38:30 -0700 | [diff] [blame] | 33 | * Returns the resource name of this database. |
| 34 | * |
| 35 | * @return resource name |
| 36 | */ |
| 37 | String resourceName(); |
| 38 | |
| 39 | /** |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 40 | * Update metric value by specifying metric type. |
| 41 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 42 | * @param metricType metric type (e.g., load, usage, etc.) |
| 43 | * @param value metric value |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 44 | */ |
| 45 | void updateMetric(String metricType, double value); |
| 46 | |
| 47 | /** |
| 48 | * Update metric value by specifying metric type in a certain time. |
| 49 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 50 | * @param metricType metric type (e.g., load, usage, etc.) |
| 51 | * @param value metric value |
| 52 | * @param time update time in seconds |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 53 | */ |
| 54 | void updateMetric(String metricType, double value, long time); |
| 55 | |
| 56 | /** |
| 57 | * Update metric values of a collection of metric types. |
| 58 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 59 | * @param metrics a collection of metrics which consists of a pair of |
| 60 | * metric type and metric value |
| 61 | * @param time update time in seconds |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 62 | */ |
| 63 | void updateMetrics(Map<String, Double> metrics, long time); |
| 64 | |
| 65 | /** |
| 66 | * Update metric values of a collection of metric types. |
| 67 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 68 | * @param metrics a collection of metrics which consists of a pair of |
| 69 | * metric type and metric value |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 70 | */ |
| 71 | void updateMetrics(Map<String, Double> metrics); |
| 72 | |
| 73 | /** |
| 74 | * Returns most recent metric value of a given metric type. |
| 75 | * |
| 76 | * @param metricType metric type |
| 77 | * @return metric value |
| 78 | */ |
| 79 | double recentMetric(String metricType); |
| 80 | |
| 81 | /** |
| 82 | * Return most recent metric values of a given metric type for a given period. |
| 83 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 84 | * @param metricType metric type |
| 85 | * @param duration duration |
| 86 | * @param unit time unit |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 87 | * @return a collection of metric value |
| 88 | */ |
| 89 | double[] recentMetrics(String metricType, int duration, TimeUnit unit); |
| 90 | |
| 91 | /** |
| 92 | * Returns minimum metric value of a given metric type. |
| 93 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 94 | * @param metricType metric type |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 95 | * @return metric value |
| 96 | */ |
| 97 | double minMetric(String metricType); |
| 98 | |
| 99 | /** |
| 100 | * Returns maximum metric value of a given metric type. |
| 101 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 102 | * @param metricType metric type |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 103 | * @return metric value |
| 104 | */ |
| 105 | double maxMetric(String metricType); |
| 106 | |
| 107 | /** |
| 108 | * Returns a collection of metric values of a given metric type for a day. |
| 109 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 110 | * @param metricType metric type |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 111 | * @return a collection of metric value |
| 112 | */ |
| 113 | double[] metrics(String metricType); |
| 114 | |
| 115 | /** |
| 116 | * Returns a collection of metric values of a given metric type for |
| 117 | * a given period. |
| 118 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 119 | * @param metricType metric type |
| 120 | * @param startTime start time |
| 121 | * @param endTime end time |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 122 | * @return a collection of metric value |
| 123 | */ |
| 124 | double[] metrics(String metricType, long startTime, long endTime); |
| 125 | |
| 126 | /** |
Jian Li | ec343ff | 2016-02-02 17:11:13 -0800 | [diff] [blame] | 127 | * Returns the latest metric update time. |
| 128 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 129 | * @param metricType metric type |
Jian Li | ec343ff | 2016-02-02 17:11:13 -0800 | [diff] [blame] | 130 | * @return timestamp |
| 131 | */ |
| 132 | long lastUpdate(String metricType); |
| 133 | |
| 134 | /** |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 135 | * A builder of MetricsDatabase. |
| 136 | */ |
| 137 | interface Builder { |
| 138 | |
| 139 | /** |
| 140 | * Sets the metric name. |
| 141 | * |
| 142 | * @param metricName metric name |
| 143 | * @return builder object |
| 144 | */ |
| 145 | Builder withMetricName(String metricName); |
| 146 | |
| 147 | /** |
Jian Li | daf55ea | 2016-04-04 20:38:30 -0700 | [diff] [blame] | 148 | * Sets the resource name. |
| 149 | * |
| 150 | * @param resourceName resource name |
| 151 | * @return builder object |
| 152 | */ |
| 153 | Builder withResourceName(String resourceName); |
| 154 | |
| 155 | /** |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 156 | * Add a new metric to be monitored. |
| 157 | * |
| 158 | * @param metricType control metric type |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 159 | * @return builder object |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 160 | */ |
| 161 | Builder addMetricType(String metricType); |
| 162 | |
| 163 | /** |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 164 | * Builds a metric database instance. |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 165 | * |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 166 | * @return metric database instance |
Jian Li | 4614890 | 2016-01-29 13:33:50 -0800 | [diff] [blame] | 167 | */ |
| 168 | MetricsDatabase build(); |
| 169 | } |
| 170 | } |