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 ;
40
40
import java .util .TimeZone ;
41
41
42
42
43
-
44
-
45
43
/**
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.
44
+ * Class to demonstrate creating a custom metric with Cloud Monitoring.
45
+ * <p/>
46
+ * <p>This class provides a few functions that create a custom GAUGE metric, writes a timeseries
47
+ * value to it, then reads that metric's value back within the last 5 minutes to see the value
48
+ * written.
49
49
*/
50
50
public class CreateCustomMetric {
51
51
@@ -111,7 +111,8 @@ public CreateCustomMetric(Monitoring monitoringService, String projectResource)
111
111
/**
112
112
* Constructs an instance of the class using the default metric name, and takes in a random
113
113
* number generaotr (used for test purposes).
114
- * Package-private to be accessible to tests.
114
+ * <p/>
115
+ * <p>Package-private to be accessible to tests.
115
116
*/
116
117
CreateCustomMetric (Monitoring monitoringService , String projectResource ,
117
118
String metricName , int bound ) {
@@ -162,7 +163,8 @@ private long getRandomPoint() {
162
163
/**
163
164
* This method creates a custom metric with arbitrary names, description,
164
165
* and units.
165
- * Package-private to be accessible to tests.
166
+ * <p/>
167
+ * <p>Package-private to be accessible to tests.
166
168
*/
167
169
MetricDescriptor createCustomMetric () throws IOException {
168
170
MetricDescriptor metricDescriptor = new MetricDescriptor ();
@@ -196,8 +198,10 @@ MetricDescriptor createCustomMetric() throws IOException {
196
198
}
197
199
198
200
/**
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
+ * Retrieve the custom metric created by createCustomMetric.
202
+ * <p/>
203
+ * <p>It can sometimes take a few moments before a new custom metric is ready to have
204
+ * TimeSeries written to it, so this method is used
201
205
* to check when it is ready.
202
206
*/
203
207
public MetricDescriptor getCustomMetric () throws IOException {
@@ -218,8 +222,8 @@ public MetricDescriptor getCustomMetric() throws IOException {
218
222
}
219
223
220
224
/**
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,
225
+ * Writes a timeseries value for the custom metric created.
226
+ * <p>The value written is a random integer value for demonstration purposes. It's a GAUGE metric,
223
227
* which means its a measure of a value at a point in time, and thus the start
224
228
* window and end window times are the same.
225
229
*
@@ -264,21 +268,21 @@ void writeCustomMetricTimeseriesValue() throws IOException {
264
268
}
265
269
266
270
/**
267
- * Read the TimeSeries value for the custom metrics created within a window of the
271
+ * <p> Read the TimeSeries value for the custom metrics created within a window of the
268
272
* last 5 minutes.
269
273
*
270
274
* @return The TimeSeries response object reflecting the Timeseries of the custom metrics
271
- * for the last 5 minutes.
275
+ * for the last 5 minutes.
272
276
* @throws IOException On network error.
273
277
*/
274
278
ListTimeSeriesResponse readTimeseriesValue () throws IOException {
275
279
ListTimeSeriesResponse response =
276
280
monitoringService .projects ().timeSeries ().list (projectResource )
277
- .setFilter ("metric.type=\" " + metricType + "\" " )
278
- .setPageSize (3 )
279
- .setIntervalStartTime (getStartTime ())
280
- .setIntervalEndTime (getNow ())
281
- .execute ();
281
+ .setFilter ("metric.type=\" " + metricType + "\" " )
282
+ .setPageSize (3 )
283
+ .setIntervalStartTime (getStartTime ())
284
+ .setIntervalEndTime (getNow ())
285
+ .execute ();
282
286
return response ;
283
287
}
284
288
@@ -302,8 +306,8 @@ public static void main(final String[] args) throws Exception {
302
306
// Create an authorized API client
303
307
Monitoring monitoringService = ListResources .authenticate ();
304
308
305
- CreateCustomMetric metricWriter = new CreateCustomMetric (
306
- monitoringService , projectResource );
309
+ CreateCustomMetric metricWriter =
310
+ new CreateCustomMetric ( monitoringService , projectResource );
307
311
308
312
MetricDescriptor metricDescriptor = metricWriter .createCustomMetric ();
309
313
0 commit comments