Giter Club home page Giter Club logo

uwsgi-sloth's Introduction

uwsgi-sloth

uwsgi-sloth is a realtime uwsgi log analyer, designed for helping optimization of uwsgi app's performance.

It can both generates a static report file or analyze your log file in realtime.

Image preview:

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

You should consider using uwsgi-sloth if your website are running under uwsgi and have no conception of how slow/fast your website is.

QuickStart

Install

uwsgi-sloth is written in python, to install it, simply use pip:

# Install a stable version
$ pip install uwsgi-sloth

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

uwsgi-sloth now only supports Python3.5 and above, for Python2 users, please install uwsgi-sloth<3.0.0 instead.

Static report

After installation, you can analyzing your uwsgi log using uwsgi-sloth analyze command.

# 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

Check more: uwsgi-sloth analyze

Realtime reports

We do support a more powerful feature: realtime uwsgi log report. It's a little more complicated to configure.

First, create a default config file using uwsgi-sloth echo_conf:

uwsgi-sloth echo_conf > /data/uwsgi_sloth/myblog.conf

The default config file are like this:

# A sample uwsgi-sloth config file

# uwsgi log path, only support default log format
uwsgi_log_path = '/your_uwsgi_logs/web.log'

# All HTML files and data files will store here, must have read/write permissions
data_dir = '/you_data/uwsgi-sloth/'

# Minimal msecs for detect slow requests, default to 200
# min_msecs = 200

# Domain for your website, best given
domain = 'http://www.yourwebsite.com/'

# Custom url regular expressions file
# url_file = '/your_custom_url_file_path'

After modified uwsgi_log_path and data_dir, your can start uwsgi-sloth worker via uwsgi-sloth start -c /data/uwsgi_sloth/myblog.conf command, if everything goes fine, you will see some messages like this:

[2014-06-26 01:32:56,851] uwsgi_sloth INFO: Start from last savepoint, last_log_datetime: 2014-06-26 09:32:04
[2014-06-26 01:32:58,859] uwsgi_sloth INFO: Rendering HTML file /data/uwsgi_sloth/myblog/html/latest_5mins.html...
... ...

This may take several seconds if your log file are big.

Demonize

uwsgi-sloth does not support built-in deamonize option, so you may need tools like supervisor to manage this process.

Serve your reports

Now, HTML files have been generated, we should configure our webserver so we can visit it, this configuration is for nginx:

$ cat /etc/nginx/sites-enabled/sloth_myblog.conf
server {

    listen   80;
    server_name  uwsgi-sloth.zlovezl.cn;

    location / {
        root /data/uwsgi_sloth/myblog/html/;
        index "latest_5mins.html";
    }
}

After reloading your nginx config, open your browser then you will see the fancy reports waiting for you.

Commands

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
  --limit-url-groups LIMIT_URL_GROUPS
                        Number of url groups considered, default: 200
  --limit-per-url-group LIMIT_PER_URL_GROUP
                        Number of urls per group considered, default: 20

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 echo_conf

Print a default config file

uwsgi-sloth start

Start uwsgi-sloth worker to generate realtime report

$ uwsgi-sloth start -h
usage: uwsgi-sloth start [-h] -c CONFIG

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        uwsgi-sloth config file, use "uwsgi-sloth echo_conf"
                        for a default one

Notes

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

Any feedbacks are greatly welcomed!

uwsgi-sloth's People

Contributors

peterbe avatar piglei avatar xrmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uwsgi-sloth's Issues

In the reports, what is the detail section for?

My application serves 90% of the traffic on a specific URL. Hence, my log file is filled with below logline.

[pid: 25827|app: 0|req: 18/18] 162.158.158.173 () {62 vars in 1255 bytes} [Thu Jul 11 22:08:38 2019] POST /apis/shops/get_aff_url/ => generated 274 bytes in 23 msecs (HTTP/1.1 404) 5 headers in 152 bytes (1 switches on core 0)

