Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stream the last few lines of a file in Django?

For monitoring purposes I'd like to stream the last N lines of a log file into a Django website interface. Like displaying the result of a tail -f filename command.

Basically I'd like to do the same as supervisord which alows to logtail a process from its http interface.

Any idea on how to do that?

like image 320
Arnaud Avatar asked Jul 06 '12 07:07

Arnaud


2 Answers

As requested by the OP, here is an example using webtail:

$ webtail \
    --port=8000 \
    --files=/var/log/nginx/error.log,/var/log/nginx/access.log \
    --logging=warn

As I understand from the comments - the OP needs a solution that supports websockets. Webtails does. If you look in the webtail.py file:

routes = [(r'/', MainHandler), (r'/tail/', TailHandler),
    (r'/signin/', SigninHandler), (r'/signout/', SignoutHandler)]

where TailHandler is:

from tornado.websocket import WebSocketHandler

....

class TailHandler(WebSocketHandler):

I'm using this for monitoring lots of logs, and it works like a charm :)

like image 95
Tisho Avatar answered Oct 03 '22 20:10

Tisho


if you need in admin panel u can check out django_logtail here.

beside this there is a question here if you interested...

like image 34
Aragon Avatar answered Oct 03 '22 19:10

Aragon