Skip to content

Commit 2e683f4

Browse files
author
Bill Prin
committed
Add Monitoring v3 Samples
Refactor v2 samples in to separate directory By default I skip tests, but they pass. Will send in incoming PR to add -DskipTests=false to the travis file (because since the tests require service account setup I don’t want to run them by default.)
1 parent 853c3e8 commit 2e683f4

12 files changed

+876
-6
lines changed

monitoring/pom.xml renamed to monitoring/v2/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<artifactId>doc-samples</artifactId>
1010
<groupId>com.google.cloud</groupId>
1111
<version>1.0.0</version>
12-
<relativePath>..</relativePath>
12+
<relativePath>../..</relativePath>
1313
</parent>
1414

1515

monitoring/src/main/java/CloudMonitoringAuthSample.java renamed to monitoring/v2/src/main/java/CloudMonitoringAuthSample.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
/**
2929
* Simple command-line program to demonstrate connecting to and retrieving data
3030
* from the Google Cloud Monitoring API using application default credentials.
31+
* Please see README.md on instructions to run.
3132
*/
3233
public final class CloudMonitoringAuthSample {
3334

@@ -97,10 +98,6 @@ public static void main(final String[] args) throws Exception {
9798
System.out.println("Timeseries.list raw response:");
9899
System.out.println(timeseriesListRequest.execute().toPrettyString());
99100

100-
// This example only demonstrates completing the OAuth flow and displaying
101-
// the raw response from a simple request. See the API client library docs
102-
// for applicable methods for working with the returned data, including
103-
// getting results and paging through results.
104101

105102
}
106103
}

monitoring/v3/README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Cloud Monitoring Sample
2+
3+
Simple command-line program to demonstrate connecting to the Google
4+
Monitoring API to retrieve API data.
5+
6+
This also includes an example of how to create a cusom metric and
7+
write a TimeSeries value to it.
8+
9+
## Prerequisites to run locally:
10+
11+
* [Maven 3](https://maven.apache.org)
12+
13+
14+
Go to the [Google Developers Console](https://console.developer.google.com).
15+
16+
* Go too API Manager -> Credentials
17+
* Click ['New Credentials', and create a Service Account](https://console.developers.google.com/project/_/apiui/credential/serviceaccount)
18+
Download the JSON for this service account, and set the `GOOGLE_APPLICATION_CREDENTIALS`
19+
environment variable to point to the file containing the JSON credentials.
20+
21+
```
22+
export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/<project-id>-0123456789abcdef.json
23+
```
24+
25+
# Set Up Your Local Dev Environment
26+
27+
To run locally:
28+
* `mvn clean install`
29+
* `./run_monitoring_example.sh <YOUR-PROJECT-ID>
30+
* `./run_custom_metrics.sh <YOUR-PROJECT-ID>
31+
32+
## Run Tests
33+
34+
The tests emulate what the scripts accomplish, so there isn't a reason why they need to be run if the examples work.
35+
However, if you'd like to run them, change TEST_PROJECT_ID in ListResourcesTest to the appropriate project ID
36+
that matches the Service Account pointed to by GOOGLE_APPLICATION_CREDENTIALS, then run:
37+
38+
mvn test -DskipTests=false
39+
40+
## Contributing changes
41+
42+
See CONTRIBUTING.md
43+
44+
## Licensing
45+
46+
* See [LICENSE](LICENSE)
47+
48+
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
mvn exec:java -Dexec.mainClass=ListResources -Dexec.args="$1"

monitoring/v3/pom.xml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.google.cloud.monotoring.samples</groupId>
6+
<artifactId>cloud-monitoring-v3-samples</artifactId>
7+
<version>0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<artifactId>doc-samples</artifactId>
12+
<groupId>com.google.cloud</groupId>
13+
<version>1.0.0</version>
14+
<relativePath>../..</relativePath>
15+
</parent>
16+
17+
18+
<properties>
19+
<project.http.version>1.19.0</project.http.version>
20+
<project.oauth.version>1.19.0</project.oauth.version>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<skipTests>true</skipTests>
23+
</properties>
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>com.google.api-client</groupId>
28+
<artifactId>google-api-client</artifactId>
29+
<version>1.20.0</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>com.google.oauth-client</groupId>
33+
<artifactId>google-oauth-client</artifactId>
34+
<version>${project.oauth.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.google.http-client</groupId>
38+
<artifactId>google-http-client-jackson2</artifactId>
39+
<version>${project.http.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.google.oauth-client</groupId>
43+
<artifactId>google-oauth-client-jetty</artifactId>
44+
<version>${project.oauth.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>com.google.code.gson</groupId>
48+
<artifactId>gson</artifactId>
49+
<version>2.3.1</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>junit</groupId>
53+
<artifactId>junit</artifactId>
54+
<scope>test</scope>
55+
<version>4.12</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.jcabi</groupId>
59+
<artifactId>jcabi-matchers</artifactId>
60+
<scope>test</scope>
61+
<version>1.3</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>joda-time</groupId>
65+
<artifactId>joda-time</artifactId>
66+
<version>2.9</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.commons</groupId>
70+
<artifactId>commons-lang3</artifactId>
71+
<version>3.4</version>
72+
</dependency>
73+
<!-- To be replaced by a Maven dependency on public release -->
74+
<dependency>
75+
<groupId>com.google.apis</groupId>
76+
<artifactId>google-api-services-monitoring</artifactId>
77+
<version>v3-rev1-1.21.0</version>
78+
</dependency>
79+
</dependencies>
80+
<build>
81+
<pluginManagement>
82+
<plugins>
83+
<plugin>
84+
<artifactId>maven-compiler-plugin</artifactId>
85+
<version>2.3.2</version>
86+
<configuration>
87+
<source>1.7</source>
88+
<target>1.7</target>
89+
</configuration>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-surefire-plugin</artifactId>
94+
<version>2.4.2</version>
95+
<configuration>
96+
<skipTests>${skipTests}</skipTests>
97+
</configuration>
98+
</plugin>
99+
</plugins>
100+
</pluginManagement>
101+
102+
</build>
103+
</project>

monitoring/v3/run_custom_metrics.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bash
2+
mvn exec:java -Dexec.mainClass=CreateCustomMetric -Dexec.args="$1"

0 commit comments

Comments
 (0)