However, in the reports, I don't see this URL under the detail section.

Below is the screenshot of Today period.

Screenshot 2019-07-11 at 10 15 41 PM

Issues

  1. I don't see /apis/shops/get_aff_url/ in the reports at all, even when it was hit 90% of the time.

  2. Total requests are 491, which is incorrect. I'd over 2000 hits on the above URL, and around 100 requests on the other URLs.

Kindly help in explaining the reports.

broken build

Traceback (most recent call last):
File "/usr/bin/uwsgi-sloth", line 7, in
execfile(file)
File "/home/ec2-user/src/uwsgi-sloth/uwsgi_sloth/uwsgi-sloth", line 10, in
from commands.analyze import load_subcommand
ImportError: No module named analyze

rolling back to version 0637fcb resolves the issue

TypeError: must be string without null bytes, not str

$ sudo uwsgi-sloth analyze -f /var/log/uwsgi-project.log.1 --output=report.html --min-msecs=1500
[2014-09-03 14:07:25,054] uwsgi_sloth.analyze INFO: Analyzing log file "/var/log/uwsgi-project.log.1"...
Traceback (most recent call last):
  File "/usr/home/user/.virtualenvs/default/bin/uwsgi-sloth", line 8, in <module>
    execfile(__file__)
  File "/usr/home/user/.virtualenvs/default/src/uwsgi-sloth/uwsgi_sloth/uwsgi-sloth", line 26, in <module>
    main()
  File "/usr/home/user/.virtualenvs/default/src/uwsgi-sloth/uwsgi_sloth/uwsgi-sloth", line 22, in main
    args.func(args)
  File "/usr/home/user/.virtualenvs/default/src/uwsgi-sloth/uwsgi_sloth/commands/analyze.py", line 32, in analyze
    data = analyze_log(args.filepath, args, url_rules)
  File "/usr/home/user/.virtualenvs/default/src/uwsgi-sloth/uwsgi_sloth/commands/analyze.py", line 20, in analyze_log
    analyzer.analyze_line(line)
  File "/usr/home/user/.virtualenvs/default/src/uwsgi-sloth/uwsgi_sloth/analyzer.py", line 97, in analyze_line
    result = self.log_parser.parse(line)
  File "/usr/home/user/.virtualenvs/default/src/uwsgi-sloth/uwsgi_sloth/analyzer.py", line 46, in parse
    self.DATETIME_FORMAT)
TypeError: must be string without null bytes, not str

python 3.5 issues

There is already #10, I couldn't re-open, so I filed a new ticket instead.

When running on python 3.5 I get errors

(v) harm@sensor1:~/uwsgi-sloth$ uwsgi-sloth start -c josene.conf 
[2019-02-28 10:53:29,072] uwsgi_sloth INFO: Start from last savepoint, last_log_datetime: 2019-02-28 10:48:29.071966
[2019-02-28 10:53:35,884] uwsgi_sloth INFO: Rendering HTML file /home/harm/uwsgi-sloth/html/html/latest_5mins.html...
[2019-02-28 10:53:35,916] uwsgi_sloth INFO: Rendering HTML file /home/harm/uwsgi-sloth/html/html/day_2019-02-28.html...
Traceback (most recent call last):
  File "/home/harm/uwsgi-sloth/v/bin/uwsgi-sloth", line 32, in <module>
    main()
  File "/home/harm/uwsgi-sloth/v/bin/uwsgi-sloth", line 25, in main
    args.func(args)
  File "/home/harm/uwsgi-sloth/v/lib/python3.5/site-packages/uwsgi_sloth/commands/start.py", line 118, in start
    day_requests_data.save()
  File "/home/harm/uwsgi-sloth/v/lib/python3.5/site-packages/uwsgi_sloth/models.py", line 48, in save
    pickle.dump(self.data, fp)
TypeError: write() argument must be str, not bytes

When changing models.py::RequestsData to open() as 'rb' and 'wb' this crash disappears, but then I get

