mongotail


Namemongotail JSON
Version 3.1.1 PyPI version JSON
download
home_pagehttps://github.com/mrsarm/mongotail
SummaryMongotail, Log all MongoDB queries in a "tail"able way.
upload_time2023-04-17 22:50:19
maintainer
docs_urlNone
authorMariano Ruiz
requires_python
licenseGPL-3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Mongotail
=========

Mongotail, Log all `MongoDB <http://www.mongodb.org>`_ queries in a *"tail"able* way.

``mongotail`` is a command line tool to outputs any operation from a Mongo
database in the standard output. You can see the operations collected by the
database profiler from a console, or redirect the result to a file, pipes
it with ``grep`` or other command line tool, etc.

The syntax is very similar to ``mongo`` client, and the output, as like
``tail`` command will be the latest 10 lines of logging.

But the more interesting feature (also like ``tail``) is to see the changes
in *"real time"* with the ``-f`` option, and occasionally filter the result
with ``grep`` to find a particular operation.

MongoDB version 2.8 and above are supported.

Syntax
------

Usage::

    mongotail [db address] [options]

"db address" can be:

+------------------------------+-----------------------------------------------------------------+
| foo                          | foo database on local machine (IPv4 connection)                 |
+------------------------------+-----------------------------------------------------------------+
| :1234/foo                    | foo database on local machine on port 1234                      |
+------------------------------+-----------------------------------------------------------------+
| 192.169.0.5/foo              | foo database on 192.168.0.5 machine                             |
+------------------------------+-----------------------------------------------------------------+
| remotehost/foo               | foo database on *remotehost* machine                            |
+------------------------------+-----------------------------------------------------------------+
| user:pass@host/foo           | foo database on *host* machine, with user and pass provided     |
+------------------------------+-----------------------------------------------------------------+
| 192.169.0.5:9999/foo         | foo database on 192.168.0.5 machine on port 9999                |
+------------------------------+-----------------------------------------------------------------+
| "[::1]:9999/foo"             | foo database on ::1 machine on port 9999 (IPv6 connection)      |
+------------------------------+-----------------------------------------------------------------+
| mongodb://10.0.0.4:9999/foo  | foo resource on 10.0.0.4 machine on port 9999, scheme mongodb   |
+------------------------------+-----------------------------------------------------------------+
| mongodb+srv://user@host/foo  | foo resource on *host* machine, scheme mongodb+srv and username |
+------------------------------+-----------------------------------------------------------------+

*New in 3.1*: URIs with schemas ``mongodb://`` and ``mongodb+srv://`` are supported,
e.g. ``mongodb://host:1234/foo``, and user and password can also be set in the URI,
although it's a very insecure way of provide that information. See bellow
how to provide authentication information like user, password, auth database, ...

**Optional arguments**:

-u USERNAME, --username USERNAME
                      username for authentication
-p PASSWORD, --password PASSWORD
                      password for authentication. If username is given and
                      password isn't, it's asked from tty
-b AUTH_DATABASE, --authenticationDatabase AUTH_DATABASE
                      database to use to authenticate the user. If not
                      specified, the user will be authenticated against the
                      database specified in the [db address]
-n N, --lines N       output the last N lines, instead of the last 10. Use
                      ALL value to show all lines
-f, --follow          output appended data as the log grows
-l LEVEL, --level LEVEL
                      specifies the profiling level, which is either 0 for
                      no profiling, 1 for only slow operations, or 2 for all
                      operations. Or use with 'status' word to show the
                      current level configured. Uses this option once before
                      logging the database
-s MS, --slowms MS    sets the threshold in milliseconds for the profile to
                      consider a query or operation to be slow (use with
                      `--level 1`). Or use with 'status' word to show the
                      current milliseconds configured
-m METADATA, --metadata METADATA
                      extra metadata fields to show. Known fields may vary
                      depending of the operation and the MongoDB version:
                      millis, nscanned, docsExamined, execStats, lockStats ...
                      (pass each METADATA field separated by one space)
