{ "info": { "author": "Jim Fulton", "author_email": "jim@zope.com", "bugtrack_url": null, "classifiers": [], "description": "==============\nMonitor Server\n==============\n\nThe monitor server is a server that provides a command-line interface to\nrequest various bits of information. The server is zc.ngi based, so we can use\nthe zc.ngi testing infrastructure to demonstrate it.\n\n >>> import zc.ngi.testing\n >>> import zc.monitor\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n\nThe server supports an extensible set of commands. It looks up\ncommands as named zc.monitor.interfaces.IMonitorPlugin \"utilities\", as defined\nby the zope.component package.\n\nTo see this, we'll create a hello plugin:\n\n >>> def hello(connection, name='world'):\n ... \"\"\"Say hello\n ...\n ... Provide a name if you're not the world.\n ... \"\"\"\n ... connection.write(\"Hi %s, nice to meet ya!\\n\" % name)\n\nand register it:\n\n >>> zc.monitor.register(hello)\n\nWhen we register a command, we can provide a name. To see this, we'll\nregister ``hello`` again:\n\n >>> zc.monitor.register(hello, 'hi')\n\nNow we can give the hello command to the server:\n\n >>> connection.test_input('hi\\n')\n Hi world, nice to meet ya!\n -> CLOSE\n\nWe can pass a name:\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('hello Jim\\n')\n Hi Jim, nice to meet ya!\n -> CLOSE\n\nThe server comes with a few basic commands. Let's register\nthem so we can see what they do. We'll use the simplfied registration\ninterface:\n\n >>> zc.monitor.register_basics()\n\nThe first is the help command. Giving help without input, gives a\nlist of available commands:\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('help\\n')\n Supported commands:\n hello -- Say hello\n help -- Get help about server commands\n hi -- Say hello\n interactive -- Turn on monitor's interactive mode\n quit -- Quit the monitor\n -> CLOSE\n\nWe can get detailed help by specifying a command name:\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('help help\\n')\n Help for help:\n \n Get help about server commands\n \n By default, a list of commands and summaries is printed. Provide\n a command name to get detailed documentation for a command.\n \n -> CLOSE\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('help hello\\n')\n Help for hello:\n \n Say hello\n \n Provide a name if you're not the world.\n \n -> CLOSE\n\nThe ``interactive`` command switches the monitor into interactive mode. As\nseen above, the monitor usually responds to a single command and then closes\nthe connection. In \"interactive mode\", the connection is not closed until\nthe ``quit`` command is used. This can be useful when accessing the monitor\nvia telnet for diagnostics.\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('interactive\\n')\n Interactive mode on. Use \"quit\" To exit.\n >>> connection.test_input('help interactive\\n')\n Help for interactive:\n \n Turn on monitor's interactive mode\n \n Normally, the monitor releases the connection after a single command.\n By entering the interactive mode, the monitor will not end the connection\n until you enter the \"quit\" command.\n \n In interactive mode, an empty line repeats the last command.\n \n >>> connection.test_input('help quit\\n')\n Help for quit:\n \n Quit the monitor\n \n This is only really useful in interactive mode (see the \"interactive\"\n command).\n \n\nNotice that the result of the commands did not end with \"-> CLOSE\", which would\nhave indicated a closed connection.\n\nAlso notice that the interactive mode allows you to repeat commands.\n\n >>> connection.test_input('hello\\n')\n Hi world, nice to meet ya!\n >>> connection.test_input('\\n')\n Hi world, nice to meet ya!\n >>> connection.test_input('hello Jim\\n')\n Hi Jim, nice to meet ya!\n >>> connection.test_input('\\n')\n Hi Jim, nice to meet ya!\n\nNow we will use ``quit`` to close the connection.\n\n >>> connection.test_input('quit\\n')\n Goodbye.\n -> CLOSE\n\nFinally, it's worth noting that exceptions will generate a\ntraceback on the connection.\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('hello Jim 42\\n') # doctest: +ELLIPSIS\n Traceback (most recent call last):\n ...\n TypeError: hello() takes at most 2 arguments (3 given)\n \n -> CLOSE\n\n.. Edge cases\n\n Closing the connection:\n\n >>> connection.test_close('test')\n\n\nCommand loops\n-------------\n\nUsing the \"MORE\" mode, commands can signal that they want to claim all future\nuser input. We'll implement a silly example to demonstrate how it works.\n\nHere's a command that implements a calculator.\n\n >>> PROMPT = '.'\n >>> def calc(connection, *args):\n ... if args and args[0] == 'quit':\n ... return zc.monitor.QUIT_MARKER\n ...\n ... if args:\n ... connection.write(str(eval(''.join(args))))\n ... connection.write('\\n')\n ...\n ... connection.write(PROMPT)\n ... return zc.monitor.MORE_MARKER\n\nIf we register this command...\n\n >>> zc.monitor.register(calc)\n\n...we can invoke it and we get a prompt.\n\n >>> connection = zc.ngi.testing.TextConnection()\n >>> server = zc.monitor.Server(connection)\n >>> connection.test_input('calc\\n')\n .\n\nIf we then give it more input we get the result plus another prompt.\n\n >>> connection.test_input('2+2\\n')\n 4\n .\n\n >>> connection.test_input('4*2\\n')\n 8\n .\n\nOnce we're done we can tell the calculator to let us go.\n\n >>> connection.test_input('quit\\n')\n -> CLOSE\n\nStart server\n------------\n\n >>> import time\n >>> import zope.testing.loggingsupport, logging\n >>> loghandler = zope.testing.loggingsupport.InstalledHandler(\n ... None, level=logging.INFO)\n\n\n >>> zc.monitor.start(9644)\n ('', 9644)\n\n >>> print loghandler\n zc.ngi.async.server INFO\n listening on ('', 9644)\n\n >>> zc.monitor.last_listener.close()\n >>> zc.monitor.last_listener = None\n >>> time.sleep(0.1)\n\n >>> loghandler.clear()\n\n >>> zc.monitor.start(('127.0.0.1', 9644))\n ('127.0.0.1', 9644)\n\n >>> print loghandler\n zc.ngi.async.server INFO\n listening on ('127.0.0.1', 9644)\n\n >>> zc.monitor.last_listener.close()\n >>> zc.monitor.last_listener = None\n >>> time.sleep(0.1)\n\nBind to port 0:\n\n >>> addr = zc.monitor.start(0)\n >>> addr == zc.monitor.last_listener.address\n True\n\n >>> zc.monitor.last_listener.close()\n >>> zc.monitor.last_listener = None\n >>> time.sleep(0.1)\n\nTrying to rebind to a port in use:\n\n >>> loghandler.clear()\n\n >>> zc.monitor.start(('127.0.0.1', 9644))\n ('127.0.0.1', 9644)\n\n >>> zc.monitor.start(('127.0.0.1', 9644))\n False\n\n >>> print loghandler\n zc.ngi.async.server INFO\n listening on ('127.0.0.1', 9644)\n zc.ngi.async.server WARNING\n unable to listen on ('127.0.0.1', 9644)\n root WARNING\n unable to start zc.monitor server because the address ('127.0.0.1', 9644) is in use.\n\n >>> zc.monitor.last_listener.close()\n >>> zc.monitor.last_listener = None\n >>> time.sleep(0.1)\n\n >>> loghandler.uninstall()\n\n\n==============\nChange History\n==============\n\n0.3.1 (2012-04-27)\n------------------\n\n- When binding the monitor to a Unix-domain socket, remove an existing\n socket at the same path so the bind is successful. This may affect\n existing usage with respect to zopectl debug behavior, but will be\n more predictable.\n\n\n0.3.0 (2011-12-12)\n------------------\n\n- Added a simplified registration interface.\n\n\n0.2.1 (2011-12-10)\n------------------\n\n- Added an ``address`` option to ``start`` to be able to specify an adapter\n to bind to.\n\n- ``start`` now returns the address being listened on, which is useful\n when binding to port 0.\n\n- Using Python's ``doctest`` module instead of depreacted\n ``zope.testing.doctest``.\n\n\n0.2.0 (2009-10-28)\n------------------\n\n- Add the \"MORE\" mode so commands can co-opt user interaction\n\n\n0.1.2 (2008-09-15)\n------------------\n\n- Bugfix: The z3monitor server lacked a handle_close method, which\n caused errors to get logged when users closed connections before\n giving commands.\n\n\n0.1.1 (2008-09-14)\n------------------\n\n- Bugfix: fixed and added test for regression in displaying tracebacks.\n\n\n0.1.0 (2008-09-14)\n------------------\n\nInitial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "zope3", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "zc.monitor", "package_url": "https://pypi.org/project/zc.monitor/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/zc.monitor/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/zc.monitor/0.3.1/", "requires_dist": null, "requires_python": null, "summary": "A network-accessible command-line monitoring interface.", "version": "0.3.1" }, "last_serial": 718565, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "ce3f54f92bf067975472e62a6a814bba", "sha256": "5bf4448d45a365045127ffb9acd015dcb4657ff1b6a8b1715f2a67ffe531af7b" }, "downloads": -1, "filename": "zc.monitor-0.1.0.tar.gz", "has_sig": false, "md5_digest": "ce3f54f92bf067975472e62a6a814bba", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6312, "upload_time": "2008-09-14T19:27:00", "url": "https://files.pythonhosted.org/packages/e1/41/104c81188486a1f728d2b5be98016b3357c4b3431083556f01dfa7f9856c/zc.monitor-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "da6bacb9eb455db18b0b49abadc08101", "sha256": "b6608d45a6ac867d2a93552063b6e7fbd69197c3050b494a9081d4ab4794af07" }, "downloads": -1, "filename": "zc.monitor-0.1.1.tar.gz", "has_sig": false, "md5_digest": "da6bacb9eb455db18b0b49abadc08101", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6593, "upload_time": "2008-09-15T01:56:20", "url": "https://files.pythonhosted.org/packages/b8/b9/d84ecad9a2da691f052fd870011c996d5152785990a0451aa67b2771e309/zc.monitor-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "1cfb24e880ef6e9d9ba5487bd830c508", "sha256": "22190c6b79da586ee481f5012ef44c786362ab6d65a524ce21c4f070b2d039be" }, "downloads": -1, "filename": "zc.monitor-0.1.2.tar.gz", "has_sig": false, "md5_digest": "1cfb24e880ef6e9d9ba5487bd830c508", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6077, "upload_time": "2008-09-15T22:25:18", "url": "https://files.pythonhosted.org/packages/e5/69/1a0bca8a3b72c82bb638708af28ec32bd62d000d9d845e5a206c3cb8c366/zc.monitor-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "e406ff70ec077b31e7358c9d938b3c8c", "sha256": "dd315f2e99f5a80ff201735e48f768f4ef9228b6e21099646db304f1a8cdcb5d" }, "downloads": -1, "filename": "zc.monitor-0.2.0.tar.gz", "has_sig": false, "md5_digest": "e406ff70ec077b31e7358c9d938b3c8c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6691, "upload_time": "2009-10-29T13:58:10", "url": "https://files.pythonhosted.org/packages/8d/a1/cdc5839824e202e666f8be358df2291835e629af703f193522a19eb9f6aa/zc.monitor-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "54d061a7c1a41c4a97c5c87409d5e4f4", "sha256": "81a0c241784531a67cd6f1f784c33a6f1835b16e4bce69842ae85e08bfe7020f" }, "downloads": -1, "filename": "zc.monitor-0.2.1.tar.gz", "has_sig": false, "md5_digest": "54d061a7c1a41c4a97c5c87409d5e4f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11162, "upload_time": "2011-12-10T18:46:51", "url": "https://files.pythonhosted.org/packages/67/5c/af2972cfded88f2abea299d6baa3e24272fe237ab7555a1094d33451883a/zc.monitor-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "7de7a83be6f386e3f3545b1488eecbc7", "sha256": "2b2b46acb9e667d757930aca92b4393fa75c991b00327129182d2c6e16f0ed78" }, "downloads": -1, "filename": "zc.monitor-0.3.0.tar.gz", "has_sig": false, "md5_digest": "7de7a83be6f386e3f3545b1488eecbc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11265, "upload_time": "2011-12-12T12:58:46", "url": "https://files.pythonhosted.org/packages/fc/a2/396bffa77294d0db40375b501b840f0b2d2a7686dc52addcabfbfd43923e/zc.monitor-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "55cd4a5a3cc8c0b5745d2dbfbe9823ee", "sha256": "612df49257353a68b13eab126dabe95e02b14615d48e18406db65a85cb64e904" }, "downloads": -1, "filename": "zc.monitor-0.3.1.tar.gz", "has_sig": false, "md5_digest": "55cd4a5a3cc8c0b5745d2dbfbe9823ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11521, "upload_time": "2012-04-27T18:19:26", "url": "https://files.pythonhosted.org/packages/56/c9/0de736fea00ec7e4087c3dd26d0ff831edf58feb4b93c1bce64ede1a1753/zc.monitor-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "55cd4a5a3cc8c0b5745d2dbfbe9823ee", "sha256": "612df49257353a68b13eab126dabe95e02b14615d48e18406db65a85cb64e904" }, "downloads": -1, "filename": "zc.monitor-0.3.1.tar.gz", "has_sig": false, "md5_digest": "55cd4a5a3cc8c0b5745d2dbfbe9823ee", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11521, "upload_time": "2012-04-27T18:19:26", "url": "https://files.pythonhosted.org/packages/56/c9/0de736fea00ec7e4087c3dd26d0ff831edf58feb4b93c1bce64ede1a1753/zc.monitor-0.3.1.tar.gz" } ] }