|
| 1 | +.. This file is automatically generated. Do not edit this file directly. |
| 2 | +
|
| 3 | +Google Stackdriver Monitoring API Python Samples |
| 4 | +=============================================================================== |
| 5 | + |
| 6 | +This directory contains samples for Google Stackdriver Monitoring API. Stackdriver Monitoring collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch |
| 7 | + and many others. Stackdriver ingests that data and generates insights |
| 8 | + via dashboards, charts, and alerts. |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +.. _Google Stackdriver Monitoring API: https://cloud.google.com/monitoring/docs/ |
| 14 | + |
| 15 | +Setup |
| 16 | +------------------------------------------------------------------------------- |
| 17 | + |
| 18 | + |
| 19 | +Authentication |
| 20 | +++++++++++++++ |
| 21 | + |
| 22 | +Authentication is typically done through `Application Default Credentials`_, |
| 23 | +which means you do not have to change the code to authenticate as long as |
| 24 | +your environment has credentials. You have a few options for setting up |
| 25 | +authentication: |
| 26 | + |
| 27 | +#. When running locally, use the `Google Cloud SDK`_ |
| 28 | + |
| 29 | + .. code-block:: bash |
| 30 | +
|
| 31 | + gcloud beta auth application-default login |
| 32 | +
|
| 33 | +
|
| 34 | +#. When running on App Engine or Compute Engine, credentials are already |
| 35 | + set-up. However, you may need to configure your Compute Engine instance |
| 36 | + with `additional scopes`_. |
| 37 | + |
| 38 | +#. You can create a `Service Account key file`_. This file can be used to |
| 39 | + authenticate to Google Cloud Platform services from any environment. To use |
| 40 | + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to |
| 41 | + the path to the key file, for example: |
| 42 | + |
| 43 | + .. code-block:: bash |
| 44 | +
|
| 45 | + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json |
| 46 | +
|
| 47 | +.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow |
| 48 | +.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using |
| 49 | +.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount |
| 50 | + |
| 51 | +Install Dependencies |
| 52 | +++++++++++++++++++++ |
| 53 | + |
| 54 | +#. Install `pip`_ and `virtualenv`_ if you do not already have them. |
| 55 | + |
| 56 | +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. |
| 57 | + |
| 58 | + .. code-block:: bash |
| 59 | +
|
| 60 | + $ virtualenv env |
| 61 | + $ source env/bin/activate |
| 62 | +
|
| 63 | +#. Install the dependencies needed to run the samples. |
| 64 | + |
| 65 | + .. code-block:: bash |
| 66 | +
|
| 67 | + $ pip install -r requirements.txt |
| 68 | +
|
| 69 | +.. _pip: https://pip.pypa.io/ |
| 70 | +.. _virtualenv: https://virtualenv.pypa.io/ |
| 71 | + |
| 72 | +Samples |
| 73 | +------------------------------------------------------------------------------- |
| 74 | + |
| 75 | +Quickstart |
| 76 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +To run this sample: |
| 81 | + |
| 82 | +.. code-block:: bash |
| 83 | +
|
| 84 | + $ python quickstart.py |
| 85 | +
|
| 86 | +
|
| 87 | +Snippets |
| 88 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +To run this sample: |
| 93 | + |
| 94 | +.. code-block:: bash |
| 95 | +
|
| 96 | + $ python snippets.py |
| 97 | +
|
| 98 | + usage: snippets.py [-h] [--project_id PROJECT_ID] |
| 99 | + {create-metric-descriptor,list-metric-descriptors,delete-metric-descriptor,list-resources,get-resource,write-time-series,list-time-series,list-time-series-header,list-time-series-reduce,list-time-series-aggregate} |
| 100 | + ... |
| 101 | + |
| 102 | + Demonstrates Monitoring API operations. |
| 103 | + |
| 104 | + positional arguments: |
| 105 | + {create-metric-descriptor,list-metric-descriptors,delete-metric-descriptor,list-resources,get-resource,write-time-series,list-time-series,list-time-series-header,list-time-series-reduce,list-time-series-aggregate} |
| 106 | + create-metric-descriptor |
| 107 | + list-metric-descriptors |
| 108 | + delete-metric-descriptor |
| 109 | + list-resources |
| 110 | + get-resource |
| 111 | + write-time-series |
| 112 | + list-time-series |
| 113 | + list-time-series-header |
| 114 | + list-time-series-reduce |
| 115 | + list-time-series-aggregate |
| 116 | + |
| 117 | + optional arguments: |
| 118 | + -h, --help show this help message and exit |
| 119 | + --project_id PROJECT_ID |
| 120 | + Your cloud project ID. |
| 121 | +
|
| 122 | +
|
| 123 | +
|
| 124 | +
|
| 125 | +The client library |
| 126 | +------------------------------------------------------------------------------- |
| 127 | + |
| 128 | +This sample uses the `Google Cloud Client Library for Python`_. |
| 129 | +You can read the documentation for more details on API usage and use GitHub |
| 130 | +to `browse the source`_ and `report issues`_. |
| 131 | + |
| 132 | +.. Google Cloud Client Library for Python: |
| 133 | + https://googlecloudplatform.github.io/google-cloud-python/ |
| 134 | +.. browse the source: |
| 135 | + https://github.com/GoogleCloudPlatform/google-cloud-python |
| 136 | +.. report issues: |
| 137 | + https://github.com/GoogleCloudPlatform/google-cloud-python/issues |
| 138 | +
|
| 139 | +
|
| 140 | +.. _Google Cloud SDK: https://cloud.google.com/sdk/ |
0 commit comments