1
- /**
2
- * Copyright (c) 2015 Google Inc.
3
- * <p/>
4
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
- * use this file except in compliance with the License. You may obtain a copy of
6
- * the License at
7
- * <p/>
1
+ /*
2
+ * Copyright 2016 Google Inc. All Rights Reserved .
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
8
* http://www.apache.org/licenses/LICENSE-2.0
9
- * <p/>
9
+ *
10
10
* Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- * License for the specific language governing permissions and limitations under
14
- * the License.
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
15
*/
16
16
17
17
import com .google .api .services .monitoring .v3 .Monitoring ;
28
28
import com .google .api .services .monitoring .v3 .model .TypedValue ;
29
29
import com .google .common .collect .ImmutableMap ;
30
30
import com .google .common .collect .Lists ;
31
-
32
31
import org .joda .time .DateTime ;
33
32
34
33
import java .io .IOException ;
40
39
import java .util .TimeZone ;
41
40
42
41
43
-
44
-
45
42
/**
46
- * Class to demonstrate creating a custom metric with Cloud Monitoring. This class provides a few
47
- * functions that create a custom GAUGE metric, writes a timeseries value to it, then reads that
48
- * metric's value back within the last 5 minutes to see the value written.
43
+ * Class to demonstrate creating a custom metric with Cloud Monitoring.
44
+ * <p/>
45
+ * <p>This class provides a few functions that create a custom GAUGE metric, writes a timeseries
46
+ * value to it, then reads that metric's value back within the last 5 minutes to see the value
47
+ * written.</p>
49
48
*/
50
49
public class CreateCustomMetric {
51
50
@@ -111,7 +110,8 @@ public CreateCustomMetric(Monitoring monitoringService, String projectResource)
111
110
/**
112
111
* Constructs an instance of the class using the default metric name, and takes in a random
113
112
* number generaotr (used for test purposes).
114
- * Package-private to be accessible to tests.
113
+ * <p/>
114
+ * <p>Package-private to be accessible to tests.</p>
115
115
*/
116
116
CreateCustomMetric (Monitoring monitoringService , String projectResource ,
117
117
String metricName , int bound ) {
@@ -162,7 +162,8 @@ private long getRandomPoint() {
162
162
/**
163
163
* This method creates a custom metric with arbitrary names, description,
164
164
* and units.
165
- * Package-private to be accessible to tests.
165
+ * <p/>
166
+ * <p>Package-private to be accessible to tests.</p>
166
167
*/
167
168
MetricDescriptor createCustomMetric () throws IOException {
168
169
MetricDescriptor metricDescriptor = new MetricDescriptor ();
@@ -196,9 +197,11 @@ MetricDescriptor createCustomMetric() throws IOException {
196
197
}
197
198
198
199
/**
199
- * Retrieve the custom metric created by createCustomMetric. It can sometimes take a few moments
200
- * before a new custom metric is ready to have TimeSeries written to it, so this method is used
201
- * to check when it is ready.
200
+ * Retrieve the custom metric created by createCustomMetric.
201
+ * <p/>
202
+ * <p>It can sometimes take a few moments before a new custom metric is ready to have
203
+ * TimeSeries written to it, so this method is used
204
+ * to check when it is ready.</p>
202
205
*/
203
206
public MetricDescriptor getCustomMetric () throws IOException {
204
207
Monitoring .Projects .MetricDescriptors .List metrics =
@@ -218,10 +221,10 @@ public MetricDescriptor getCustomMetric() throws IOException {
218
221
}
219
222
220
223
/**
221
- * Writes a timeseries value for the custom metric created. The value written
222
- * is a random integer value for demonstration purposes. It's a GAUGE metric,
224
+ * Writes a timeseries value for the custom metric created.
225
+ * <p>The value written is a random integer value for demonstration purposes. It's a GAUGE metric,
223
226
* which means its a measure of a value at a point in time, and thus the start
224
- * window and end window times are the same.
227
+ * window and end window times are the same.</p>
225
228
*
226
229
* @throws IOException On network error.
227
230
*/
@@ -264,21 +267,21 @@ void writeCustomMetricTimeseriesValue() throws IOException {
264
267
}
265
268
266
269
/**
267
- * Read the TimeSeries value for the custom metrics created within a window of the
268
- * last 5 minutes.
270
+ * <p> Read the TimeSeries value for the custom metrics created within a window of the
271
+ * last 5 minutes.</p>
269
272
*
270
273
* @return The TimeSeries response object reflecting the Timeseries of the custom metrics
271
- * for the last 5 minutes.
274
+ * for the last 5 minutes.
272
275
* @throws IOException On network error.
273
276
*/
274
277
ListTimeSeriesResponse readTimeseriesValue () throws IOException {
275
278
ListTimeSeriesResponse response =
276
279
monitoringService .projects ().timeSeries ().list (projectResource )
277
- .setFilter ("metric.type=\" " + metricType + "\" " )
278
- .setPageSize (3 )
279
- .setIntervalStartTime (getStartTime ())
280
- .setIntervalEndTime (getNow ())
281
- .execute ();
280
+ .setFilter ("metric.type=\" " + metricType + "\" " )
281
+ .setPageSize (3 )
282
+ .setIntervalStartTime (getStartTime ())
283
+ .setIntervalEndTime (getNow ())
284
+ .execute ();
282
285
return response ;
283
286
}
284
287
@@ -302,8 +305,8 @@ public static void main(final String[] args) throws Exception {
302
305
// Create an authorized API client
303
306
Monitoring monitoringService = ListResources .authenticate ();
304
307
305
- CreateCustomMetric metricWriter = new CreateCustomMetric (
306
- monitoringService , projectResource );
308
+ CreateCustomMetric metricWriter =
309
+ new CreateCustomMetric ( monitoringService , projectResource );
307
310
308
311
MetricDescriptor metricDescriptor = metricWriter .createCustomMetric ();
309
312
0 commit comments