blob: ccdc6b8951c449513c980c925cfbe6ae3dcdb571 [file] [log] [blame]
Jian Li46148902016-01-29 13:33:50 -08001/*
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 */
16package org.onosproject.cpman;
17
18import java.util.Map;
19import java.util.concurrent.TimeUnit;
20
21/**
22 * Database for storing a metric.
23 */
24public interface MetricsDatabase {
25 /**
26 * Returns the metric name of this database.
27 *
28 * @return metric name
29 */
30 String metricName();
31
32 /**
Jian Lidaf55ea2016-04-04 20:38:30 -070033 * Returns the resource name of this database.
34 *
35 * @return resource name
36 */
37 String resourceName();
38
39 /**
Jian Li46148902016-01-29 13:33:50 -080040 * Update metric value by specifying metric type.
41 *
Jian Lic5cb4a12016-02-03 23:24:42 -080042 * @param metricType metric type (e.g., load, usage, etc.)
43 * @param value metric value
Jian Li46148902016-01-29 13:33:50 -080044 */
45 void updateMetric(String metricType, double value);
46
47 /**
48 * Update metric value by specifying metric type in a certain time.
49 *
Jian Lic5cb4a12016-02-03 23:24:42 -080050 * @param metricType metric type (e.g., load, usage, etc.)
51 * @param value metric value
52 * @param time update time in seconds
Jian Li46148902016-01-29 13:33:50 -080053 */
54 void updateMetric(String metricType, double value, long time);
55
56 /**
57 * Update metric values of a collection of metric types.
58 *
Jian Lic5cb4a12016-02-03 23:24:42 -080059 * @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 Li46148902016-01-29 13:33:50 -080062 */
63 void updateMetrics(Map<String, Double> metrics, long time);
64
65 /**
66 * Update metric values of a collection of metric types.
67 *
Jian Lic5cb4a12016-02-03 23:24:42 -080068 * @param metrics a collection of metrics which consists of a pair of
69 * metric type and metric value
Jian Li46148902016-01-29 13:33:50 -080070 */
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 Lic5cb4a12016-02-03 23:24:42 -080084 * @param metricType metric type
85 * @param duration duration
86 * @param unit time unit
Jian Li46148902016-01-29 13:33:50 -080087 * @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 Lic5cb4a12016-02-03 23:24:42 -080094 * @param metricType metric type
Jian Li46148902016-01-29 13:33:50 -080095 * @return metric value
96 */
97 double minMetric(String metricType);
98
99 /**
100 * Returns maximum metric value of a given metric type.
101 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800102 * @param metricType metric type
Jian Li46148902016-01-29 13:33:50 -0800103 * @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 Lic5cb4a12016-02-03 23:24:42 -0800110 * @param metricType metric type
Jian Li46148902016-01-29 13:33:50 -0800111 * @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 Lic5cb4a12016-02-03 23:24:42 -0800119 * @param metricType metric type
120 * @param startTime start time
121 * @param endTime end time
Jian Li46148902016-01-29 13:33:50 -0800122 * @return a collection of metric value
123 */
124 double[] metrics(String metricType, long startTime, long endTime);
125
126 /**
Jian Liec343ff2016-02-02 17:11:13 -0800127 * Returns the latest metric update time.
128 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800129 * @param metricType metric type
Jian Liec343ff2016-02-02 17:11:13 -0800130 * @return timestamp
131 */
132 long lastUpdate(String metricType);
133
134 /**
Jian Li46148902016-01-29 13:33:50 -0800135 * 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 Lidaf55ea2016-04-04 20:38:30 -0700148 * Sets the resource name.
149 *
150 * @param resourceName resource name
151 * @return builder object
152 */
153 Builder withResourceName(String resourceName);
154
155 /**
Jian Li46148902016-01-29 13:33:50 -0800156 * Add a new metric to be monitored.
157 *
158 * @param metricType control metric type
Jian Li72b9b122016-02-11 15:58:51 -0800159 * @return builder object
Jian Li46148902016-01-29 13:33:50 -0800160 */
161 Builder addMetricType(String metricType);
162
163 /**
Jian Lic5cb4a12016-02-03 23:24:42 -0800164 * Builds a metric database instance.
Jian Li46148902016-01-29 13:33:50 -0800165 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800166 * @return metric database instance
Jian Li46148902016-01-29 13:33:50 -0800167 */
168 MetricsDatabase build();
169 }
170}