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

For monitoring purposes, I would like to pass the last N lines of the log file to the interface of the Django website. Like displaying the result of the tail -f filename command.

Basically, I would like to do the same thing as a supervisor who wants to get the process out of his http interface.

Any idea on how to do this?

+4
source share
2 answers

As requested by 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 - 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 is TailHandler :

 from tornado.websocket import WebSocketHandler .... class TailHandler(WebSocketHandler): 

I use this to monitor a large number of magazines, and it works like a charm :)

+3
source

if you need admin panel, you can check django_logtail here .

next to this a question arises here if you are interested ...

+1
source

All Articles