-i, --info            get information about the MongoDB server we're connected to
-v, --verbose         verbose mode (not recommended). All the operations will
                      printed in JSON without format and with all the
                      information available from the log
--tls                 creates the connection to the server using
                      transport layer security
--tlsCertificateKeyFile TLSCERTIFICATEKEYFILE
                      client certificate to connect against MongoDB.
                      It's the concatenation of both the private key and and
                      the certificate file
--tlsAllowInvalidCertificates
                      disable the requirement of a certificate from the
                      server when TLS is enabled
--tlsCAFile TLSCAFILE
                      file that contains a set of concatenated CA certificates,
                      which are used to validate certificates passed
                      from the other end of the connection
--tlsCertificateKeyFilePassword TLSCERTIFICATEKEYFILEPASSWORD
                      password or passphrase to decrypt the encrypted private
                      keys if the private key contained in the
                      certificate keyfile is encrypted.
--tlsCRLFile TLSCRLFILE
                      path to a PEM or DER formatted certificate revocation list
-h, --help            show this help message and exit
-V, --version         show program's version number and exit


Enabling Database Profiling and Showing Logs
--------------------------------------------

First you have to activate in the current database the
`profiler <http://docs.mongodb.org/manual/reference/method/db.setProfilingLevel>`_,
so MongoDB will capture all the activity in a special collection that is read by Mongotail.

You can achieve this with the ``-l, --level`` option. For example, if you want to see the logs
from MYDATABASE, first you have to execute::

    $ mongotail MYDATABASE -l 2

Then you can see the latest logged records with::

    $ mongotail MYDATABASE
    2015-02-24 19:17:01.194 QUERY  [Company] : {"_id": ObjectId("548b164144ae122dc430376b")}. 1 returned.
    2015-02-24 19:17:01.195 QUERY  [User] : {"_id": ObjectId("549048806b5d3db78cf6f654")}. 1 returned.
    2015-02-24 19:17:01.196 UPDATE [Activation] : {"_id": "AB524"}, {"_id": "AB524", "code": "f2cbad0c"}. 1 updated.
    2015-02-24 19:17:10.729 COUNT  [User] : {"active": {"$exists": true}, "firstName": {"$regex": "mac"}}
    ...

To Connect with SSL or a remote Mongo instance, check the options with ``mongotail --help``.

Profiling considerations
^^^^^^^^^^^^^^^^^^^^^^^^

**NOTE**: The level chosen can affect performance. It also can allow the
server to write the content of queries to the log, which might have
information security implications for your deployment. Remember to setup your
database profiling level to ``0`` again after debugging your data::

    $ mongotail MYDATABASE -l 0


Find slow queries
^^^^^^^^^^^^^^^^^

When you activate the profiler, you can choose to so with level 1 profiling
instead of level 2. Level 1 configure the profiler system to log only "slow" operations.
Then you have to set the threshold in milliseconds for the profile to consider an
operation "slow". In the following example the threshold is set to 10 milliseconds::

    $ mongotail sales -l 1
    Profiling set to level 1
    $ mongotail sales -s 10
    Threshold profiling set to 10 milliseconds

Then when you check your databases only operations that take 10 or more milliseconds
will be displayed.

A *step-by-step* guide of how to use Mongotail and the latest features
is `here <http://mrsarm.blogspot.com.ar/2016/08/mongotail-2-0-with-new-features-mongodb-3-2-support.html>`_.


Installation
------------

See `INSTALL.rst <https://github.com/mrsarm/mongotail/blob/master/INSTALL.rst>`_
guide to install from sources. To install
from `PyPI repositories <https://pypi.org/project/mongotail/>`_,
follow these instructions depending of your OS:


Linux Installation
^^^^^^^^^^^^^^^^^^

You can install the latest stable version with ``pip`` in your
environment, but it's recommended to install it with
Python 3 (``pip3``)::

    $ pip3 install mongotail

Execute this command with administrator/root privileges (in
Debian/Ubuntu Linux distribution prepend ``sudo`` to the command).

