{ "info": { "author": "Niels Lensink", "author_email": "niels@elements.nl", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Topic :: Internet :: WWW/HTTP" ], "description": "Time Execution\n==============\n\n.. image:: https://secure.travis-ci.org/kpn-digital/py-timeexecution.svg?branch=master\n :target: http://travis-ci.org/kpn-digital/py-timeexecution?branch=master\n\n.. image:: https://img.shields.io/codecov/c/github/kpn-digital/py-timeexecution/master.svg\n :target: http://codecov.io/github/kpn-digital/py-timeexecution?branch=master\n\n.. image:: https://img.shields.io/pypi/v/py-timeexecution.svg\n :target: https://pypi.python.org/pypi/py-timeexecution\n\n.. image:: https://readthedocs.org/projects/py-timeexecution/badge/?version=latest\n :target: http://py-timeexecution.readthedocs.org/en/latest/?badge=latest\n\n\nThis package is designed to record metrics of the application into a backend.\nWith the help of grafana_ you can easily create dashboards with them\n\n\nFeatures\n--------\n\n- Sending data to multiple backends\n- Custom backends\n- Hooks\n\nBackends\n--------\n\n- InfluxDB 0.8\n- Elasticsearch 2.1\n\n\nInstallation\n------------\n\n.. code-block:: bash\n\n $ pip install py-timeexecution\n\nUsage\n-----\n\nTo use this package you decorate the functions you want to time its execution.\nEvery wrapped function will create a metric consisting of 3 default values:\n\n- `name` - The name of the series the metric will be stored in\n- `value` - The time it took in ms for the wrapped function to complete\n- `hostname` - The hostname of the machine the code is running on\n\nSee the following example\n\n.. code-block:: python\n\n from time_execution import configure, time_execution\n from time_execution.backends.influxdb import InfluxBackend\n from time_execution.backends.elasticsearch import ElasticsearchBackend\n\n # Setup the desired backend\n influx = InfluxBackend(host='influx', database='metrics', use_udp=False)\n elasticsearch = ElasticsearchBackend('elasticsearch', index='metrics')\n\n # Configure the time_execution decorator\n configure(backends=[influx, elasticsearch])\n\n # Wrap the methods where u want the metrics\n @time_execution\n def hello():\n return 'World'\n\n # Now when we call hello() and we will get metrics in our backends\n hello()\n\nThis will result in an entry in the influxdb\n\n.. code-block:: json\n\n [\n {\n \"name\": \"__main__.hello\",\n \"columns\": [\n \"time\",\n \"sequence_number\",\n \"value\",\n \"hostname\",\n ],\n \"points\": [\n [\n 1449739813939,\n 1111950001,\n 312,\n \"machine.name\",\n ]\n ]\n }\n ]\n\nAnd the following in Elasticsearch\n\n.. code-block:: json\n\n [\n {\n \"_index\": \"metrics-2016.01.28\",\n \"_type\": \"metric\",\n \"_id\": \"AVKIp9DpnPWamvqEzFB3\",\n \"_score\": null,\n \"_source\": {\n \"timestamp\": \"2016-01-28T14:34:05.416968\",\n \"hostname\": \"dfaa4928109f\",\n \"name\": \"__main__.hello\",\n \"value\": 312\n },\n \"sort\": [\n 1453991645416\n ]\n }\n ]\n\n\nHooks\n-----\n\n`time_execution` supports hooks where you can change the metric before its\nbeing send to the backend.\n\nWith a hook you can add additional and change existing fields. This can be\nuseful for cases where you would like to add a column to the metric based on\nthe response of the wrapped function.\n\nA hook will always get 3 arguments:\n\n- `response` - The returned value of the wrapped function\n- `exception` - The raised exception of the wrapped function\n- `metric` - A dict containing the data to be send to the backend\n- `func_args` - Original args received by the wrapped function.\n- `func_kwargs` - Original kwargs received by the wrapped function.\n\nFrom within a hook you can change the `name` if you want the metrics to be split\ninto multiple series.\n\nSee the following example how to setup hooks.\n\n.. code-block:: python\n\n # Now lets create a hook\n def my_hook(response, exception, metric, func_args, func_kwargs):\n status_code = getattr(response, 'status_code', None)\n if status_code:\n return dict(\n name='{}.{}'.format(metric['name'], status_code),\n extra_field='foo bar'\n )\n\n # Configure the time_execution decorator, but now with hooks\n configure(backends=[backend], hooks=[my_hook])\n\nManually sending metrics\n------------------------\n\nYou can also send any metric you have manually to the backend. These will not\nadd the default values and will not hit the hooks.\n\nSee the following example.\n\n.. code-block:: python\n\n loadavg = os.getloadavg()\n write_metric('cpu.load.1m', value=loadavg[0])\n write_metric('cpu.load.5m', value=loadavg[1])\n write_metric('cpu.load.15m', value=loadavg[2])\n\n.. _grafana: http://grafana.org/\n\n\nCustom Backend\n--------------\n\nWriting a custom backend is very simple, all you need to do is create a class\nwith a `write` method. It is not required to extend `BaseMetricsBackend`\nbut in order to easily upgrade I recommend u do.\n\n.. code-block:: python\n\n from time_execution.backends.base import BaseMetricsBackend\n\n\n class MetricsPrinter(BaseMetricsBackend):\n def write(self, name, **data):\n print(name, data)\n\n\nContribute\n----------\n\nYou have something to contribute ? Great !\nA few things that may come in handy.\n\nTesting in this project is done via docker. There is a docker-compose to easily\nget all the required containers up and running.\n\nThere is a Makefile with a few targets that we use often:\n\n- `make test`\n- `make isort`\n- `make lint`\n- `make build`\n- `make setup.py`\n\nAll of these make targets can be prefixed by `docker/`. This will execute\nthe target inside the docker container instead of on your local machine.\nFor example `make docker/build`.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kpn-digital/py-timeexecution", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "py-timeexecution", "package_url": "https://pypi.org/project/py-timeexecution/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/py-timeexecution/", "project_urls": { "Homepage": "https://github.com/kpn-digital/py-timeexecution" }, "release_url": "https://pypi.org/project/py-timeexecution/1.3.0/", "requires_dist": null, "requires_python": "", "summary": "Python project", "version": "1.3.0" }, "last_serial": 3176127, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "7f928777de28db767cf4ba10b3a6f14f", "sha256": "defb4cf18f682372b7e0a7aeeec7768127ff8083562adeb5c6bdee67f9ef1ba0" }, "downloads": -1, "filename": "py-timeexecution-1.0.0.tar.gz", "has_sig": false, "md5_digest": "7f928777de28db767cf4ba10b3a6f14f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11349, "upload_time": "2015-12-07T23:13:05", "url": "https://files.pythonhosted.org/packages/8c/a5/ce767a64543dc382bb4d4888623d19b91a6479749cbf9de89f946b8f6ca1/py-timeexecution-1.0.0.tar.gz" } ], "1.0.1": [], "1.0.2": [ { "comment_text": "", "digests": { "md5": "a361d65500be5d5407d811616763ac1e", "sha256": "3acc9768eeae398c22cff7431df657370b08071261168d7b23d01691c702d764" }, "downloads": -1, "filename": "py-timeexecution-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a361d65500be5d5407d811616763ac1e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14877, "upload_time": "2015-12-14T12:32:49", "url": "https://files.pythonhosted.org/packages/7a/e0/195e16078342b347f1147db6dec1e410365274442970f02d7ecff3a12de6/py-timeexecution-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "138673feaf79fb5ea16b5ffa085fa1ae", "sha256": "3ecd0e6b9c94833667ac0bd7525792502a2dec5de38a350b0210449463f1f5e6" }, "downloads": -1, "filename": "py-timeexecution-1.0.3.tar.gz", "has_sig": false, "md5_digest": "138673feaf79fb5ea16b5ffa085fa1ae", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14873, "upload_time": "2015-12-14T12:49:29", "url": "https://files.pythonhosted.org/packages/73/c6/d42529146c3c36f45851cfebd18bcf25de78b54411d85d6b641bbeba2208/py-timeexecution-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "215bd23193156cac54e2ffd8845e5b1f", "sha256": "2e7f55e4457f4e4a609e3eb2d55e205cf990a83190bd33c0b2daa995aa125340" }, "downloads": -1, "filename": "py-timeexecution-1.0.4.tar.gz", "has_sig": false, "md5_digest": "215bd23193156cac54e2ffd8845e5b1f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14873, "upload_time": "2015-12-14T12:53:42", "url": "https://files.pythonhosted.org/packages/1b/e8/27cf02786aead40794a72221a458f376f931a5034efb328e4c5fdc43af3e/py-timeexecution-1.0.4.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "1524fe4cae72e7f7905fa835a94fa1ff", "sha256": "469bd53d47da91bdd0e3eb5c9571d18e01af9b93832d71082beb0e52748468a0" }, "downloads": -1, "filename": "py-timeexecution-1.1.0.tar.gz", "has_sig": false, "md5_digest": "1524fe4cae72e7f7905fa835a94fa1ff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14906, "upload_time": "2016-01-21T12:30:34", "url": "https://files.pythonhosted.org/packages/c0/db/1770b3fab1e9a56a3a0ec99ea6ebb21a91afa2dccc8d1f1b3388cb380106/py-timeexecution-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "baa6f39052db101b7a37be0b09ac70eb", "sha256": "b7072966c38b714b05d18c6f98381540e3b7119dd98dfac5d9618ab5948d68b3" }, "downloads": -1, "filename": "py-timeexecution-1.2.0.tar.gz", "has_sig": false, "md5_digest": "baa6f39052db101b7a37be0b09ac70eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15019, "upload_time": "2016-01-26T15:00:30", "url": "https://files.pythonhosted.org/packages/c8/32/986da9a423a3c7c2088df872035c121d6febb7f7a0b92fd4571ed3bba62c/py-timeexecution-1.2.0.tar.gz" } ], "1.3.0": [ { "comment_text": "", "digests": { "md5": "7755ae631021ab2e09e37f692baa8aa5", "sha256": "65b4b48590877662a0217289dbc5033acb3544c5227f3576272278e00a8dfe8d" }, "downloads": -1, "filename": "py-timeexecution-1.3.0.tar.gz", "has_sig": false, "md5_digest": "7755ae631021ab2e09e37f692baa8aa5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18190, "upload_time": "2016-02-01T13:49:18", "url": "https://files.pythonhosted.org/packages/e2/53/14170006583c1e773832abd8a66b4b334c3ff4c03cab59fee402fd3f0ee4/py-timeexecution-1.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7755ae631021ab2e09e37f692baa8aa5", "sha256": "65b4b48590877662a0217289dbc5033acb3544c5227f3576272278e00a8dfe8d" }, "downloads": -1, "filename": "py-timeexecution-1.3.0.tar.gz", "has_sig": false, "md5_digest": "7755ae631021ab2e09e37f692baa8aa5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18190, "upload_time": "2016-02-01T13:49:18", "url": "https://files.pythonhosted.org/packages/e2/53/14170006583c1e773832abd8a66b4b334c3ff4c03cab59fee402fd3f0ee4/py-timeexecution-1.3.0.tar.gz" } ] }