Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Monitoring v3 Samples #116

Merged
merged 1 commit into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion monitoring/pom.xml → monitoring/v2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<artifactId>doc-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
<relativePath>../..</relativePath>
</parent>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/**
* Simple command-line program to demonstrate connecting to and retrieving data
* from the Google Cloud Monitoring API using application default credentials.
* Please see README.md on instructions to run.
*/
public final class CloudMonitoringAuthSample {

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

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

}
}
Expand Down
48 changes: 48 additions & 0 deletions monitoring/v3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Cloud Monitoring Sample

Simple command-line program to demonstrate connecting to the Google
Monitoring API to retrieve API data.

This also includes an example of how to create a cusom metric and
write a TimeSeries value to it.

## Prerequisites to run locally:

* [Maven 3](https://maven.apache.org)


Go to the [Google Developers Console](https://console.developer.google.com).

* Go too API Manager -> Credentials
* Click ['New Credentials', and create a Service Account](https://console.developers.google.com/project/_/apiui/credential/serviceaccount)
Download the JSON for this service account, and set the `GOOGLE_APPLICATION_CREDENTIALS`
environment variable to point to the file containing the JSON credentials.

```
export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/<project-id>-0123456789abcdef.json
```

# Set Up Your Local Dev Environment

To run locally:
* `mvn clean install`
* `./run_monitoring_example.sh <YOUR-PROJECT-ID>
* `./run_custom_metrics.sh <YOUR-PROJECT-ID>

## Run Tests

The tests emulate what the scripts accomplish, so there isn't a reason why they need to be run if the examples work.
However, if you'd like to run them, change TEST_PROJECT_ID in ListResourcesTest to the appropriate project ID
that matches the Service Account pointed to by GOOGLE_APPLICATION_CREDENTIALS, then run:

mvn test -DskipTests=false

## Contributing changes

See CONTRIBUTING.md

## Licensing

* See [LICENSE](LICENSE)


2 changes: 2 additions & 0 deletions monitoring/v3/list_resources_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
mvn exec:java -Dexec.mainClass=ListResources -Dexec.args="$1"
103 changes: 103 additions & 0 deletions monitoring/v3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud.monotoring.samples</groupId>
<artifactId>cloud-monitoring-v3-samples</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<artifactId>doc-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>../..</relativePath>
</parent>


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] extra new line here

<properties>
<project.http.version>1.19.0</project.http.version>
<project.oauth.version>1.19.0</project.oauth.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>

<dependencies>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.20.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>${project.oauth.version}</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>${project.http.version}</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>${project.oauth.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-matchers</artifactId>
<scope>test</scope>
<version>1.3</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- To be replaced by a Maven dependency on public release -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment no longer relevant. (I assume this maven dependency is now public)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by #122.

<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-monitoring</artifactId>
<version>v3-rev1-1.21.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>

</build>
</project>
2 changes: 2 additions & 0 deletions monitoring/v3/run_custom_metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
mvn exec:java -Dexec.mainClass=CreateCustomMetric -Dexec.args="$1"
Loading