{ "info": { "author": "John Casey", "author_email": "jdcasey@commonjava.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License (GPL)", "Programming Language :: Python :: 3", "Topic :: Utilities" ], "description": "mu Relay (mulay) Library for Python\n========================================\n\nThis library's main purpose is to establish a common framework for relaying messages from one bus to another, or to some message consumer (such as Carbon / GraphiteDB). It currently includes support for MQTT, AMQP, and for using a Slack channel as a poor man's message bus. \n\nBasic Architecture\n------------------\n\nYou can configure this library pretty much any way you want. Each Sender or Relay class expects a configuration dict with relevant details for connecting. Relays also expect a Sender object, which allows you to pair any receiver type (implemented in the Relay) to any type of Sender. Since each class only expects a dict for configuration, it's possible to bridge two buses of the same protocol together using different configuration dicts, or subsections of the same larger configuration.\n\nExample: Relay MQTT to Carbon (GraphiteDB)\n------------------------------------------\n\nWe can use the MQTT Relay class with the Carbon Sender class to relay between a public MQTT server and a GraphiteDB server without exposing the GraphiteDB server to the internet. First, the configuration, which we could conveniently store in a YAML file::\n\n\tcarbon:\n\t\thost: my.graphitedb.home.net\n\t\tport: 2023\n\tmqtt:\n\t\thost: m16.cloudmqtt.com\n\t\tport: 20996\n\t\tuser: \n\t\tpassword: \n\nThen, in our code we start a sender for Carbon, and a relay for MQTT with the sender as a parameter::\n\n\tfrom mulay.carbon import PlaintextSender\n\tfrom mulay.mqtt import Relay\n\n\tsender = PlaintextSender(config['carbon'])\n\trelay = Relay(config['mqtt'], sender)\n\n try:\n\t\tsender.start()\n\n\t\t# Relay will loop forever\n\t\trelay.start()\n\texcept KeyboardInterrupt:\n\t\trelay.stop()\n\t\tsender.stop()\n\nExample: Relay MQTT to Carbon (GraphiteDB)\n------------------------------------------\n\nOr, we could opt to use an AMQP service, by specifying the AMQP Relay class with the Carbon Sender class. Again, this will not expose the GraphiteDB server to the internet. First, the configuration, which we could conveniently store in a YAML file::\n\n\tcarbon:\n\t\thost: my.graphitedb.home.net\n\t\tport: 2023\n\tamqp:\n\t\turl: amqp://:@wombat.rmq.cloudamqp.com/\n\t\tqueue: my-metrics\n\nThen, in our code we start a sender for Carbon, and a relay for MQTT with the sender as a parameter::\n\n\tfrom mulay.carbon import PlaintextSender\n\tfrom mulay.amqp import Relay\n\n\tsender = PlaintextSender(config['carbon'])\n\trelay = Relay(config['amqp'], sender)\n\n try:\n\t\tsender.start()\n\n\t\t# Relay will loop forever\n\t\trelay.start()\n\texcept KeyboardInterrupt:\n\t\trelay.stop()\n\t\tsender.stop()\n\nExample: Relay Slack to Carbon (GraphiteDB)\n-------------------------------------------\n\nWe can even use Slack in much the same way as MQTT or AMQP, with the Carbon Sender class. First, the configuration, which we could conveniently store in a YAML file::\n\n\tcarbon:\n\t\thost: my.graphitedb.home.net\n\t\tport: 2023\n\tslack:\n\t\ttoken: \n\t\tchannel: my-metrics\n\nThen, in our code we start a sender for Carbon, and a relay for Slack with the sender as a parameter::\n\n\tfrom mulay.carbon import PlaintextSender\n\tfrom mulay.slack import Relay\n\n\tsender = PlaintextSender(config['carbon'])\n\trelay = Relay(config['slack'], sender)\n\n try:\n\t\tsender.start()\n\n\t\t# Relay will loop forever\n\t\trelay.start()\n\texcept KeyboardInterrupt:\n\t\trelay.stop()\n\t\tsender.stop()\n\nExample: Publishing to MQTT\n---------------------------\n\nAs a convenience, and to make the relay functions truly flexible, mulay provides a Sender class with all of the protocol implementations. This is to allow bridging from any protocol to any other protocol that's supported by the library, but it's also useful for publishing into a public bus some data that will eventually get routed into your internal consumer server (such as GraphiteDB). This only requires configuration for the public bus, which makes it simpler than a relay configuration::\n\n\thost: m16.cloudmqtt.com\n\tport: 20996\n\tuser: \n\tpassword: \n\nThen, in our code, we setup a loop to take measurements and publish them::\n\n\tfrom mulay.mqtt import Sender\n\timport time\n\timport speedtest as st\n\n\tsender = Sender(config)\n\tsender.start()\n\n test = st.Speedtest()\n test.get_best_server()\n\n try:\n\t while True:\n\t\t test.download()\n\t\t test.upload()\n\n\t\t result = test.results.dict()\n\n\t\t now = int(time.time())\n\n\t\t sender.send_raw(f\"my.speedtest.download {result['download']} {now}\")\n\t\t sender.send_raw(f\"my.speedtest.upload {result['upload']} {now}\")\n\n\t\t time.sleep(30) # check this at most every 30 seconds\n\texcept KeyboardInterrupt:\n\t\tsender.stop()", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jdcasey/mulay", "keywords": "graphite carbon metrics monitoring mqtt amqp slack", "license": "GPLv3+", "maintainer": "", "maintainer_email": "", "name": "mulay", "package_url": "https://pypi.org/project/mulay/", "platform": "", "project_url": "https://pypi.org/project/mulay/", "project_urls": { "Homepage": "https://github.com/jdcasey/mulay" }, "release_url": "https://pypi.org/project/mulay/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "Relay / sender library for various bus / consumer types", "version": "0.3.0" }, "last_serial": 5170305, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "e7f688169d8a5e4be8ee6fd938351994", "sha256": "e245ae87278e878d9b88fba2196a234898c455979c6a5ce913554dab126a5af8" }, "downloads": -1, "filename": "mulay-0.0.2.tar.gz", "has_sig": false, "md5_digest": "e7f688169d8a5e4be8ee6fd938351994", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18593, "upload_time": "2019-04-14T21:59:34", "url": "https://files.pythonhosted.org/packages/a7/d7/593e92440e876b95922b6fd45d33ea351343bbb17402a86da7743be301bf/mulay-0.0.2.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "c6c5d4d5b232e9f7754e327aeb869da8", "sha256": "94563149d3a0db3d964ffe0f30031dd3c03f51ef76d13a0aef832934809366d8" }, "downloads": -1, "filename": "mulay-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c6c5d4d5b232e9f7754e327aeb869da8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19272, "upload_time": "2019-04-21T05:36:06", "url": "https://files.pythonhosted.org/packages/0b/fa/71af54b0f4df439dc735cd892b16e8f0c62dec417c2a4c1adbccefe47c1d/mulay-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "752aa569de1f0d1f3a19ffbefaa6f99e", "sha256": "767936b531a0cb2d3dffd7efc90c26679faf0511c1965a1ec3445c2537055a9d" }, "downloads": -1, "filename": "mulay-0.2.0.tar.gz", "has_sig": false, "md5_digest": "752aa569de1f0d1f3a19ffbefaa6f99e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19274, "upload_time": "2019-04-21T05:51:02", "url": "https://files.pythonhosted.org/packages/1e/50/6814130dfe350b86496598c2470997fa96a4fbe52d5a79d2f2531a001728/mulay-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "7506feabd069420933fc6e6ea4349706", "sha256": "5f52eb5b9caf97fb7a1f6df421743f57eae89637c76efd97d0914d6fef11f777" }, "downloads": -1, "filename": "mulay-0.3.0.tar.gz", "has_sig": false, "md5_digest": "7506feabd069420933fc6e6ea4349706", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19273, "upload_time": "2019-04-21T17:20:41", "url": "https://files.pythonhosted.org/packages/d5/5d/5d12bfee6525f060c0e83ab1b56ef9dbf6a6f936f370a28e780fb2e3e56a/mulay-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7506feabd069420933fc6e6ea4349706", "sha256": "5f52eb5b9caf97fb7a1f6df421743f57eae89637c76efd97d0914d6fef11f777" }, "downloads": -1, "filename": "mulay-0.3.0.tar.gz", "has_sig": false, "md5_digest": "7506feabd069420933fc6e6ea4349706", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19273, "upload_time": "2019-04-21T17:20:41", "url": "https://files.pythonhosted.org/packages/d5/5d/5d12bfee6525f060c0e83ab1b56ef9dbf6a6f936f370a28e780fb2e3e56a/mulay-0.3.0.tar.gz" } ] }