{ "info": { "author": "Bojan Keca", "author_email": "kecabojan@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# cloudwatch-metrics-buffer ![Python 3](https://img.shields.io/badge/Python-3-brightgreen.svg)\n\nThis is a wrapper library for publishing metrics to **[AWS CloudWatch](https://aws.amazon.com/cloudwatch/)**. \n\nWhile playing around with lambdas and serveless frameworks, I needed a library to help me with publishing metrics to CloudWatch in easy and elegant way. I wanted to avoid boilerplate code that polutes all my methods. Ideally, I would decorate my function to measure execution time or count. After unsuccessful search, I implemented my own.\n\nThis wrapper will buffer metrics first, then send them in batches. It supports **timeit** and **count** decorators for metricating functions in elegant way. Though publishing metrics is batched, there is no guaranty ClouWatch will swallow everything. If you send > [150 TPS](https://docs.aws.amazon.com/en_pv/AmazonCloudWatch/latest/APIReference/API_PutMetricData.html) \n(can happen easily if you scale out with Lambdas), you might get throttled. Read CloudWatch documentation for limits and pricing consideration.\n\n## Installation\n```\npip install cloudwatch-metrics-buffer\n```\n\n## Usage\n### Post metrics explicitly\n```python\nfrom cwmetrics import CloudWatchMetricsBuffer\n\ncw = CloudWatchMetricsBuffer('Some Namespace')\n\n# buffer single metrics value to buffer\ncw.put_value('total_calls', 5) # metric without units of value 5\ncw.put_value('latency', 11.25, unit='Milliseconds') # metric with unit specified\ncw.put_value('latency', 11.25, dimensions={'HTTP Method': 'GET'}, unit='Milliseconds') # same latency with specified dimension \ncw.put_value('home-page', 1, timestamp=datetime.datetime(2019, 10, 10, 14, 0, 0)) # metric on exact time\n\n# buffer statistic value; use this if you are gathering your statistics along the way in your app\ncw.put_statistic('metric', sample_count=50, sum=10000, minimum=0, maximum=500)\n\n# send all to Cloudwatch\ncw.send()\n```\n\n### Post metrics using decorators\n```python\nfrom cwmetrics import CloudWatchMetricsBuffer\n\ncw = CloudWatchMetricsBuffer('Some Namespace')\n\n# send value of for metric for each execution\n@cw.count('count_metric1')\ndef func():\n ...\n\nfunc()\n```\n\nYou can also decorate function multiple times. Publishing to CloudWatch is executed after outer decorator finishes:\n```python\n# measure execution time in milliseconds and count request\n@cw.timeit('api')\n@cw.timeit('api', dimensions={'HTTP Method': 'GET'})\n@cw.count('requests', dimensions={'HTTP Method': 'GET'})\ndef process_api_request():\n ...\n\n# CW will receive 3 metric values\nprocess_api_request() \n```\n\nThis will also work:\n```python\n@cw.timeit('api')\n@cw.timeit('api', dimensions={'HTTP Method': 'GET'})\n@cw.count('requests', dimensions={'HTTP Method': 'GET'})\n@cw.count('requests')\ndef process_api_request():\n ...\n authenticate()\n ...\n\n@cw.timeit('auth')\n@cw.count('auth requests')\ndef authenticate():\n ...\n\n# all metrics (total of 6) are buffered and sent after method was executed\nprocess_api_request() \n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kecabojan/cloudwatch-metrics-buffer", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "cloudwatch-metrics-buffer", "package_url": "https://pypi.org/project/cloudwatch-metrics-buffer/", "platform": "", "project_url": "https://pypi.org/project/cloudwatch-metrics-buffer/", "project_urls": { "Homepage": "https://github.com/kecabojan/cloudwatch-metrics-buffer" }, "release_url": "https://pypi.org/project/cloudwatch-metrics-buffer/0.1.0/", "requires_dist": [ "boto3", "botocore" ], "requires_python": "", "summary": "Library for posting metrics to AWS CloudWatch", "version": "0.1.0" }, "last_serial": 5969754, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "dbafa3db6ecac6ebb9ef2fa885643431", "sha256": "df7fda3bca57d27a7c034034c57ccdd3d567a041df6c9e00044eb78cb599f6da" }, "downloads": -1, "filename": "cloudwatch_metrics_buffer-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dbafa3db6ecac6ebb9ef2fa885643431", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5781, "upload_time": "2019-10-14T03:37:05", "url": "https://files.pythonhosted.org/packages/19/4d/8375e33066621bb8493d8222c695951ead63739afd030ba44c72156b0afe/cloudwatch_metrics_buffer-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "15ebfdccc83a87121f305b5b6b3ca9d5", "sha256": "a4d0daa7bc33a48554408a4cf4fb45c331e63b6d7481d6a9ef5dd39a903eb75d" }, "downloads": -1, "filename": "cloudwatch-metrics-buffer-0.1.0.tar.gz", "has_sig": false, "md5_digest": "15ebfdccc83a87121f305b5b6b3ca9d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4682, "upload_time": "2019-10-14T03:37:08", "url": "https://files.pythonhosted.org/packages/84/ac/0a53a29d368180bd03a57c873805b58f1e534a0b1b1c695063cf5298a470/cloudwatch-metrics-buffer-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dbafa3db6ecac6ebb9ef2fa885643431", "sha256": "df7fda3bca57d27a7c034034c57ccdd3d567a041df6c9e00044eb78cb599f6da" }, "downloads": -1, "filename": "cloudwatch_metrics_buffer-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dbafa3db6ecac6ebb9ef2fa885643431", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5781, "upload_time": "2019-10-14T03:37:05", "url": "https://files.pythonhosted.org/packages/19/4d/8375e33066621bb8493d8222c695951ead63739afd030ba44c72156b0afe/cloudwatch_metrics_buffer-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "15ebfdccc83a87121f305b5b6b3ca9d5", "sha256": "a4d0daa7bc33a48554408a4cf4fb45c331e63b6d7481d6a9ef5dd39a903eb75d" }, "downloads": -1, "filename": "cloudwatch-metrics-buffer-0.1.0.tar.gz", "has_sig": false, "md5_digest": "15ebfdccc83a87121f305b5b6b3ca9d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4682, "upload_time": "2019-10-14T03:37:08", "url": "https://files.pythonhosted.org/packages/84/ac/0a53a29d368180bd03a57c873805b58f1e534a0b1b1c695063cf5298a470/cloudwatch-metrics-buffer-0.1.0.tar.gz" } ] }