You have to be installed ``pip`` / ``pip3`` tool first. In Debian/Ubuntu Linux
distribution you can install it with (also with root privileges)::

    $ apt-get install python3-pip

Install mongotail in the user space without root privileges is also
possible with::

    $ pip3 install --user mongotail

Note that the ``mongotail`` executable will be installed in the ``$HOME/.local/bin``
folder. If the folder didn't exist before, Pip will create it, but in the
shell console the path won't be added to the ``$PATH`` variable until Bash is not
instantiated again, so to be able to execute the command without the need to use
the full path (``$HOME/.local/bin/mongotail``) just open a new Bash session.


Mac OSX Installation
^^^^^^^^^^^^^^^^^^^^

First you need to install the Python package manager ``pip`` in
your environment, and then like Linux to install Mongotail you
can execute ``sudo pip install mongotail`` from the command line,
but also it can be installed with ``easy_install``, an
old Python package manager present in most OSX versions. Try this::

    $ sudo easy_install mongotail


Docker
^^^^^^

Run with Docker (you don't need to download the source code)::

    $ docker run -it --rm mrsarm/mongotail --help

If you want to connect with a database also running locally in a
container, you have to link both instances (see howto in the Docker
documentation), or if the db is a local instance running without
Docker, remember to use the local IP of your computer because the
``localhost`` address (IP 127.0.0.1) points to the container, not to
your host. Eg.::

    $ docker run -it --rm mrsarm/mongotail 192.168.0.21/test

If it does not work, it may be related with network access rules,
or because the mongo instance is not listening remote connections,
check to have properly configured the
`IP Binding <https://docs.mongodb.com/manual/core/security-mongodb-configuration/>`_.

About
-----

Project: https://github.com/mrsarm/mongotail

Authors: (2015-2022) Mariano Ruiz <mrsarm@g...l.com>

Changelog: `CHANGELOG.rst <https://github.com/mrsarm/mongotail/blob/master/CHANGELOG.rst>`_

More guides: http://mrsarm.blogspot.com.ar/search/label/Mongotail

License: GPL-3



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mrsarm/mongotail",
    "name": "mongotail",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mariano Ruiz",
    "author_email": "mrsarm@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5f/ae/ca8d426ca97f418d08c9b1a53617243e683eb897f5831a647f6a6ecb31e7/mongotail-3.1.1.tar.gz",
    "platform": "any",
    "description": "Mongotail\n=========\n\nMongotail, Log all `MongoDB <http://www.mongodb.org>`_ queries in a *\"tail\"able* way.\n\n``mongotail`` is a command line tool to outputs any operation from a Mongo\ndatabase in the standard output. You can see the operations collected by the\ndatabase profiler from a console, or redirect the result to a file, pipes\nit with ``grep`` or other command line tool, etc.\n\nThe syntax is very similar to ``mongo`` client, and the output, as like\n``tail`` command will be the latest 10 lines of logging.\n\nBut the more interesting feature (also like ``tail``) is to see the changes\nin *\"real time\"* with the ``-f`` option, and occasionally filter the result\nwith ``grep`` to find a particular operation.\n\nMongoDB version 2.8 and above are supported.\n\nSyntax\n------\n\nUsage::\n\n    mongotail [db address] [options]\n\n\"db address\" can be:\n\n+------------------------------+-----------------------------------------------------------------+\n| foo                          | foo database on local machine (IPv4 connection)                 |\n+------------------------------+-----------------------------------------------------------------+\n| :1234/foo                    | foo database on local machine on port 1234                      |\n+------------------------------+-----------------------------------------------------------------+\n| 192.169.0.5/foo              | foo database on 192.168.0.5 machine                             |\n+------------------------------+-----------------------------------------------------------------+\n| remotehost/foo               | foo database on *remotehost* machine                            |\n+------------------------------+-----------------------------------------------------------------+\n| user:pass@host/foo           | foo database on *host* machine, with user and pass provided     |\n+------------------------------+-----------------------------------------------------------------+\n| 192.169.0.5:9999/foo         | foo database on 192.168.0.5 machine on port 9999                |\n+------------------------------+-----------------------------------------------------------------+\n| \"[::1]:9999/foo\"             | foo database on ::1 machine on port 9999 (IPv6 connection)      |\n+------------------------------+-----------------------------------------------------------------+\n| mongodb://10.0.0.4:9999/foo  | foo resource on 10.0.0.4 machine on port 9999, scheme mongodb   |\n+------------------------------+-----------------------------------------------------------------+\n| mongodb+srv://user@host/foo  | foo resource on *host* machine, scheme mongodb+srv and username |\n+------------------------------+-----------------------------------------------------------------+\n\n*New in 3.1*: URIs with schemas ``mongodb://`` and ``mongodb+srv://`` are supported,\ne.g. ``mongodb://host:1234/foo``, and user and password can also be set in the URI,\nalthough it's a very insecure way of provide that information. See bellow\nhow to provide authentication information like user, password, auth database, ...\n\n**Optional arguments**:\n\n-u USERNAME, --username USERNAME\n                      username for authentication\n-p PASSWORD, --password PASSWORD\n                      password for authentication. If username is given and\n                      password isn't, it's asked from tty\n-b AUTH_DATABASE, --authenticationDatabase AUTH_DATABASE\n                      database to use to authenticate the user. If not\n                      specified, the user will be authenticated against the\n                      database specified in the [db address]\n-n N, --lines N       output the last N lines, instead of the last 10. Use\n                      ALL value to show all lines\n-f, --follow          output appended data as the log grows\n-l LEVEL, --level LEVEL\n                      specifies the profiling level, which is either 0 for\n                      no profiling, 1 for only slow operations, or 2 for all\n                      operations. Or use with 'status' word to show the\n                      current level configured. Uses this option once before\n                      logging the database\n-s MS, --slowms MS    sets the threshold in milliseconds for the profile to\n                      consider a query or operation to be slow (use with\n                      `--level 1`). Or use with 'status' word to show the\n                      current milliseconds configured\n-m METADATA, --metadata METADATA\n                      extra metadata fields to show. Known fields may vary\n                      depending of the operation and the MongoDB version:\n                      millis, nscanned, docsExamined, execStats, lockStats ...\n                      (pass each METADATA field separated by one space)\n-i, --info            get information about the MongoDB server we're connected to\n-v, --verbose         verbose mode (not recommended). All the operations will\n                      printed in JSON without format and with all the\n                      information available from the log\n--tls                 creates the connection to the server using\n                      transport layer security\n--tlsCertificateKeyFile TLSCERTIFICATEKEYFILE\n                      client certificate to connect against MongoDB.\n                      It's the concatenation of both the private key and and\n                      the certificate file\n--tlsAllowInvalidCertificates\n                      disable the requirement of a certificate from the\n                      server when TLS is enabled\n--tlsCAFile TLSCAFILE\n                      file that contains a set of concatenated CA certificates,\n                      which are used to validate certificates passed\n                      from the other end of the connection\n--tlsCertificateKeyFilePassword TLSCERTIFICATEKEYFILEPASSWORD\n                      password or passphrase to decrypt the encrypted private\n                      keys if the private key contained in the\n                      certificate keyfile is encrypted.\n--tlsCRLFile TLSCRLFILE\n                      path to a PEM or DER formatted certificate revocation list\n-h, --help            show this help message and exit\n-V, --version         show program's version number and exit\n\n\nEnabling Database Profiling and Showing Logs\n--------------------------------------------\n\nFirst you have to activate in the current database the\n`profiler <http://docs.mongodb.org/manual/reference/method/db.setProfilingLevel>`_,\nso MongoDB will capture all the activity in a special collection that is read by Mongotail.\n\nYou can achieve this with the ``-l, --level`` option. For example, if you want to see the logs\nfrom MYDATABASE, first you have to execute::\n\n    $ mongotail MYDATABASE -l 2\n\nThen you can see the latest logged records with::\n\n    $ mongotail MYDATABASE\n    2015-02-24 19:17:01.194 QUERY  [Company] : {\"_id\": ObjectId(\"548b164144ae122dc430376b\")}. 1 returned.\n    2015-02-24 19:17:01.195 QUERY  [User] : {\"_id\": ObjectId(\"549048806b5d3db78cf6f654\")}. 1 returned.\n    2015-02-24 19:17:01.196 UPDATE [Activation] : {\"_id\": \"AB524\"}, {\"_id\": \"AB524\", \"code\": \"f2cbad0c\"}. 1 updated.\n    2015-02-24 19:17:10.729 COUNT  [User] : {\"active\": {\"$exists\": true}, \"firstName\": {\"$regex\": \"mac\"}}\n    ...\n\nTo Connect with SSL or a remote Mongo instance, check the options with ``mongotail --help``.\n\nProfiling considerations\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n**NOTE**: The level chosen can affect performance. It also can allow the\nserver to write the content of queries to the log, which might have\ninformation security implications for your deployment. Remember to setup your\ndatabase profiling level to ``0`` again after debugging your data::\n\n    $ mongotail MYDATABASE -l 0\n\n\nFind slow queries\n^^^^^^^^^^^^^^^^^\n\nWhen you activate the profiler, you can choose to so with level 1 profiling\ninstead of level 2. Level 1 configure the profiler system to log only \"slow\" operations.\nThen you have to set the threshold in milliseconds for the profile to consider an\noperation \"slow\". In the following example the threshold is set to 10 milliseconds::\n\n    $ mongotail sales -l 1\n    Profiling set to level 1\n    $ mongotail sales -s 10\n    Threshold profiling set to 10 milliseconds\n\nThen when you check your databases only operations that take 10 or more milliseconds\nwill be displayed.\n\nA *step-by-step* guide of how to use Mongotail and the latest features\nis `here <http://mrsarm.blogspot.com.ar/2016/08/mongotail-2-0-with-new-features-mongodb-3-2-support.html>`_.\n\n\nInstallation\n------------\n\nSee `INSTALL.rst <https://github.com/mrsarm/mongotail/blob/master/INSTALL.rst>`_\nguide to install from sources. To install\nfrom `PyPI repositories <https://pypi.org/project/mongotail/>`_,\nfollow these instructions depending of your OS:\n\n\nLinux Installation\n^^^^^^^^^^^^^^^^^^\n\nYou can install the latest stable version with ``pip`` in your\nenvironment, but it's recommended to install it with\nPython 3 (``pip3``)::\n\n    $ pip3 install mongotail\n\nExecute this command with administrator/root privileges (in\nDebian/Ubuntu Linux distribution prepend ``sudo`` to the command).\n\nYou have to be installed ``pip`` / ``pip3`` tool first. In Debian/Ubuntu Linux\ndistribution you can install it with (also with root privileges)::\n\n    $ apt-get install python3-pip\n\nInstall mongotail in the user space without root privileges is also\npossible with::\n\n    $ pip3 install --user mongotail\n\nNote that the ``mongotail`` executable will be installed in the ``$HOME/.local/bin``\nfolder. If the folder didn't exist before, Pip will create it, but in the\nshell console the path won't be added to the ``$PATH`` variable until Bash is not\ninstantiated again, so to be able to execute the command without the need to use\nthe full path (``$HOME/.local/bin/mongotail``) just open a new Bash session.\n\n\nMac OSX Installation\n^^^^^^^^^^^^^^^^^^^^\n\nFirst you need to install the Python package manager ``pip`` in\nyour environment, and then like Linux to install Mongotail you\ncan execute ``sudo pip install mongotail`` from the command line,\nbut also it can be installed with ``easy_install``, an\nold Python package manager present in most OSX versions. Try this::\n\n    $ sudo easy_install mongotail\n\n\nDocker\n^^^^^^\n\nRun with Docker (you don't need to download the source code)::\n\n    $ docker run -it --rm mrsarm/mongotail --help\n\nIf you want to connect with a database also running locally in a\ncontainer, you have to link both instances (see howto in the Docker\ndocumentation), or if the db is a local instance running without\nDocker, remember to use the local IP of your computer because the\n``localhost`` address (IP 127.0.0.1) points to the container, not to\nyour host. Eg.::\n\n    $ docker run -it --rm mrsarm/mongotail 192.168.0.21/test\n\nIf it does not work, it may be related with network access rules,\nor because the mongo instance is not listening remote connections,\ncheck to have properly configured the\n`IP Binding <https://docs.mongodb.com/manual/core/security-mongodb-configuration/>`_.\n\nAbout\n-----\n\nProject: https://github.com/mrsarm/mongotail\n\nAuthors: (2015-2022) Mariano Ruiz <mrsarm@g...l.com>\n\nChangelog: `CHANGELOG.rst <https://github.com/mrsarm/mongotail/blob/master/CHANGELOG.rst>`_\n\nMore guides: http://mrsarm.blogspot.com.ar/search/label/Mongotail\n\nLicense: GPL-3\n\n\n",
    "bugtrack_url": null,
    "license": "GPL-3",
    "summary": "Mongotail, Log all MongoDB queries in a \"tail\"able way.",
    "version": "3.1.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b6d4e978124b43d0485e0130583728b5f35ac52c1224a2b80f463bc0c16b349b",
                "md5": "7f72b6a28b293f0e1506af6e7c6704ad",
                "sha256": "37386ecd2a4799913ec05a529a72e52f2ad83219c6ebba429f2abdc06aebb2c5"
            },
            "downloads": -1,
            "filename": "mongotail-3.1.1-py2-none-any.whl",
            "has_sig": false,
            "md5_digest": "7f72b6a28b293f0e1506af6e7c6704ad",
            "packagetype": "bdist_wheel",
            "python_version": "py2",
            "requires_python": null,
            "size": 29796,
            "upload_time": "2023-04-17T22:50:15",
            "upload_time_iso_8601": "2023-04-17T22:50:15.218264Z",
            "url": "https://files.pythonhosted.org/packages/b6/d4/e978124b43d0485e0130583728b5f35ac52c1224a2b80f463bc0c16b349b/mongotail-3.1.1-py2-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a650c844f3b5259f2e069edf467e49461f972b2f044cfc097658ad2e4459f62",
                "md5": "2bcbb79eaa300aa92251398989cfa829",
                "sha256": "93a57214e5a17ac8e58e4d2ba8c00611b6cd4405cf0b3a856a4ae254f6f23832"
            },
            "downloads": -1,
            "filename": "mongotail-3.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2bcbb79eaa300aa92251398989cfa829",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 29820,
            "upload_time": "2023-04-17T22:50:17",
            "upload_time_iso_8601": "2023-04-17T22:50:17.119408Z",
            "url": "https://files.pythonhosted.org/packages/5a/65/0c844f3b5259f2e069edf467e49461f972b2f044cfc097658ad2e4459f62/mongotail-3.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5faeca8d426ca97f418d08c9b1a53617243e683eb897f5831a647f6a6ecb31e7",
                "md5": "a4c2eaea0a1a7a26a9841474ee66e04f",
                "sha256": "6720441da33c345bedc93a1d39128947412e47a846b763d6f038ed0f03c02949"
            },
            "downloads": -1,
            "filename": "mongotail-3.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "a4c2eaea0a1a7a26a9841474ee66e04f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 31852,
            "upload_time": "2023-04-17T22:50:19",
            "upload_time_iso_8601": "2023-04-17T22:50:19.066189Z",
            "url": "https://files.pythonhosted.org/packages/5f/ae/ca8d426ca97f418d08c9b1a53617243e683eb897f5831a647f6a6ecb31e7/mongotail-3.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-17 22:50:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mrsarm",
    "github_project": "mongotail",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mongotail"
}
        
Elapsed time: 0.05558s