cleanup/example output

This commit is contained in:
James Turk 2014-02-14 10:21:27 -05:00
parent c55fe89e55
commit 0236cf0730
3 changed files with 21 additions and 10 deletions

View File

@ -3,6 +3,20 @@ mongowatch
Log watcher for `MongoDB <http://mongodb.org>`_.
Usage
-----
./mongoprof [--host hostname] [--slowms ms] dbname
Monitors connections to DB ``dbname`` at ``hostname``.
--host is an optional parameter, defaults to localhost (recommended)
If slowms is included the log level will be set to only log queries slower than ``ms``
milliseconds.
BSD-licensed. (see LICENSE)
Copyright 2012 Sunlight Foundation, James Turk

BIN
example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -16,6 +16,8 @@ quit = False
def watch(host, dbname, refresh, slowms=0):
global quit
db = getattr(Connection(host), dbname)
# 1 - slow operations
# 2 - all operations
db.set_profiling_level(1 if slowms else 2, slowms or 100)
last_ts = datetime.datetime.utcnow()
exclude_name = '{0}.system.profile'.format(dbname)
@ -29,8 +31,7 @@ def watch(host, dbname, refresh, slowms=0):
signal.signal(signal.SIGINT, ctrl_c)
while not quit:
for e in db.system.profile.find({'ns': {'$ne': exclude_name},
'ts': {'$gt': last_ts}}):
for e in db.system.profile.find({'ns': {'$ne': exclude_name}, 'ts': {'$gt': last_ts}}):
output = []
output.append(colored('{ts:%H:%M:%S}'.format(**e), 'white'))
@ -44,23 +45,19 @@ def watch(host, dbname, refresh, slowms=0):
elif op == 'update':
output.append(colored('update {query}'.format(**e), 'green'))
elif op == 'getmore':
output.append(colored('getmore {0}'.format(e.get('query', '')),
'grey'))
output.append(colored('getmore {0}'.format(e.get('query', '')), 'grey'))
elif op == 'command':
output.append(colored('{command}'.format(**e), 'cyan'))
else:
output.append(colored('unknown operation: {0}'.format(op),
'red'))
output.append(colored('unknown operation: {0}'.format(op), 'red'))
print(e)
if 'nscanned' in e:
output.append(colored('scanned {nscanned}'.format(**e),
'yellow'))
output.append(colored('scanned {nscanned}'.format(**e), 'yellow'))
if 'ntoskip' in e:
output.append(colored('skip {ntoskip}'.format(**e), 'blue'))
if 'nreturned' in e:
output.append(colored('returned {nreturned}'.format(**e),
'green'))
output.append(colored('returned {nreturned}'.format(**e), 'green'))
if e.get('scanAndOrder'):
output.append(colored('scanAndOrder', 'red'))