| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
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.
* [Maven 3](https://maven.apache.org) * [GCloud CLI](https://cloud.google.com/sdk/gcloud/) * Create a Cloud project
Create local credentials by running the following command and following the oauth2 flow:
gcloud beta auth application-default login
To run:
* `mvn clean install` * `./list_resources_example.sh <YOUR-PROJECT-ID>` * `./run_custom_metrics.sh <YOUR-PROJECT-ID>`
On Google App Engine, the credentials should be found automatically.
On Google Compute Engine, the credentials should be found automatically, but require that you create the instance with the correct scopes.
gcloud compute instances create --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/compute.readonly" test-instance
If you did not create the instance with the right scopes, you can still upload a JSON service account and set GOOGLE_APPLICATION_CREDENTIALS as described below.
In non-Google Cloud environments, GCE instances created without the correct scopes, or local workstations if the gcloud beta auth application-default login command fails, use a Service Account by doing the following:
Go to API Manager -> Credentials
Click 'New Credentials', and create a Service Account or [click here](https://console.cloud.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/-0123456789abcdef.json
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
| Back | FazBrowse Home | New Git URL |