uwsgi-sloth
===========

uwsgi-sloth is a small tool for analyzing uwsgi log files, it can generates a 
well-looking report showing the slowest requests in your website.

It's a great tool when optimizing your uwsgi web apps.

Preview
-------

This `html <http://www.zlovezl.cn/static/uwsgi-sloth-report-example.html>`_ 
is generated by uwsgi-sloth:

.. image:: https://github.com/piglei/uwsgi-sloth/raw/master/uwsgi-sloth-screenshot.png


Install
-------

To install uwsgi-sloth, simply use pip:

.. code-block:: bash

    # Install a stable version
    $ pip install uwsgi-sloth

    # Install from github
    $ pip install -e git+https://github.com/piglei/uwsgi-sloth#egg=uwsgi-sloth


Tutorial
--------

.. code-block:: bash

    # Generate a report
    $ uwsgi-sloth analyze -f uwsgi_access.log --output=report.html

    # Specify threshold for request process time
    $ uwsgi-sloth analyze -f uwsgi_access.log --output=report.html --min-msecs=400

Using a customized url rules
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

First, get a list of url regular expressions.

::

    $ cat url_rules
    # A valid url_rules file are seperated regular expressions
    ^club/(?P<place>\w+)/(?P<year>\d+)/(?P<issue>\d+)/signup/$
    ^club/signup/success/$
    ^club/checkin/success/$

Using `--url-file` to specify this url_rules

::

    $ uwsgi-sloth analyze -f uwsgi_access.log --output=report.html --url-file=url_rules


uwsgi-sloth analyze
-------------------

Available arguments
~~~~~~~~~~~~~~~~~~~

::

    usage: uwsgi-sloth analyze [-h] -f FILEPATH [--output OUTPUT]
                               [--min-msecs MIN_MSECS] [--domain DOMAIN]
                               [--url-file URL_FILE]

    optional arguments:
      -h, --help            show this help message and exit
      -f FILEPATH, --filepath FILEPATH
                            Path of uwsgi log file
      --output OUTPUT       HTML report file path
      --min-msecs MIN_MSECS
                            Request serve time lower than this value will not be
                            counted, default: 200
      --domain DOMAIN       Make url in report become a hyper-link by settings a
                            domain
      --url-file URL_FILE   Customized url rules in regular expression

Notes
-----

- Only default uwsgi log format is supported at present.
- By default, uwsgi-sloth will classify ``url_path`` by replacing sequential
  digits part by '(\d+)': ``/users/3074/`` -> ``/users/(\d+)``


Any feedbacks are greatly welcomed!

