[Checkins] SVN: zc.monitorcache/trunk/ - Add files

Alex Chapman achapman at zope.com
Tue Dec 21 17:26:39 EST 2010


Log message for revision 119041:
   - Add files
  

Changed:
  _U  zc.monitorcache/trunk/
  A   zc.monitorcache/trunk/buildout.cfg
  A   zc.monitorcache/trunk/setup.py
  A   zc.monitorcache/trunk/src/
  A   zc.monitorcache/trunk/src/zc/
  A   zc.monitorcache/trunk/src/zc/__init__.py
  A   zc.monitorcache/trunk/src/zc/monitorcache/
  A   zc.monitorcache/trunk/src/zc/monitorcache/README.txt
  A   zc.monitorcache/trunk/src/zc/monitorcache/__init__.py
  A   zc.monitorcache/trunk/src/zc/monitorcache/configure.zcml
  A   zc.monitorcache/trunk/src/zc/monitorcache/tests.py

-=-

Property changes on: zc.monitorcache/trunk
___________________________________________________________________
Added: svn:ignore
   + develop-eggs
bootstrap.py
bin
parts


Added: zc.monitorcache/trunk/buildout.cfg
===================================================================
--- zc.monitorcache/trunk/buildout.cfg	                        (rev 0)
+++ zc.monitorcache/trunk/buildout.cfg	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,13 @@
+[buildout]
+develop = .
+parts = test py
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.monitorcache
+
+[py]
+recipe = zc.recipe.egg
+eggs = ${test:eggs}
+interpreter = py
+

Added: zc.monitorcache/trunk/setup.py
===================================================================
--- zc.monitorcache/trunk/setup.py	                        (rev 0)
+++ zc.monitorcache/trunk/setup.py	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,38 @@
+##############################################################################
+#
+# Copyright (c) Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os, setuptools
+
+
+def read(name):
+    fn = os.path.join(os.path.dirname(__file__), *name.split('/'))
+    with open(fn) as f:
+        return f.read()
+
+setuptools.setup(
+    name = 'zc.monitorcache',
+    version = '0',
+    author = 'Alex Chapman',
+    author_email = 'achapman at zope.com',
+    description = 'zc.monitor plugin to modify cache sizes',
+    long_description = read('src/zc/monitorcache/README.txt'),
+    license = 'ZPL 2.1',
+    include_package_data = True,
+    packages = setuptools.find_packages('src'),
+    namespace_packages = ['zc'],
+    package_dir = {'': 'src'},
+    install_requires = ['setuptools', 'zc.monitor', 'zc.z3monitor'],
+    zip_safe = False,
+    extras_require = dict()
+    )

Added: zc.monitorcache/trunk/src/zc/__init__.py
===================================================================
--- zc.monitorcache/trunk/src/zc/__init__.py	                        (rev 0)
+++ zc.monitorcache/trunk/src/zc/__init__.py	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,11 @@
+# This is a namespace package.
+
+try:
+    import pkg_resources
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)
+    del pkgutil
+else:
+    pkg_resources.declare_namespace(__name__)
+    del pkg_resources

