|
1 | | -Python Client for Stackdriver Monitoring |
2 | | -======================================== |
| 1 | +Python Client for Stackdriver Monitoring API (`Alpha`_) |
| 2 | +======================================================= |
3 | 3 |
|
4 | | - Python idiomatic client for `Stackdriver Monitoring`_ |
| 4 | +`Stackdriver Monitoring API`_: Manages your Stackdriver Monitoring data and configurations. Most projects |
| 5 | +must be associated with a Stackdriver account, with a few exceptions as |
| 6 | +noted on the individual method pages. |
5 | 7 |
|
6 | | -.. _Stackdriver Monitoring: https://cloud.google.com/monitoring/ |
| 8 | +- `Client Library Documentation`_ |
| 9 | +- `Product Documentation`_ |
7 | 10 |
|
8 | | -|pypi| |versions| |
9 | | - |
10 | | -- `Documentation`_ |
11 | | - |
12 | | -.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/monitoring/usage.html |
| 11 | +.. _Alpha: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst |
| 12 | +.. _Stackdriver Monitoring API: https://cloud.google.com/monitoring |
| 13 | +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/monitoring/usage.html |
| 14 | +.. _Product Documentation: https://cloud.google.com/monitoring |
13 | 15 |
|
14 | 16 | Quick Start |
15 | 17 | ----------- |
16 | 18 |
|
17 | | -.. code-block:: console |
| 19 | +In order to use this library, you first need to go through the following steps: |
| 20 | + |
| 21 | +1. `Select or create a Cloud Platform project.`_ |
| 22 | +2. `Enable billing for your project.`_ |
| 23 | +3. `Enable the Stackdriver Monitoring API.`_ |
| 24 | +4. `Setup Authentication.`_ |
| 25 | + |
| 26 | +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project |
| 27 | +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project |
| 28 | +.. _Enable the Stackdriver Monitoring API.: https://cloud.google.com/monitoring |
| 29 | +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html |
| 30 | + |
| 31 | +Installation |
| 32 | +~~~~~~~~~~~~ |
18 | 33 |
|
19 | | - $ pip install --upgrade google-cloud-monitoring |
| 34 | +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to |
| 35 | +create isolated Python environments. The basic problem it addresses is one of |
| 36 | +dependencies and versions, and indirectly permissions. |
20 | 37 |
|
21 | | -For more information on setting up your Python development environment, |
22 | | -such as installing ``pip`` and ``virtualenv`` on your system, please refer |
23 | | -to `Python Development Environment Setup Guide`_ for Google Cloud Platform. |
| 38 | +With `virtualenv`_, it's possible to install this library without needing system |
| 39 | +install permissions, and without clashing with the installed system |
| 40 | +dependencies. |
24 | 41 |
|
25 | | -.. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup |
| 42 | +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ |
26 | 43 |
|
27 | | -Authentication |
28 | | --------------- |
29 | 44 |
|
30 | | -With ``google-cloud-python`` we try to make authentication as painless as |
31 | | -possible. Check out the `Authentication section`_ in our documentation to |
32 | | -learn more. You may also find the `authentication document`_ shared by all |
33 | | -the ``google-cloud-*`` libraries to be helpful. |
| 45 | +Mac/Linux |
| 46 | +^^^^^^^^^ |
34 | 47 |
|
35 | | -.. _Authentication section: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html |
36 | | -.. _authentication document: https://github.com/GoogleCloudPlatform/google-cloud-common/tree/master/authentication |
| 48 | +.. code-block:: console |
| 49 | +
|
| 50 | + pip install virtualenv |
| 51 | + virtualenv <your-env> |
| 52 | + source <your-env>/bin/activate |
| 53 | + <your-env>/bin/pip install google-cloud-monitoring |
| 54 | +
|
| 55 | +
|
| 56 | +Windows |
| 57 | +^^^^^^^ |
| 58 | + |
| 59 | +.. code-block:: console |
37 | 60 |
|
38 | | -Using the API |
39 | | -------------- |
| 61 | + pip install virtualenv |
| 62 | + virtualenv <your-env> |
| 63 | + <your-env>\Scripts\activate |
| 64 | + <your-env>\Scripts\pip.exe install google-cloud-monitoring |
40 | 65 |
|
41 | | -`Stackdriver Monitoring`_ (`Monitoring API docs`_) collects metrics, |
42 | | -events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), |
43 | | -hosted uptime probes, application instrumentation, and a variety of common |
44 | | -application components including Cassandra, Nginx, Apache Web Server, |
45 | | -Elasticsearch and many others. Stackdriver ingests that data and generates |
46 | | -insights via dashboards, charts, and alerts. |
| 66 | +Preview |
| 67 | +~~~~~~~ |
47 | 68 |
|
48 | | -This package currently supports all Monitoring API operations other than |
49 | | -writing custom metrics. |
| 69 | +MetricServiceClient |
| 70 | +^^^^^^^^^^^^^^^^^^^ |
50 | 71 |
|
51 | | -.. _Monitoring API docs: https://cloud.google.com/monitoring/api/ref_v3/rest/ |
| 72 | +.. code:: py |
52 | 73 |
|
53 | | -List available metric types: |
| 74 | + from google.cloud import monitoring_v3 |
54 | 75 |
|
55 | | -.. code:: python |
| 76 | + client = monitoring_v3.MetricServiceClient() |
56 | 77 |
|
57 | | - from google.cloud import monitoring |
58 | | - client = monitoring.Client() |
59 | | - for descriptor in client.list_metric_descriptors(): |
60 | | - print(descriptor.type) |
| 78 | + name = client.project_path('[PROJECT]') |
61 | 79 |
|
62 | | -Display CPU utilization across your GCE instances during the last five minutes: |
63 | 80 |
|
64 | | -.. code:: python |
| 81 | + # Iterate over all results |
| 82 | + for element in client.list_monitored_resource_descriptors(name): |
| 83 | + # process element |
| 84 | + pass |
65 | 85 |
|
66 | | - metric = 'compute.googleapis.com/instance/cpu/utilization' |
67 | | - query = client.query(metric, minutes=5) |
68 | | - print(query.as_dataframe()) |
| 86 | + # Or iterate over results one page at a time |
| 87 | + for page in client.list_monitored_resource_descriptors(name, options=CallOptions(page_token=INITIAL_PAGE)): |
| 88 | + for element in page: |
| 89 | + # process element |
| 90 | + pass |
69 | 91 |
|
70 | | -See the ``google-cloud-python`` API `monitoring documentation`_ to learn how |
71 | | -to connect to Stackdriver Monitoring using this Client Library. |
| 92 | +Next Steps |
| 93 | +~~~~~~~~~~ |
72 | 94 |
|
73 | | -.. _monitoring documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/monitoring/usage.html |
| 95 | +- Read the `Client Library Documentation`_ for Stackdriver Monitoring API |
| 96 | + API to see other available methods on the client. |
| 97 | +- Read the `Stackdriver Monitoring API Product documentation`_ to learn |
| 98 | + more about the product and see How-to Guides. |
| 99 | +- View this `repository’s main README`_ to see the full list of Cloud |
| 100 | + APIs that we cover. |
74 | 101 |
|
75 | | -.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-monitoring.svg |
76 | | - :target: https://pypi.org/project/google-cloud-monitoring/ |
77 | | -.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-monitoring.svg |
78 | | - :target: https://pypi.org/project/google-cloud-monitoring/ |
| 102 | +.. _Stackdriver Monitoring API Product documentation: https://cloud.google.com/monitoring |
| 103 | +.. _repository’s main README: https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/README.rst |
0 commit comments