From 51b1b777b902740afefc6c59b9ea49a696fa1320 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 26 Sep 2016 16:18:53 -0700 Subject: [PATCH 1/2] Moving all monitoring files into subdirectory. Done via: $ mkdir -p monitoring/google/cloud $ cp google/__init__.py monitoring/google/__init__.py $ git add monitoring/google/__init__.py $ cp google/cloud/__init__.py monitoring/google/cloud/__init__.py $ git add monitoring/google/cloud/__init__.py $ git mv google/cloud/monitoring monitoring/google/cloud/monitoring $ git mv unit_tests/monitoring monitoring/unit_tests --- monitoring/google/__init__.py | 20 +++++++++++++++++++ monitoring/google/cloud/__init__.py | 20 +++++++++++++++++++ .../google}/cloud/monitoring/__init__.py | 0 .../google}/cloud/monitoring/_dataframe.py | 0 .../google}/cloud/monitoring/client.py | 0 .../google}/cloud/monitoring/connection.py | 0 .../google}/cloud/monitoring/group.py | 0 .../google}/cloud/monitoring/label.py | 0 .../google}/cloud/monitoring/metric.py | 0 .../google}/cloud/monitoring/query.py | 0 .../google}/cloud/monitoring/resource.py | 0 .../google}/cloud/monitoring/timeseries.py | 0 .../unit_tests}/__init__.py | 0 .../unit_tests}/test__dataframe.py | 0 .../unit_tests}/test_client.py | 0 .../unit_tests}/test_connection.py | 0 .../unit_tests}/test_group.py | 0 .../unit_tests}/test_label.py | 0 .../unit_tests}/test_metric.py | 0 .../unit_tests}/test_query.py | 0 .../unit_tests}/test_resource.py | 0 .../unit_tests}/test_timeseries.py | 0 22 files changed, 40 insertions(+) create mode 100644 monitoring/google/__init__.py create mode 100644 monitoring/google/cloud/__init__.py rename {google => monitoring/google}/cloud/monitoring/__init__.py (100%) rename {google => monitoring/google}/cloud/monitoring/_dataframe.py (100%) rename {google => monitoring/google}/cloud/monitoring/client.py (100%) rename {google => monitoring/google}/cloud/monitoring/connection.py (100%) rename {google => monitoring/google}/cloud/monitoring/group.py (100%) rename {google => monitoring/google}/cloud/monitoring/label.py (100%) rename {google => monitoring/google}/cloud/monitoring/metric.py (100%) rename {google => monitoring/google}/cloud/monitoring/query.py (100%) rename {google => monitoring/google}/cloud/monitoring/resource.py (100%) rename {google => monitoring/google}/cloud/monitoring/timeseries.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/__init__.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test__dataframe.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_client.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_connection.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_group.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_label.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_metric.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_query.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_resource.py (100%) rename {unit_tests/monitoring => monitoring/unit_tests}/test_timeseries.py (100%) diff --git a/monitoring/google/__init__.py b/monitoring/google/__init__.py new file mode 100644 index 000000000000..b2b833373882 --- /dev/null +++ b/monitoring/google/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +try: + import pkg_resources + pkg_resources.declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/monitoring/google/cloud/__init__.py b/monitoring/google/cloud/__init__.py new file mode 100644 index 000000000000..8ac7b74af136 --- /dev/null +++ b/monitoring/google/cloud/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2014 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +try: + import pkg_resources + pkg_resources.declare_namespace(__name__) +except ImportError: + import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/google/cloud/monitoring/__init__.py b/monitoring/google/cloud/monitoring/__init__.py similarity index 100% rename from google/cloud/monitoring/__init__.py rename to monitoring/google/cloud/monitoring/__init__.py diff --git a/google/cloud/monitoring/_dataframe.py b/monitoring/google/cloud/monitoring/_dataframe.py similarity index 100% rename from google/cloud/monitoring/_dataframe.py rename to monitoring/google/cloud/monitoring/_dataframe.py diff --git a/google/cloud/monitoring/client.py b/monitoring/google/cloud/monitoring/client.py similarity index 100% rename from google/cloud/monitoring/client.py rename to monitoring/google/cloud/monitoring/client.py diff --git a/google/cloud/monitoring/connection.py b/monitoring/google/cloud/monitoring/connection.py similarity index 100% rename from google/cloud/monitoring/connection.py rename to monitoring/google/cloud/monitoring/connection.py diff --git a/google/cloud/monitoring/group.py b/monitoring/google/cloud/monitoring/group.py similarity index 100% rename from google/cloud/monitoring/group.py rename to monitoring/google/cloud/monitoring/group.py diff --git a/google/cloud/monitoring/label.py b/monitoring/google/cloud/monitoring/label.py similarity index 100% rename from google/cloud/monitoring/label.py rename to monitoring/google/cloud/monitoring/label.py diff --git a/google/cloud/monitoring/metric.py b/monitoring/google/cloud/monitoring/metric.py similarity index 100% rename from google/cloud/monitoring/metric.py rename to monitoring/google/cloud/monitoring/metric.py diff --git a/google/cloud/monitoring/query.py b/monitoring/google/cloud/monitoring/query.py similarity index 100% rename from google/cloud/monitoring/query.py rename to monitoring/google/cloud/monitoring/query.py diff --git a/google/cloud/monitoring/resource.py b/monitoring/google/cloud/monitoring/resource.py similarity index 100% rename from google/cloud/monitoring/resource.py rename to monitoring/google/cloud/monitoring/resource.py diff --git a/google/cloud/monitoring/timeseries.py b/monitoring/google/cloud/monitoring/timeseries.py similarity index 100% rename from google/cloud/monitoring/timeseries.py rename to monitoring/google/cloud/monitoring/timeseries.py diff --git a/unit_tests/monitoring/__init__.py b/monitoring/unit_tests/__init__.py similarity index 100% rename from unit_tests/monitoring/__init__.py rename to monitoring/unit_tests/__init__.py diff --git a/unit_tests/monitoring/test__dataframe.py b/monitoring/unit_tests/test__dataframe.py similarity index 100% rename from unit_tests/monitoring/test__dataframe.py rename to monitoring/unit_tests/test__dataframe.py diff --git a/unit_tests/monitoring/test_client.py b/monitoring/unit_tests/test_client.py similarity index 100% rename from unit_tests/monitoring/test_client.py rename to monitoring/unit_tests/test_client.py diff --git a/unit_tests/monitoring/test_connection.py b/monitoring/unit_tests/test_connection.py similarity index 100% rename from unit_tests/monitoring/test_connection.py rename to monitoring/unit_tests/test_connection.py diff --git a/unit_tests/monitoring/test_group.py b/monitoring/unit_tests/test_group.py similarity index 100% rename from unit_tests/monitoring/test_group.py rename to monitoring/unit_tests/test_group.py diff --git a/unit_tests/monitoring/test_label.py b/monitoring/unit_tests/test_label.py similarity index 100% rename from unit_tests/monitoring/test_label.py rename to monitoring/unit_tests/test_label.py diff --git a/unit_tests/monitoring/test_metric.py b/monitoring/unit_tests/test_metric.py similarity index 100% rename from unit_tests/monitoring/test_metric.py rename to monitoring/unit_tests/test_metric.py diff --git a/unit_tests/monitoring/test_query.py b/monitoring/unit_tests/test_query.py similarity index 100% rename from unit_tests/monitoring/test_query.py rename to monitoring/unit_tests/test_query.py diff --git a/unit_tests/monitoring/test_resource.py b/monitoring/unit_tests/test_resource.py similarity index 100% rename from unit_tests/monitoring/test_resource.py rename to monitoring/unit_tests/test_resource.py diff --git a/unit_tests/monitoring/test_timeseries.py b/monitoring/unit_tests/test_timeseries.py similarity index 100% rename from unit_tests/monitoring/test_timeseries.py rename to monitoring/unit_tests/test_timeseries.py From 454dde37c5b110cf275d2e418766d14bf4e2fb69 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Mon, 26 Sep 2016 16:18:53 -0700 Subject: [PATCH 2/2] Making monitoring subpackage into a proper package. - Adding README, setup.py, MANIFEST.in, .coveragerc and tox.ini - Adding google-cloud-monitoring as a dependency to the umbrella package - Adding the monitoring subdirectory into the list of packages for verifying the docs - Incorporating the monitoring subdirectory into the umbrella coverage report - Adding the monitoring only tox tests to the Travis config - Adding {toxinidir}/../core as a dependency for the monitoring tox config --- .travis.yml | 3 ++ monitoring/.coveragerc | 11 +++++ monitoring/MANIFEST.in | 4 ++ monitoring/README.rst | 68 ++++++++++++++++++++++++++++++ monitoring/setup.py | 68 ++++++++++++++++++++++++++++++ monitoring/tox.ini | 30 +++++++++++++ scripts/verify_included_modules.py | 1 + setup.py | 1 + tox.ini | 7 +++ 9 files changed, 193 insertions(+) create mode 100644 monitoring/.coveragerc create mode 100644 monitoring/MANIFEST.in create mode 100644 monitoring/README.rst create mode 100644 monitoring/setup.py create mode 100644 monitoring/tox.ini diff --git a/.travis.yml b/.travis.yml index 26f11bed27c9..6d3b8fb43b0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ script: - (cd language && tox -e py27) - (cd error_reporting && tox -e py27) - (cd resource_manager && tox -e py27) + - (cd monitoring && tox -e py27) - tox -e py34 - (cd core && tox -e py34) - (cd bigtable && tox -e py34) @@ -29,6 +30,7 @@ script: - (cd language && tox -e py34) - (cd error_reporting && tox -e py34) - (cd resource_manager && tox -e py34) + - (cd monitoring && tox -e py34) - tox -e lint - tox -e cover - (cd core && tox -e cover) @@ -42,6 +44,7 @@ script: - (cd language && tox -e cover) - (cd error_reporting && tox -e cover) - (cd resource_manager && tox -e cover) + - (cd monitoring && tox -e cover) - tox -e system-tests - tox -e system-tests3 - scripts/update_docs.sh diff --git a/monitoring/.coveragerc b/monitoring/.coveragerc new file mode 100644 index 000000000000..a54b99aa14b7 --- /dev/null +++ b/monitoring/.coveragerc @@ -0,0 +1,11 @@ +[run] +branch = True + +[report] +fail_under = 100 +show_missing = True +exclude_lines = + # Re-enable the standard pragma + pragma: NO COVER + # Ignore debug-only repr + def __repr__ diff --git a/monitoring/MANIFEST.in b/monitoring/MANIFEST.in new file mode 100644 index 000000000000..cb3a2b9ef4fa --- /dev/null +++ b/monitoring/MANIFEST.in @@ -0,0 +1,4 @@ +include README.rst +graft google +graft unit_tests +global-exclude *.pyc diff --git a/monitoring/README.rst b/monitoring/README.rst new file mode 100644 index 000000000000..f969e82fa1b3 --- /dev/null +++ b/monitoring/README.rst @@ -0,0 +1,68 @@ +Python Client for Stackdriver Monitoring +======================================== + + Python idiomatic client for `Stackdriver Monitoring`_ + +.. _Stackdriver Monitoring: https://cloud.google.com/monitoring/ + +- `Homepage`_ +- `API Documentation`_ + +.. _Homepage: https://googlecloudplatform.github.io/google-cloud-python/ +.. _API Documentation: http://googlecloudplatform.github.io/google-cloud-python/ + +Quick Start +----------- + +:: + + $ pip install --upgrade google-cloud-monitoring + +Authentication +-------------- + +With ``google-cloud-python`` we try to make authentication as painless as +possible. Check out the `Authentication section`_ in our documentation to +learn more. You may also find the `authentication document`_ shared by all +the ``google-cloud-*`` libraries to be helpful. + +.. _Authentication section: http://google-cloud-python.readthedocs.io/en/latest/google-cloud-auth.html +.. _authentication document: https://github.com/GoogleCloudPlatform/gcloud-common/tree/master/authentication + +Using the API +------------- + +`Stackdriver Monitoring`_ (`Monitoring API docs`_) 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 and many others. Stackdriver ingests that data and generates +insights via dashboards, charts, and alerts. + +This package currently supports all Monitoring API operations other than +writing custom metrics. + +.. _Stackdriver Monitoring: https://cloud.google.com/monitoring/ +.. _Monitoring API docs: https://cloud.google.com/monitoring/api/ref_v3/rest/ + +List available metric types: + +.. code:: python + + from google.cloud import monitoring + client = monitoring.Client() + for descriptor in client.list_metric_descriptors(): + print(descriptor.type) + +Display CPU utilization across your GCE instances during the last five minutes: + +.. code:: python + + metric = 'compute.googleapis.com/instance/cpu/utilization' + query = client.query(metric, minutes=5) + print(query.as_dataframe()) + +See the ``google-cloud-python`` API `monitoring documentation`_ to learn how +to connect to Stackdriver Monitoring using this Client Library. + +.. _monitoring documentation: https://googlecloudplatform.github.io/google-cloud-python/stable/monitoring-usage.html diff --git a/monitoring/setup.py b/monitoring/setup.py new file mode 100644 index 000000000000..650629f3b313 --- /dev/null +++ b/monitoring/setup.py @@ -0,0 +1,68 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from setuptools import find_packages +from setuptools import setup + + +PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__)) + +with open(os.path.join(PACKAGE_ROOT, 'README.rst')) as file_obj: + README = file_obj.read() + +# NOTE: This is duplicated throughout and we should try to +# consolidate. +SETUP_BASE = { + 'author': 'Google Cloud Platform', + 'author_email': 'jjg+google-cloud-python@google.com', + 'scripts': [], + 'url': 'https://github.com/GoogleCloudPlatform/google-cloud-python', + 'license': 'Apache 2.0', + 'platforms': 'Posix; MacOS X; Windows', + 'include_package_data': True, + 'zip_safe': False, + 'classifiers': [ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: Apache Software License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Topic :: Internet', + ], +} + + +REQUIREMENTS = [ + 'google-cloud-core', +] + +setup( + name='google-cloud-monitoring', + version='0.20.0dev', + description='Python Client for Stackdriver Monitoring', + long_description=README, + namespace_packages=[ + 'google', + 'google.cloud', + ], + packages=find_packages(), + install_requires=REQUIREMENTS, + **SETUP_BASE +) diff --git a/monitoring/tox.ini b/monitoring/tox.ini new file mode 100644 index 000000000000..79bed6ed038b --- /dev/null +++ b/monitoring/tox.ini @@ -0,0 +1,30 @@ +[tox] +envlist = + py27,py34,py35,cover + +[testing] +deps = + {toxinidir}/../core + pytest +covercmd = + py.test --quiet \ + --cov=google.cloud.monitoring \ + --cov=unit_tests \ + --cov-config {toxinidir}/.coveragerc \ + unit_tests + +[testenv] +commands = + py.test --quiet {posargs} unit_tests +deps = + {[testing]deps} + +[testenv:cover] +basepython = + python2.7 +commands = + {[testing]covercmd} +deps = + {[testenv]deps} + coverage + pytest-cov diff --git a/scripts/verify_included_modules.py b/scripts/verify_included_modules.py index bca71e2521dd..de0506979d7c 100644 --- a/scripts/verify_included_modules.py +++ b/scripts/verify_included_modules.py @@ -67,6 +67,7 @@ 'error_reporting', 'language', 'logging', + 'monitoring', 'pubsub', 'resource_manager', 'storage', diff --git a/setup.py b/setup.py index 7d992a5b61d8..1d9683c75295 100644 --- a/setup.py +++ b/setup.py @@ -58,6 +58,7 @@ 'google-cloud-error-reporting', 'google-cloud-language', 'google-cloud-logging', + 'google-cloud-monitoring', 'google-cloud-pubsub', 'google-cloud-resource-manager', 'google-cloud-storage', diff --git a/tox.ini b/tox.ini index 4d83c46460f8..20cde1811837 100644 --- a/tox.ini +++ b/tox.ini @@ -15,6 +15,7 @@ deps = {toxinidir}/language {toxinidir}/error_reporting {toxinidir}/resource_manager + {toxinidir}/monitoring pytest covercmd = py.test --quiet \ @@ -88,6 +89,12 @@ covercmd = --cov-append \ --cov-config {toxinidir}/.coveragerc \ resource_manager/unit_tests + py.test --quiet \ + --cov=google.cloud \ + --cov=unit_tests \ + --cov-append \ + --cov-config {toxinidir}/.coveragerc \ + monitoring/unit_tests coverage report --show-missing --fail-under=100 [testenv]