[2019-02-28 10:56:56,919] uwsgi_sloth INFO: Start from last savepoint, last_log_datetime: 2019-02-28 10:51:56.919301
[2019-02-28 10:57:03,777] uwsgi_sloth INFO: Rendering HTML file /home/harm/uwsgi-sloth/html/html/latest_5mins.html...
[2019-02-28 10:57:03,812] uwsgi_sloth INFO: Rendering HTML file /home/harm/uwsgi-sloth/html/html/day_2019-02-28.html...
Traceback (most recent call last):
  File "/home/harm/uwsgi-sloth/v/bin/uwsgi-sloth", line 32, in <module>
    main()
  File "/home/harm/uwsgi-sloth/v/bin/uwsgi-sloth", line 25, in main
    args.func(args)
  File "/home/harm/uwsgi-sloth/v/lib/python3.5/site-packages/uwsgi_sloth/commands/start.py", line 111, in start
    for date in analyzer.data.keys():
RuntimeError: dictionary changed size during iteration

last crash might not be a python3.5 issue, but first crash is I think.

version

uwsgi-sloth==3.0.1

uwsgi-sloth latest_5mins.html fails when timezone uwsgi does not match timezone of user running uwsgi-sloth

My uwsgi logging is in utc, the users typically have timezone 'Europe/Amsterdam'.

running uwsgi-sloth start gives:

(v) harm@server:~/uwsgi-sloth$ uwsgi-sloth start -c myconf.conf 
[2019-02-28 11:38:14,005] uwsgi_sloth INFO: Start from last savepoint, last_log_datetime: 2019-02-28 11:33:14.005028
[2019-02-28 11:38:20,828] uwsgi_sloth INFO: Rendering HTML file /home/harm/uwsgi-sloth/html/html/latest_5mins.html...

As the uwsgi logging timestamps are in UTC (eg: "Thu Feb 28 10:40:00 2019") uwsgi-sloth does do the lookup for the last 5 minutes correctly.

Result

latest_5mins.html is always empty ( Slow / Total requests == 0 / 0 )

Expeced Result

latest_5mins.html shows the last 5 minutes.

html output should use the timezone of the user.
The parsing of the uwsgi logging should be able to deal with the timezone difference between report and uwsgi logging.

Python3.5 + compatible

Python3.5 + compatible. In the file 'uwsgi_sloth/models.py', line 43, fp needs to be encoded or a type error will be reported.For example: fp = fp. encode ()

No Data in latest_5_mins.html

Hi, I just tried setting up version 2.1.2 from pypi on CentOS 7, with python 2.7.5, uWSGI 2.0.13.1 and everything appeared to work and it generated the latest_5_mins.html page, but it shows 0 requests.

My uwsgi log file is stock, here is a sample from it:
[pid: 18227|app: 0|req: 203555/404742] 10.10.0.1 () {50 vars in 908 bytes} [Sat Aug 20 20:32:37 2016] GET /api/tournaments/53822/ => generated 1851 bytes in 121 msecs (HTTP/1.1 200) 4 headers in 149 bytes (1 switches on core 0)
[pid: 18563|app: 0|req: 201188/404743] 10.10.0.1 () {48 vars in 1013 bytes} [Sat Aug 20 20:32:37 2016] GET /api/tournaments/54496/ => generated 1835 bytes in 116 msecs (HTTP/1.1 200) 4 headers in 149 bytes (1 switches on core 0)

/var/www/uwsgi_sloth/tk.conf
uwsgi_log_path = '/var/www/logs/uwsgi.log'
data_dir = '/var/www/uwsgi_sloth/tk/'
domain = 'https://example.com/' ; Not real domain name, I do have this set correctly in my config

Running it with:
uwsgi-sloth start -c /var/www/uwsgi_sloth/tk.conf

I also noticed that the demo site shows 0 requests and looks the same as mine:
http://uwsgi-sloth.zlovezl.cn/latest_5mins.html

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.