Added: zc.monitorcache/trunk/src/zc/monitorcache/README.txt
===================================================================
--- zc.monitorcache/trunk/src/zc/monitorcache/README.txt	                        (rev 0)
+++ zc.monitorcache/trunk/src/zc/monitorcache/README.txt	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,91 @@
+zc.monitorcache
+===============
+
+zc.montorcache is a zc.z3monitor plugin that allows one to modify or check
+the cache size (in objects or bytes) of a running instance.
+
+    >>> import zc.monitorcache
+    >>> import zope.component
+    >>> import zc.ngi.testing
+    >>> import zc.monitor
+    >>> import zc.monitor.interfaces
+    >>> import zc.z3monitor
+    >>> import zc.z3monitor.interfaces
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> zope.component.provideUtility(zc.monitorcache.cacheMonitor,
+    ...     zc.z3monitor.interfaces.IZ3MonitorPlugin, 'cache_size')
+
+    >>> connection.test_input('cache_size\n')
+    -> CLOSE
+
+We have no databases right now. Lets add a few so that we can test.
+
+    >>> import ZODB.tests.util
+    >>> import ZODB.interfaces
+    >>> main = ZODB.tests.util.DB()
+    >>> zope.component.provideUtility(main, ZODB.interfaces.IDatabase)
+    >>> test = ZODB.tests.util.DB()
+    >>> zope.component.provideUtility(
+    ...     test, ZODB.interfaces.IDatabase, 'test')
+
+Now we should get information on each of the database's cache sizes
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> connection.test_input('cache_size\n')
+    DB cache sizes for main
+    Max objects: 400
+    Max object size bytes: 0MB
+    DB cache sizes for test
+    Max objects: 400
+    Max object size bytes: 0MB
+    -> CLOSE
+
+we can request information about a specific db as well
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> connection.test_input('cache_size -\n')
+    DB cache sizes for main
+    Max objects: 400
+    Max object size bytes: 0MB
+    -> CLOSE
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> connection.test_input('cache_size test\n')
+    DB cache sizes for test
+    Max objects: 400
+    Max object size bytes: 0MB
+    -> CLOSE
+
+We can also modify cache sizes for a specific db
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> connection.test_input('cache_size test 300\n')
+    Set max objects to 300
+    -> CLOSE
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> connection.test_input('cache_size test 10MB\n')
+    Set max object size bytes to 10MB
+    -> CLOSE
+
+    >>> connection = zc.ngi.testing.TextConnection()
+    >>> server = zc.monitor.Server(connection)
+
+    >>> connection.test_input('cache_size test\n')
+    DB cache sizes for test
+    Max objects: 300
+    Max object size bytes: 10MB
+    -> CLOSE

Added: zc.monitorcache/trunk/src/zc/monitorcache/__init__.py
===================================================================
--- zc.monitorcache/trunk/src/zc/monitorcache/__init__.py	                        (rev 0)
+++ zc.monitorcache/trunk/src/zc/monitorcache/__init__.py	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,44 @@
+##############################################################################
+#
+# Copyright (c) Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import zope.component
+import ZODB.interfaces
+
+mb_b = 1048576
+
+def cacheMonitor(connection, database=None, size=''):
+    msg = ''
+    if database is None:
+       for nm, db in zope.component.getUtilitiesFor(ZODB.interfaces.IDatabase):
+           msg += 'DB cache sizes for %s\n' % (nm or 'main')
+           msg += 'Max objects: %s\n' % db._cache_size
+           msg += 'Max object size bytes: %sMB\n' % (db._cache_size_bytes/mb_b)
+    else:
+        if database == '-':
+            database = ''
+        db = zope.component.getUtility(ZODB.interfaces.IDatabase, database)
+        if not size:
+            msg += 'DB cache sizes for %s\n' % (database or 'main')
+            msg += 'Max objects: %s\n' % db._cache_size
+            msg += 'Max object size bytes: %sMB\n' % (
+                db._cache_size_bytes/mb_b)
+        elif size.endswith('MB'):
+            num = int(size[:-2])
+            num *= mb_b
+            db.setCacheSizeBytes(num)
+            msg += 'Set max object size bytes to %s\n' % size
+        else:
+            db.setCacheSize(int(size))
+            msg += 'Set max objects to %s\n' % size
+    connection.write(str(msg))

Added: zc.monitorcache/trunk/src/zc/monitorcache/configure.zcml
===================================================================
--- zc.monitorcache/trunk/src/zc/monitorcache/configure.zcml	                        (rev 0)
+++ zc.monitorcache/trunk/src/zc/monitorcache/configure.zcml	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,7 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+  <utility
+    component=".cacheMonitor"
+    provides="zc.z3monitor.interfaces.IZ3MonitorPlugin"
+    name="cache_size"
+    />
+</configure>

Added: zc.monitorcache/trunk/src/zc/monitorcache/tests.py
===================================================================
--- zc.monitorcache/trunk/src/zc/monitorcache/tests.py	                        (rev 0)
+++ zc.monitorcache/trunk/src/zc/monitorcache/tests.py	2010-12-21 22:26:38 UTC (rev 119041)
@@ -0,0 +1,20 @@
+##############################################################################
+#
+# Copyright (c) Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+from zope.testing import doctest
+
+def test_suite():
+    return doctest.DocFileSuite(
+        'README.txt',
+        optionflags=doctest.NORMALIZE_WHITESPACE)



More information about the checkins mailing list