[Checkins] SVN: zc.zkzeo/trunk/s Added zc.monitor support.

Jim Fulton jim at zope.com
Sun Dec 11 18:31:44 UTC 2011


Log message for revision 123675:
  Added zc.monitor support.
  

Changed:
  U   zc.zkzeo/trunk/setup.py
  U   zc.zkzeo/trunk/src/zc/zkzeo/README.txt
  U   zc.zkzeo/trunk/src/zc/zkzeo/runzeo.py
  U   zc.zkzeo/trunk/src/zc/zkzeo/server-component.xml
  U   zc.zkzeo/trunk/src/zc/zkzeo/tests.py

-=-
Modified: zc.zkzeo/trunk/setup.py
===================================================================
--- zc.zkzeo/trunk/setup.py	2011-12-11 17:23:41 UTC (rev 123674)
+++ zc.zkzeo/trunk/setup.py	2011-12-11 18:31:44 UTC (rev 123675)
@@ -16,7 +16,7 @@
 install_requires = [
     'setuptools', 'zc.zk [static]', 'ZODB3', 'zc.thread']
 extras_require = dict(
-    test=['zope.testing', 'zc.zk [static,test]', 'manuel'],
+    test=['zope.testing', 'zc.zk [static,test]', 'manuel', 'zc.monitor'],
     )
 
 entry_points = """

Modified: zc.zkzeo/trunk/src/zc/zkzeo/README.txt
===================================================================
--- zc.zkzeo/trunk/src/zc/zkzeo/README.txt	2011-12-11 17:23:41 UTC (rev 123674)
+++ zc.zkzeo/trunk/src/zc/zkzeo/README.txt	2011-12-11 18:31:44 UTC (rev 123675)
@@ -59,14 +59,63 @@
     >>> stop = zc.zkzeo.runzeo.test(
     ...     server_conf)
     >>> zk = zc.zk.ZooKeeper('zookeeper.example.com:2181')
-    >>> print zk.export_tree('/databases/demo', ephemeral=True),
+    >>> zk.print_tree('/databases/demo')
     /demo
       /127.0.0.1:56824
         pid = 88841
 
+    >>> _ = stop()
+    >>> zk.print_tree('/databases/demo')
+    /demo
+
+    >>> zk.close()
+
 where ``FILENAME`` is the name of the configuration file you created.
 
+Including a ``zc.monitor`` monitoring server
+--------------------------------------------
 
+The `zc.monitor <http://pypi.python.org/pypi/zc.monitor>`_ package
+provides a simple extensible command server for gathering monitoring
+data or providing run-time control of servers.  If ``zc.monitor`` is
+in the Python path, ``zc.zk`` can start a monitor server and make it's
+address available as the ``monitor`` property of of a server's
+ephemeral port.  To request this, we use a ``monitor-server`` option in
+the ``zookeeper`` section::
+
+   <zeo>
+      address 127.0.0.1
+   </zeo>
+
+   <zookeeper>
+      connection zookeeper.example.com:2181
+      path /databases/demo
+      monitor-server 127.0.0.1
+   </zookeeper>
+
+   <filestorage>
+      path demo.fs
+   </filestorage>
+
+.. -> server_conf
+
+    >>> stop = zc.zkzeo.runzeo.test(
+    ...     server_conf)
+
+The value is the address to listen on.
+
+With the configuration above, if we started the server and looked at
+the ZooKeeper tree for '/databases/demo' using the ``zc.zk`` package, we'd
+see something like the following::
+
+    >>> import zc.zk
+    >>> zk = zc.zk.ZooKeeper('zookeeper.example.com:2181')
+    >>> zk.print_tree('/databases/demo')
+    /demo
+      /127.0.0.1:64211
+        monitor = u'localhost:11976'
+        pid = 5082
+
 Defining ZEO clients
 ====================
 
@@ -211,6 +260,7 @@
     >>> print zk.export_tree('/databases/demo', ephemeral=True),
     /demo
       /127.0.0.1:56837
+        monitor = u'localhost:23265'
         pid = 88841
 
     >>> wait_until(db_from_config.storage.is_connected)

Modified: zc.zkzeo/trunk/src/zc/zkzeo/runzeo.py
===================================================================
--- zc.zkzeo/trunk/src/zc/zkzeo/runzeo.py	2011-12-11 17:23:41 UTC (rev 123674)
+++ zc.zkzeo/trunk/src/zc/zkzeo/runzeo.py	2011-12-11 18:31:44 UTC (rev 123675)
@@ -21,6 +21,7 @@
         self.add('zkconnection', 'zookeeper.connection')
         self.add('zkpath', 'zookeeper.path')
         self.add('zookeeper_session_timeout', 'zookeeper.session_timeout')
+        self.add('monitor_server', 'zookeeper.monitor_server')
 
 class ZKServer(ZEO.runzeo.ZEOServer):
 
@@ -32,7 +33,15 @@
 
         addr = self.server.dispatcher.socket.getsockname()
         def register():
-            self.__zk.register_server(self.options.zkpath, addr)
+
+            props = {}
+            if self.options.monitor_server:
+                global zc
+                import zc.monitor
+                props['monitor'] = "%s:%s" % zc.monitor.start(
+                    self.options.monitor_server)
+
+            self.__zk.register_server(self.options.zkpath, addr, **props)
             if self.__testing is not None:
                 self.__testing()
 

Modified: zc.zkzeo/trunk/src/zc/zkzeo/server-component.xml
===================================================================
--- zc.zkzeo/trunk/src/zc/zkzeo/server-component.xml	2011-12-11 17:23:41 UTC (rev 123674)
+++ zc.zkzeo/trunk/src/zc/zkzeo/server-component.xml	2011-12-11 18:31:44 UTC (rev 123675)
@@ -16,7 +16,7 @@
 
     <key name="path" datatype="string" required="yes">
       <description>
-        The path to register the 
+        The path to register the ZEO server at.
       </description>
     </key>
 
@@ -26,6 +26,13 @@
       </description>
     </key>
 
+    <key name="monitor-server" datatype="socket-binding-address" required="no">
+      <description>
+         Run a monitor server. The value should either be true, an
+         address, a host, or a port.
+      </description>
+    </key>
+
   </sectiontype>
 
 </component>

Modified: zc.zkzeo/trunk/src/zc/zkzeo/tests.py
===================================================================
--- zc.zkzeo/trunk/src/zc/zkzeo/tests.py	2011-12-11 17:23:41 UTC (rev 123674)
+++ zc.zkzeo/trunk/src/zc/zkzeo/tests.py	2011-12-11 18:31:44 UTC (rev 123675)
@@ -21,6 +21,7 @@
 import time
 import ZEO.zrpc.connection
 import ZODB.config
+import zc.monitor
 import zc.zk.testing
 import zc.zkzeo
 import zc.zkzeo.runzeo
@@ -255,24 +256,29 @@
     zc.zk.testing.tearDown(test)
     ZEO.zrpc.connection.server_loop = test.globs['_server_loop']
 
+def tearDownREADME(test):
+    tearDown(test)
+    zc.monitor.last_listener.close()
+
 def test_suite():
     checker = zope.testing.renormalizing.RENormalizing([
         (re.compile(r'pid = \d+'), 'pid = PID'),
         (re.compile(r'127.0.0.1:\d+'), '127.0.0.1:PORT'),
+        (re.compile(r'localhost:\d+'), 'localhost:PORT'),
         ])
     suite = unittest.TestSuite((
         doctest.DocTestSuite(
-            setUp=setUp, tearDown=zc.zk.testing.tearDown, checker=checker),
+            setUp=setUp, tearDown=tearDown, checker=checker),
         manuel.testing.TestSuite(
             manuel.doctest.Manuel(checker=checker) + manuel.capture.Manuel(),
             'README.txt',
-            setUp=setUp, tearDown=zc.zk.testing.tearDown,
+            setUp=setUp, tearDown=tearDownREADME,
             ),
         ))
     if not zc.zk.testing.testing_with_real_zookeeper():
         suite.addTest(doctest.DocFileSuite(
             'wait-for-zookeeper.test',
-            setUp=setUp, tearDown=zc.zk.testing.tearDown,
+            setUp=setUp, tearDown=tearDown,
             checker=checker))
 
     return suite



More information about the checkins mailing list