cleanup/example output
This commit is contained in:
parent
c55fe89e55
commit
0236cf0730
14
README.rst
14
README.rst
@ -3,6 +3,20 @@ mongowatch
|
|||||||
|
|
||||||
Log watcher for `MongoDB <http://mongodb.org>`_.
|
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)
|
BSD-licensed. (see LICENSE)
|
||||||
|
|
||||||
Copyright 2012 Sunlight Foundation, James Turk
|
Copyright 2012 Sunlight Foundation, James Turk
|
||||||
|
BIN
example.png
Normal file
BIN
example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 KiB |
17
mongoprof.py
17
mongoprof.py
@ -16,6 +16,8 @@ quit = False
|
|||||||
def watch(host, dbname, refresh, slowms=0):
|
def watch(host, dbname, refresh, slowms=0):
|
||||||
global quit
|
global quit
|
||||||
db = getattr(Connection(host), dbname)
|
db = getattr(Connection(host), dbname)
|
||||||
|
# 1 - slow operations
|
||||||
|
# 2 - all operations
|
||||||
db.set_profiling_level(1 if slowms else 2, slowms or 100)
|
db.set_profiling_level(1 if slowms else 2, slowms or 100)
|
||||||
last_ts = datetime.datetime.utcnow()
|
last_ts = datetime.datetime.utcnow()
|
||||||
exclude_name = '{0}.system.profile'.format(dbname)
|
exclude_name = '{0}.system.profile'.format(dbname)
|
||||||
@ -29,8 +31,7 @@ def watch(host, dbname, refresh, slowms=0):
|
|||||||
signal.signal(signal.SIGINT, ctrl_c)
|
signal.signal(signal.SIGINT, ctrl_c)
|
||||||
|
|
||||||
while not quit:
|
while not quit:
|
||||||
for e in db.system.profile.find({'ns': {'$ne': exclude_name},
|
for e in db.system.profile.find({'ns': {'$ne': exclude_name}, 'ts': {'$gt': last_ts}}):
|
||||||
'ts': {'$gt': last_ts}}):
|
|
||||||
output = []
|
output = []
|
||||||
output.append(colored('{ts:%H:%M:%S}'.format(**e), 'white'))
|
output.append(colored('{ts:%H:%M:%S}'.format(**e), 'white'))
|
||||||
|
|
||||||
@ -44,23 +45,19 @@ def watch(host, dbname, refresh, slowms=0):
|
|||||||
elif op == 'update':
|
elif op == 'update':
|
||||||
output.append(colored('update {query}'.format(**e), 'green'))
|
output.append(colored('update {query}'.format(**e), 'green'))
|
||||||
elif op == 'getmore':
|
elif op == 'getmore':
|
||||||
output.append(colored('getmore {0}'.format(e.get('query', '')),
|
output.append(colored('getmore {0}'.format(e.get('query', '')), 'grey'))
|
||||||
'grey'))
|
|
||||||
elif op == 'command':
|
elif op == 'command':
|
||||||
output.append(colored('{command}'.format(**e), 'cyan'))
|
output.append(colored('{command}'.format(**e), 'cyan'))
|
||||||
else:
|
else:
|
||||||
output.append(colored('unknown operation: {0}'.format(op),
|
output.append(colored('unknown operation: {0}'.format(op), 'red'))
|
||||||
'red'))
|
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
if 'nscanned' in e:
|
if 'nscanned' in e:
|
||||||
output.append(colored('scanned {nscanned}'.format(**e),
|
output.append(colored('scanned {nscanned}'.format(**e), 'yellow'))
|
||||||
'yellow'))
|
|
||||||
if 'ntoskip' in e:
|
if 'ntoskip' in e:
|
||||||
output.append(colored('skip {ntoskip}'.format(**e), 'blue'))
|
output.append(colored('skip {ntoskip}'.format(**e), 'blue'))
|
||||||
if 'nreturned' in e:
|
if 'nreturned' in e:
|
||||||
output.append(colored('returned {nreturned}'.format(**e),
|
output.append(colored('returned {nreturned}'.format(**e), 'green'))
|
||||||
'green'))
|
|
||||||
if e.get('scanAndOrder'):
|
if e.get('scanAndOrder'):
|
||||||
output.append(colored('scanAndOrder', 'red'))
|
output.append(colored('scanAndOrder', 'red'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user