blob: 9d4ce081721a887bfdb0d1a172d60290573bb2f8 [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 /**
33 * Update metric value by specifying metric type.
34 *
Jian Lic5cb4a12016-02-03 23:24:42 -080035 * @param metricType metric type (e.g., load, usage, etc.)
36 * @param value metric value
Jian Li46148902016-01-29 13:33:50 -080037 */
38 void updateMetric(String metricType, double value);
39
40 /**
41 * Update metric value by specifying metric type in a certain time.
42 *
Jian Lic5cb4a12016-02-03 23:24:42 -080043 * @param metricType metric type (e.g., load, usage, etc.)
44 * @param value metric value
45 * @param time update time in seconds
Jian Li46148902016-01-29 13:33:50 -080046 */
47 void updateMetric(String metricType, double value, long time);
48
49 /**
50 * Update metric values of a collection of metric types.
51 *
Jian Lic5cb4a12016-02-03 23:24:42 -080052 * @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
Jian Li46148902016-01-29 13:33:50 -080055 */
56 void updateMetrics(Map<String, Double> metrics, long time);
57
58 /**
59 * Update metric values of a collection of metric types.
60 *
Jian Lic5cb4a12016-02-03 23:24:42 -080061 * @param metrics a collection of metrics which consists of a pair of
62 * metric type and metric value
Jian Li46148902016-01-29 13:33:50 -080063 */
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 *
Jian Lic5cb4a12016-02-03 23:24:42 -080077 * @param metricType metric type
78 * @param duration duration
79 * @param unit time unit
Jian Li46148902016-01-29 13:33:50 -080080 * @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 *
Jian Lic5cb4a12016-02-03 23:24:42 -080087 * @param metricType metric type
Jian Li46148902016-01-29 13:33:50 -080088 * @return metric value
89 */
90 double minMetric(String metricType);
91
92 /**
93 * Returns maximum metric value of a given metric type.
94 *
Jian Lic5cb4a12016-02-03 23:24:42 -080095 * @param metricType metric type
Jian Li46148902016-01-29 13:33:50 -080096 * @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 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800103 * @param metricType metric type
Jian Li46148902016-01-29 13:33:50 -0800104 * @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 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800112 * @param metricType metric type
113 * @param startTime start time
114 * @param endTime end time
Jian Li46148902016-01-29 13:33:50 -0800115 * @return a collection of metric value
116 */
117 double[] metrics(String metricType, long startTime, long endTime);
118
119 /**
Jian Liec343ff2016-02-02 17:11:13 -0800120 * Returns the latest metric update time.
121 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800122 * @param metricType metric type
Jian Liec343ff2016-02-02 17:11:13 -0800123 * @return timestamp
124 */
125 long lastUpdate(String metricType);
126
127 /**
Jian Li46148902016-01-29 13:33:50 -0800128 * A builder of MetricsDatabase.
129 */
130 interface Builder {
131
132 /**
133 * Sets the metric name.
134 *
135 * @param metricName metric name
136 * @return builder object
137 */
138 Builder withMetricName(String metricName);
139
140 /**
141 * Add a new metric to be monitored.
142 *
143 * @param metricType control metric type
144 */
145 Builder addMetricType(String metricType);
146
147 /**
Jian Lic5cb4a12016-02-03 23:24:42 -0800148 * Builds a metric database instance.
Jian Li46148902016-01-29 13:33:50 -0800149 *
Jian Lic5cb4a12016-02-03 23:24:42 -0800150 * @return metric database instance
Jian Li46148902016-01-29 13:33:50 -0800151 */
152 MetricsDatabase build();
153 }
154}