Skip to content

Commit

Permalink
Fix rueckstiess#698: Add rounding option for mloginfo --queries
Browse files Browse the repository at this point in the history
  • Loading branch information
stennie committed Dec 28, 2019
1 parent 8d3e48c commit b58303b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
39 changes: 35 additions & 4 deletions doc/mloginfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ Usage

.. code-block:: bash
mloginfo [-h] [--version] logfile
[--verbose]
[--queries] [--restarts] [--distinct] [--connections] [--rsstate]
mloginfo [-h] logfile
[--clients]
[--connections]
[--cursors]
[--distinct]
[--queries]
[--rounding {0,1,2,3,4}]
[--sort {namespace,pattern,count,min,max,mean,95%,sum}]
[--restarts]
[--rsstate]
[--storagestats]
[--transactions] [--tsort {duration}]
[--transactions]
[--tsort {duration}]
[--verbose]
[--version]
General Parameters
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -130,6 +138,24 @@ In addition to the default information, this command will also output the
serverside.auth_sessions update {"session_endtime": 1, "session_userid": 1} 1 244 244 244 0.2 244 False
serverside.game_level find {"_id": 1} 1 104 104 104 0.1 104 None
``--rounding``
^^^^^^^^^^^^^^

This option adjusts the rounding for calculated statistics like mean and
95%-ile.

For example:

.. code-block:: bash
mloginfo mongod.log --queries --rounding 2
This option has no effect unless ``--queries`` is also specified.

Valid rounding values are from 0 to 4 decimal places. The default value is 1.


``--sort``
^^^^^^^^^^

Expand All @@ -143,6 +169,11 @@ example:
This option has no effect unless ``--queries`` is also specified.

Valid sort options are: ``namespace``, ``pattern``, ``count``, ``min``,
``max``, ``mean``, ``95%``, and ``sum``.

The default sort option is ``sum``.

Restarts (``--restarts``)
-------------------------

Expand Down
13 changes: 10 additions & 3 deletions mtools/mloginfo/sections/query_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ def __init__(self, mloginfo):
'mean',
'95%',
'sum'])

helptext = 'Number of decimal places for rounding of calculated stats'
self.mloginfo.argparser_sectiongroup.add_argument('--rounding',
action='store',
type=int,
default=1,
choices=range(0,5),
help=helptext)
@property
def active(self):
"""Return boolean if this section is active."""
Expand All @@ -54,6 +60,7 @@ def run(self):
grouping = Grouping(group_by=lambda x: (x.namespace, x.operation,
x.pattern, x.allowDiskUse))
logfile = self.mloginfo.logfile
rounding = self.mloginfo.args['rounding']

if logfile.start and logfile.end:
progress_start = self.mloginfo._datetime_to_epoch(logfile.start)
Expand Down Expand Up @@ -115,12 +122,12 @@ def run(self):
stats['max'] = max(group_events) if group_events else 0
stats['mean'] = 0
if np:
stats['95%'] = (np.percentile(group_events, 95)
stats['95%'] = (round(np.percentile(group_events, 95), rounding)
if group_events else 0)
else:
stats['95%'] = 'n/a'
stats['sum'] = sum(group_events) if group_events else 0
stats['mean'] = (stats['sum'] / stats['count']
stats['mean'] = (round(stats['sum'] / stats['count'], rounding)
if group_events else 0)

if self.mloginfo.args['verbose']:
Expand Down

0 comments on commit b58303b

Please sign in to comment.