{ "info": { "author": "Rob Blackbourn", "author_email": "rob.blackbourn@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "# jetblack-metrics\n\nGeneric metric classes and context based monitoring.\n\n## Installation\n\nInstall from the pie store.\n\n```bash\npip install jetblack-metrics\n```\n\n## Usage\n\nFirst you need to implement a metric which interacts with an actual\ninstrumentation implementation. The following provides an HTTP request\nmetric using Prometheus to gather the metrics and the `TimedMetric` to\nprovide a latency metric.\n\n```python\nfrom jetblack_metrics import monitor, TimedMetric\nfrom prometheus_client import Counter, Gauge, Histogram\n\nclass HttpRequestMetric(TimedMetric):\n \"\"\"\n A metric which holds HTTP information.\n \"\"\"\n\n def __init__(self, name: str, method: str, path: str) -> None:\n super().__init__()\n self.name = name\n self.scope = method\n self.info = path\n self.status = 500\n\n REQUEST_COUNT = Counter(\n \"http_request_count\",\n \"Number of requests received\",\n [\"name\", \"method\", \"path\", \"status\"]\n )\n REQUEST_LATENCY = Histogram(\n \"http_request_latency\",\n \"Elapsed time per request\",\n [\"name\", \"method\", \"path\"]\n )\n REQUEST_IN_PROGRESS = Gauge(\n \"http_requests_in_progress\",\n \"Requests in progress\",\n [\"name\", \"method\", \"path\"]\n )\n\n def on_enter(self):\n super().on_enter()\n self.REQUEST_IN_PROGRESS.labels(\n self.name,\n self.scope['method'],\n self.scope['path']\n ).inc()\n\n def on_exit(self) -> None:\n super().on_exit()\n self.REQUEST_COUNT.labels(\n self.name,\n self.scope['method'],\n self.scope['path'],\n self.status\n ).inc()\n self.REQUEST_LATENCY.labels(\n self.name,\n self.scope['method'],\n self.scope['path']\n ).observe(self.elapsed)\n self.REQUEST_IN_PROGRESS.labels(\n self.name,\n self.scope['method'],\n self.scope['path']\n ).dec()\n```\n\nOnce we have the metric we can use the `monitor` function to manage the process\nof gathering the statistics.\n\n```python\ndef some_http_middleware(request, next_handler):\n \"\"\"Some kind of HTTP middleware function\"\"\"\n with monitor(HttpRequestMetric('MyApp', request.method, request.path)) as metric:\n # Call the request handler\n response = next_handler(request)\n metric.status = response.status\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/rob-blackbourn/jetblack-metrics", "keywords": "", "license": "Apache-2.0", "maintainer": "Rob Blackbourn", "maintainer_email": "rob.blackbourn@gmail.com", "name": "jetblack-metrics", "package_url": "https://pypi.org/project/jetblack-metrics/", "platform": "", "project_url": "https://pypi.org/project/jetblack-metrics/", "project_urls": { "Homepage": "https://github.com/rob-blackbourn/jetblack-metrics", "Repository": "https://github.com/rob-blackbourn/jetblack-metrics" }, "release_url": "https://pypi.org/project/jetblack-metrics/1.0.0/", "requires_dist": null, "requires_python": ">=3.7,<4.0", "summary": "Generic metrics and context bases monitoring", "version": "1.0.0" }, "last_serial": 5990286, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "cb24ee8c95dc7efe0c44d5b3ca3e94f2", "sha256": "70a7b5e3bb57e1d7e5fb0a97d411cdfc641cc26541dfa4a44e893a227350b93f" }, "downloads": -1, "filename": "jetblack_metrics-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "cb24ee8c95dc7efe0c44d5b3ca3e94f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 7853, "upload_time": "2019-10-17T15:02:01", "url": "https://files.pythonhosted.org/packages/38/ad/db7dc5fdfc678c20dde4fe2cefb9dd0b4c881cc2a500b35b9989b1aece40/jetblack_metrics-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a22f1ef7e118f97a8852fe9e84530e04", "sha256": "f7d9dacef6420ec34e3602c277745d5b946d4d76660861eafc7048d292ceffd1" }, "downloads": -1, "filename": "jetblack-metrics-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a22f1ef7e118f97a8852fe9e84530e04", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 6941, "upload_time": "2019-10-17T15:01:56", "url": "https://files.pythonhosted.org/packages/63/05/7ede9e10f8953f9f152b3639e918161369b97ba04e62b99906379cd8919e/jetblack-metrics-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cb24ee8c95dc7efe0c44d5b3ca3e94f2", "sha256": "70a7b5e3bb57e1d7e5fb0a97d411cdfc641cc26541dfa4a44e893a227350b93f" }, "downloads": -1, "filename": "jetblack_metrics-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "cb24ee8c95dc7efe0c44d5b3ca3e94f2", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.7,<4.0", "size": 7853, "upload_time": "2019-10-17T15:02:01", "url": "https://files.pythonhosted.org/packages/38/ad/db7dc5fdfc678c20dde4fe2cefb9dd0b4c881cc2a500b35b9989b1aece40/jetblack_metrics-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a22f1ef7e118f97a8852fe9e84530e04", "sha256": "f7d9dacef6420ec34e3602c277745d5b946d4d76660861eafc7048d292ceffd1" }, "downloads": -1, "filename": "jetblack-metrics-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a22f1ef7e118f97a8852fe9e84530e04", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.7,<4.0", "size": 6941, "upload_time": "2019-10-17T15:01:56", "url": "https://files.pythonhosted.org/packages/63/05/7ede9e10f8953f9f152b3639e918161369b97ba04e62b99906379cd8919e/jetblack-metrics-1.0.0.tar.gz" } ] }