{ "info": { "author": "Ronnie Kolehmainen", "author_email": "ronnie@esn.me", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "graphite-pymetrics\r\n==================\r\ngraphite-pymetrics is a lightweight Python framework which makes it super simple to add application metrics\r\nthat is sent to a remote graphite/carbon server.\r\n\r\nAll that is needed is this package (which also includes pystatsd) and access to a remote graphite server.\r\n\r\nTo install it just run Pip as usual::\r\n\r\n $ pip install graphite-pymetrics\r\n\r\nPackage requirements:\r\n - pystatsd==0.1.6\r\n - gevent\r\n\r\n=====\r\nUsage\r\n=====\r\nMake sure there is a local graphite proxy running - start it at an early point in your application::\r\n\r\n from metrics.graphite import start_graphite_proxy\r\n start_graphite_proxy({\"host\": \"graphite.mycompany.com\", \"port\": 2003})\r\n\r\nThe proxy is pystatsd, a local server that receives UDP packets from the metrics client and periodically\r\nemits data to graphite over TCP.\r\n\r\n~~~~~~~~\r\nCounters\r\n~~~~~~~~\r\nTo add a counter for anything anywhere in your code, use Metric.add::\r\n\r\n from metrics import Metric\r\n\r\n Metric.add(\"foo.bar\")\r\n\r\nUse the @metric decorator to count specific method invocations::\r\n\r\n from metrics import metric\r\n\r\n @metric(\"bar.baz\")\r\n def foo():\r\n # do stuff here\r\n\r\n~~~~~~\r\nTiming\r\n~~~~~~\r\nThere are several ways to log timing. The most naive way is to first measure time manually and then submit it::\r\n\r\n from metrics import Metric\r\n import time\r\n\r\n start = time.time()\r\n # do stuff\r\n elapsed = time.time() - start\r\n Metric.timing(\"do.stuff\", elapsed)\r\n\r\n\r\nAn easier way is to to let the metric client keep track of time with Metric.start_timing and call done() on the\r\nreturned timing instance. Following is an example for measuring time consumed for every endpoint individually\r\nin a Flask webapp::\r\n\r\n from metrics import Metric\r\n from flask import Blueprint, current_app, request, g\r\n\r\n app = Blueprint(\"myapp\", __name__)\r\n\r\n @app.before_request\r\n def before_request():\r\n try:\r\n g.timing = Metric.start_timing(str(request.endpoint)) # start timing\r\n except:\r\n current_app.logger.error(\"Unable to time call for 'request.endpoint'\")\r\n\r\n @app.teardown_request\r\n def teardown_request(exc):\r\n try:\r\n g.timing.done() # stop timing\r\n except:\r\n current_app.logger.error(\"Timing not available\")\r\n\r\n\r\nSimilar to the @metric decorator there is a @timing decorator which is used to measure time for specific methods::\r\n\r\n from metrics import timing\r\n\r\n @timing(\"heavy.task\")\r\n def heavy_task(x, y, z):\r\n # do heavy stuff here", "description_content_type": null, "docs_url": null, "download_url": "http://github.com/esnme/graphite-pymetrics", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.esn.me", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "graphite-pymetrics", "package_url": "https://pypi.org/project/graphite-pymetrics/", "platform": "any", "project_url": "https://pypi.org/project/graphite-pymetrics/", "project_urls": { "Download": "http://github.com/esnme/graphite-pymetrics", "Homepage": "http://www.esn.me" }, "release_url": "https://pypi.org/project/graphite-pymetrics/0.1.1/", "requires_dist": null, "requires_python": null, "summary": "A simple Python metrics framework to use with carbon/graphite.", "version": "0.1.1" }, "last_serial": 792668, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "3de724b0c574818a0813c365d9efd1fb", "sha256": "d0a087ac9517c4f1f8d84da616a9938d6e2968705d46ebac8c4681e78a14ab0a" }, "downloads": -1, "filename": "graphite-pymetrics-0.1.1.tar.gz", "has_sig": false, "md5_digest": "3de724b0c574818a0813c365d9efd1fb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6021, "upload_time": "2012-11-23T08:30:07", "url": "https://files.pythonhosted.org/packages/da/0b/3f9303d7d01c4341868a9d51a7074e50da4f83b4f7fee07964d53d9c8558/graphite-pymetrics-0.1.1.tar.gz" } ], "0.1.1": [] }, "urls": [] }