Code Monkey home page Code Monkey logo

mongomon's Introduction

mongomon

A Python mongodb monitor and profiler for development.

Quick Start

Install using pip/pipenv/etc. (we recommend poetry for sane dependency management):

$ poetry add mongomon --dev

Initialize before you set up your MongoDB connection:

from mongomon import Monitor, Config
Monitor(Config(file_capture=".*/(wiki.*)")).monitor()

Actually, use an environment flag to guard against activating mongomon in production (unless this is something you want):

from mongomon import Monitor, Config
import os

if os.getenv("MGMON"):
    Monitor(Config(file_capture=".*/(wiki.*)", low_watermark_us=0)).monitor()

Use file_capture to specify how to extract relevant project file paths from traces, rather than absolute file paths.

Exploring the Example

We've taken the example from Flask-PyMongo to show how easy it is to have mongomon integrated and running.

You can look at the integration here. To run it:

$ poetry shell
$ cd examples/wiki && pip install -r requirements
$ python wiki.py

Configuration

Your main configuration points for mongomon are:

  • file_capture - an aesthetic configuration point for capturing files for your project. Usually of the form .*/(your-project.*), content in parenthesis are a regular expression capture group, and is what we actually extract.
  • low_watermark_us - a threshold in microseconds (us) above which mongomon starts working (yellow).
  • high_watermark_us - a high threshold in microseconds (us) above which mongomon displays timing as alert (red).

Rest of configuration looks like so (with their defaults and comments):

    # cleans up stack trace with uninteresting things. Usually packages, standard library, etc.
    ignores = attrib(
        default=[
            ".*/site-packages/.*",
            ".*traceback.format_stack.*",
            r".*/lib/python\d\.\d+/.*",
        ]
    )
    # shows a file, cleans up absolute path to a file
    file_capture = attrib(default="(.*)")
    # above this value mongomon starts working
    low_watermark_us = attrib(default=5000)
    # above this value mongomon flags as alert
    high_watermark_us = attrib(default=40000)
    # customize how mongodb query looks like before printing to screen
    query_filter = attrib(default=identity)
    # want to print to something else? replace this
    print_fn = attrib(default=print_)
    # want shorter stack traces? customize this
    stack_preprocess = attrib(default=trim_last)

Thanks:

To all Contributors - you make this happen, thanks!

Copyright

Copyright (c) 2019 @jondot. See LICENSE for further details.

mongomon's People

Contributors

jondot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.