|
| 1 | +# Cloud Monitoring Sample |
| 2 | + |
| 3 | +Simple command-line program to demonstrate connecting to the Google |
| 4 | +Monitoring API to retrieve and modify Alerts data. |
| 5 | + |
| 6 | +## Prerequisites to run locally: |
| 7 | + |
| 8 | + * [Maven 3](https://maven.apache.org) |
| 9 | + * [GCloud CLI](https://cloud.google.com/sdk/gcloud/) |
| 10 | + * Create a Cloud project |
| 11 | + |
| 12 | +# Set Up Your Local Dev Environment |
| 13 | + |
| 14 | +Create local credentials by running the following command and following the oauth2 flow: |
| 15 | + |
| 16 | + gcloud beta auth application-default login |
| 17 | + |
| 18 | +To run: |
| 19 | + |
| 20 | + * `mvn clean install` |
| 21 | + * `./manage_alerts_sample.sh <YOUR-PROJECT-ID> <command> <args> |
| 22 | + |
| 23 | +## Running on GCE, GAE, or other environments |
| 24 | + |
| 25 | +On Google App Engine, the credentials should be found automatically. |
| 26 | + |
| 27 | +On Google Compute Engine, the credentials should be found automatically, but require that |
| 28 | +you create the instance with the correct scopes. |
| 29 | + |
| 30 | + 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 |
| 31 | + |
| 32 | +If you did not create the instance with the right scopes, you can still upload a JSON service |
| 33 | +account and set `GOOGLE_APPLICATION_CREDENTIALS` as described below. |
| 34 | + |
| 35 | +## Using a Service Account |
| 36 | + |
| 37 | +In non-Google Cloud environments, GCE instances created without the correct scopes, or local |
| 38 | +workstations if the `gcloud beta auth application-default login` command fails, use a Service |
| 39 | +Account by doing the following: |
| 40 | + |
| 41 | +* Go to API Manager -> Credentials |
| 42 | +* Click 'New Credentials', and create a Service Account or [click here](https://console.cloud.google |
| 43 | +.com/project/_/apiui/credential/serviceaccount) |
| 44 | + Download the JSON for this service account, and set the `GOOGLE_APPLICATION_CREDENTIALS` |
| 45 | + environment variable to point to the file containing the JSON credentials. |
| 46 | + |
| 47 | + |
| 48 | + export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/<project-id>-0123456789abcdef.json |
0 commit comments