MongoDB流量模式监控器
项目描述
MongoWatch提供了一个简单的方法来测量程序中特定点的mongo数据库访问计数和计时。
首先,让我们访问数据库并获取一个db对象
>>> import pymongo >>> conn = pymongo.Connection('localhost', 27017, tz_aware=False) >>> db = conn[DBNAME]
我们的示例集合与城市生活、交通和人群相关
>>> traffic = db.cars >>> crowd = db.people
让我们创建一个表示已在集合中的某物的车辆
>>> obj = traffic.insert({'car': 'red'})
现在创建一个监视器跟踪所选数据库上由操作创建的mongo配置文件条目
>>> from mongowatch.mongo import watcher >>> wa = watcher.Watcher(conn,[DBNAME])
现在,让我们向交通中添加一个项目
>>> obj = traffic.insert({'truck':'blue'})
然后我们向人群中添加两个人
>>> obj = crowd.insert({'name':'billy'}) >>> obj = crowd.insert({'name':'jane'})
这导致了以下操作被记录在监视器中。
>>> wa.dump() total ops: inserts: 3 summary: database: mongowatch_test cars inserts: 1 people inserts: 2 details: ns mongowatch_test.cars op insert ts 2011-12-13 08:27:05.496000 millis ... <BLANKLINE> ns mongowatch_test.people op insert ts 2011-12-13 08:27:05.498000 millis ... <BLANKLINE> ns mongowatch_test.people op insert ts 2011-12-13 08:27:05.498000 millis ... <BLANKLINE>
让我们重置计数器
>>> wa.reset()
所以现在做更多的工作
>>> crowd.remove({}) >>> traffic.remove({}) >>> obj = crowd.insert({'name':'bonzo'})
- 这次我们显式地停止监视器
>>> wa.stop() >>> wa.dump() total ops: inserts: 1 removes: 2 summary: database: mongowatch_test cars removes: 1 people inserts: 1 removes: 1 details: ns mongowatch_test.people op remove query {} ts 2011-12-13 07:47:51.921000 millis 0 <BLANKLINE> ns mongowatch_test.cars op remove query {} ts 2011-12-13 07:47:51.921000 millis 0 <BLANKLINE> ns mongowatch_test.people op insert ts 2011-12-13 07:47:51.921000 millis 0 <BLANKLINE>
>>> conn.disconnect()
项目详情
关闭
mongowatch-0.1.2dev.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5bdafd04cf9b618910ce255c89d1f71547bcb2c56fe88979e864c7164c179000 |
|
MD5 | 92e956f51ead2f2a38d76643013bb382 |
|
BLAKE2b-256 | ef1741c2a65b4b8e61e813408430b6eb1c943211835012a934959721c2380cbb |