一个可网络访问的命令行界面,用于监控Zope 3进程。
项目描述
Zope 3监控服务器
Zope 3监控服务器是一个在Zope 3进程中运行的服务器,它提供了一个命令行界面来请求各种信息。它基于zc.monitor,而zc.monitor本身又基于zc.ngi,因此我们可以使用zc.ngi测试基础设施来演示它。
此包提供了一些Zope 3和ZODB监控和内省工具,这些工具在zc.monitor服务器内部运行。以下是一些演示。
请参阅zc.monitor文档,了解服务器的工作细节。
此包还支持使用ZConfig启动监控器,并提供了默认的configure.zcml来注册插件。
此文档中未演示ZConfig设置,但使用很简单。在您的ZConfig文件中,为zc.z3monitor提供一个“product-config”段,指定zc.monitor服务器应监听的端口。
例如,此段将在端口8888上启动监控服务器
<product-config zc.z3monitor> bind 8888 </product-config>
绑定到特定地址
<product-config zc.z3monitor> bind 127.0.0.1:8888 </product-config>
绑定到Unix域套接字
<product-config zc.z3monitor> bind /var/socket </product-config>
要包含zc.monitor和zc.z3monitor的默认命令,只需包含此包中的configure.zcml
<include package="zc.z3monitor" />
现在,让我们看看此包提供的命令。我们将测试与监控服务器的连接,并注册zc.monitor和zc.z3monitor提供的插件。
>>> import zc.ngi.testing >>> import zc.monitor >>> import zc.monitor.interfaces >>> import zc.z3monitor >>> import zc.z3monitor.interfaces >>> import zope.component>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> zope.component.provideUtility(zc.monitor.help, ... zc.monitor.interfaces.IMonitorPlugin, 'help') >>> zope.component.provideUtility(zc.monitor.interactive, ... zc.monitor.interfaces.IMonitorPlugin, 'interactive') >>> zope.component.provideUtility(zc.monitor.quit, ... zc.monitor.interfaces.IMonitorPlugin, 'quit')>>> zope.component.provideUtility(zc.z3monitor.monitor, ... zc.z3monitor.interfaces.IZ3MonitorPlugin, 'monitor') >>> zope.component.provideUtility(zc.z3monitor.dbinfo, ... zc.z3monitor.interfaces.IZ3MonitorPlugin, 'dbinfo') >>> zope.component.provideUtility(zc.z3monitor.zeocache, ... zc.z3monitor.interfaces.IZ3MonitorPlugin, 'zeocache') >>> zope.component.provideUtility(zc.z3monitor.zeostatus, ... zc.z3monitor.interfaces.IZ3MonitorPlugin, 'zeostatus')
我们将使用zc.monitor的帮助命令来查看可用命令列表
>>> connection.test_input('help\n') Supported commands: dbinfo -- Get database statistics help -- Get help about server commands interactive -- Turn on monitor's interactive mode monitor -- Get general process info quit -- Quit the monitor zeocache -- Get ZEO client cache statistics zeostatus -- Get ZEO client status information -> CLOSE
zc.z3monitor 包自带的命令使用数据库信息。它们将数据库作为工具访问。让我们创建一些测试数据库并将它们注册为工具。
>>> from ZODB.tests.util import DB >>> main = DB() >>> from zope import component >>> import ZODB.interfaces >>> component.provideUtility(main, ZODB.interfaces.IDatabase) >>> other = DB() >>> component.provideUtility(other, ZODB.interfaces.IDatabase, 'other')
我们还需要在数据库中启用活动监控
>>> import ZODB.ActivityMonitor >>> main.setActivityMonitor(ZODB.ActivityMonitor.ActivityMonitor()) >>> other.setActivityMonitor(ZODB.ActivityMonitor.ActivityMonitor())
进程信息
要获取关于进程整体的信息,请使用监控命令
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('help monitor\n') Help for monitor: <BLANKLINE> Get general process info <BLANKLINE> The minimal output has: <BLANKLINE> - The number of open database connections to the main database, which is the database registered without a name. - The virtual memory size, and - The resident memory size. <BLANKLINE> If there are old database connections, they will be listed. By default, connections are considered old if they are greater than 100 seconds old. You can pass a minimum old connection age in seconds. If you pass a value of 0, you'll see all connections. <BLANKLINE> If you pass a name after the integer, this is used as the database name. The database name defaults to the empty string (''). <BLANKLINE> -> CLOSE>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('monitor\n') #doctest: +NORMALIZE_WHITESPACE 0 VmSize: 35284 kB VmRSS: 28764 kB -> CLOSE>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('monitor 100 other\n') #doctest: +NORMALIZE_WHITESPACE 0 VmSize: 35284 kB VmRSS: 28764 kB -> CLOSE
请注意,截至本文撰写时,VmSize 和 VmRSS 行仅在具有 procfs 的系统上存在。这通常包括许多种类的 Linux,不包括 OS X 和 Windows。
让我们创建一些连接,然后再次使用值为 0 的 z3monitor 命令
>>> conn1 = main.open() >>> conn2 = main.open()>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('monitor 0\n') #doctest: +NORMALIZE_WHITESPACE 2 VmSize: 36560 kB VmRSS: 28704 kB 0.0 (0) 0.0 (0) -> CLOSE
额外的输出行提供了连接调试信息。如果我们设置一些额外的输入,我们将看到它
>>> conn1.setDebugInfo('/foo') >>> conn2.setDebugInfo('/bar')>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('monitor 0\n') #doctest: +NORMALIZE_WHITESPACE 2 VmSize: 13048 kB VmRSS: 10084 kB 0.0 /bar (0) 0.0 /foo (0) -> CLOSE>>> conn1.close() >>> conn2.close()
数据库信息
要获取有关数据库的信息,请使用 dbinfo 命令
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('help dbinfo\n') Help for dbinfo: <BLANKLINE> Get database statistics <BLANKLINE> By default statistics are returned for the main database. The statistics are returned as a single line consisting of the: <BLANKLINE> - number of database loads <BLANKLINE> - number of database stores <BLANKLINE> - number of connections in the last five minutes <BLANKLINE> - number of objects in the object caches (combined) <BLANKLINE> - number of non-ghost objects in the object caches (combined) <BLANKLINE> You can pass a database name, where "-" is an alias for the main database. <BLANKLINE> By default, the statistics are for a sampling interval of 5 minutes. You can request another sampling interval, up to an hour, by passing a sampling interval in seconds after the database name. <BLANKLINE> -> CLOSE>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('dbinfo\n') #doctest: +NORMALIZE_WHITESPACE 0 0 2 0 0 -> CLOSE
让我们打开一个连接并做一些工作
>>> conn = main.open() >>> conn.root()['a'] = 1 >>> import transaction >>> transaction.commit() >>> conn.root()['a'] = 1 >>> transaction.commit() >>> conn.close()>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('dbinfo\n') #doctest: +NORMALIZE_WHITESPACE 1 2 3 1 1 -> CLOSE
您可以指定数据库名称。因此,要获取其他数据库的统计信息,我们将指定其注册时的名称
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('dbinfo other\n') #doctest: +NORMALIZE_WHITESPACE 0 0 0 0 0 -> CLOSE
您可以使用“-”来命名主数据库
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('dbinfo -\n') #doctest: +NORMALIZE_WHITESPACE 1 2 3 1 1 -> CLOSE
您可以指定要采样的秒数。例如,要获取最后 10 秒的数据
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('dbinfo - 10\n') #doctest: +NORMALIZE_WHITESPACE 1 2 3 1 1 -> CLOSE
ZEO 缓存统计
您可以使用 zeocache 命令获取 ZEO 缓存统计信息
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('help zeocache\n') Help for zeocache: <BLANKLINE> Get ZEO client cache statistics <BLANKLINE> The command returns data in a single line: <BLANKLINE> - the number of records added to the cache, <BLANKLINE> - the number of bytes added to the cache, <BLANKLINE> - the number of records evicted from the cache, <BLANKLINE> - the number of bytes evicted from the cache, <BLANKLINE> - the number of cache accesses. <BLANKLINE> By default, data for the main database are returned. To return information for another database, pass the database name. <BLANKLINE> -> CLOSE>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('zeocache\n') #doctest: +NORMALIZE_WHITESPACE 42 4200 23 2300 1000 -> CLOSE
您可以指定数据库名称
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('zeocache other\n') #doctest: +NORMALIZE_WHITESPACE 42 4200 23 2300 1000 -> CLOSE
ZEO 连接状态
zeostatus 命令让您获取 ZEO 连接状态信息
>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('help zeostatus\n') Help for zeostatus: <BLANKLINE> Get ZEO client status information <BLANKLINE> The command returns True if the client is connected and False otherwise. <BLANKLINE> By default, data for the main database are returned. To return information for another database, pass the database name. <BLANKLINE> -> CLOSE>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('zeostatus\n') #doctest: +NORMALIZE_WHITESPACE True -> CLOSE>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('zeostatus other\n') #doctest: +NORMALIZE_WHITESPACE True -> CLOSE
在此示例中,我们使用一个模拟的 ZEO 连接。它有一个属性来确定是否连接。如果我们更改它,则 zeocache 输出将更改
>>> main._storage._is_connected = False>>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)>>> connection.test_input('zeostatus\n') #doctest: +NORMALIZE_WHITESPACE False -> CLOSE
变更历史
0.8.0 (2012-02-21)
功能
添加了新产品配置选项 new bind product-config,以便绑定到特定地址/套接字。旧的端口仍然可用。
0.7.0 (2008-09-14)
功能
zc.monitor 交互模式现在支持通过发送空行来重复上一个命令。
其他
服务器和 help、interactive、quit 命令已被提取到新的 zc.monitor 包中,zc.z3monitor 现在依赖于该包。
0.6.0 (2008-09-14)
功能
新的 interactive 命令使连接可以继续通过多个命令,直到您使用 quit 命令。
monitor 命令接受可选的数据库参数(在旧的长参数之后)。
0.5.0 (2008-4-4)
功能
如果请求的监控端口正在使用中,则记录并继续,而不是使用异常停止进程。这使得 zopectl debug 可以与运行实例一起工作。
0.4.1 (2008-3-31)
PyPI 的初始发布
错误修复
根据失败的测试,将 zope.app.appsetup 添加到依赖项中
其他
添加了注释,说明监控示例目前在没有 procfs 的系统上失败
调整 setup.py 以进行 PyPI 发布
0.4.0 (2007-11-29)
新功能
将 ZEO 缓存状态移动到 zeostatus 命令。
0.3.0 (2007-11-29)
新功能
命令现在作为工具提供。这意味着可以通过实现简单的工具来添加 z3monitor 命令。
添加了一个工作的 help 命令。
将 ZEO 连接状态添加到 zeocache 输出。
0.2.0 (2007-11-15)
新功能
添加了一个获取 ZEO 缓存统计信息的命令。
项目详情
zc.z3monitor-0.8.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c602cfbe33c1c74c82991a67883b842abef777307cd9a48521072f2bcf6ec1e2 |
|
MD5 | 5669db32a8700975b755c51af55d956b |
|
BLAKE2b-256 | 019f8350b7a02576280ccfbee0812b31883dcf3c37f29e2da1f6609ef2309bb0 |