From 644d49c4fee3308fe7a68539891010583d728bfd Mon Sep 17 00:00:00 2001 From: Bill Prin Date: Tue, 22 Mar 2016 16:15:58 -0700 Subject: [PATCH] Update README.md --- monitoring/README.md | 45 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/monitoring/README.md b/monitoring/README.md index 109b3c2adc..16417fe7b2 100644 --- a/monitoring/README.md +++ b/monitoring/README.md @@ -6,22 +6,47 @@ Monitoring API to retrieve API data. `create_custom_metric.js` demonstrates how to create a custom metric, write a timeseries value to it, and read it back. -## Prerequisites to run locally: -Go to the [Google Developers Console](https://console.developer.google.com). +# Run locally - * Go to API Manager -> Credentials and click New Credential in the Google Developers Console. - [or click here ]{https://console.developers.google.com/project/_/apiui/credential/serviceaccount) - Select a JSON-format key, which will be downloaded to your computer. The key file must be located on the computer(s) from which you will access the Monitoring API. Access to the file should be restricted so that only trusted people can read the key. +Create local credentials by running the following command and following the oauth2 flow: - ``` - export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/-0123456789abcdef.json - ``` + gcloud beta auth application-default login + +Then to run: -# Run locally - npm install node list_resources.js node create_custom_metric.js +## Running on GCE, GAE, or other environments + +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. + + +## Using a Service Account + +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 + + +