6

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?

Arnaud
  • 1,121
  • 1
  • 11
  • 26
  • 2
    Take a look at http://pypi.python.org/pypi/webtail/0.1b16 – Tisho Jul 06 '12 at 07:43
  • possible duplicate of [tail -f in a webbrowser](http://stackoverflow.com/questions/2836838/tail-f-in-a-webbrowser) – Martijn Pieters Jul 06 '12 at 08:10
  • @MartijnPieters, I want to catch the tail -f, then display it, this question answers only the second issue. – Arnaud Jul 06 '12 at 08:15
  • 1
    @Arnaud: You'd not tail on the server side; include a file position in the response, and next time the JS calls the Django view use that file position to read more data if there is. – Martijn Pieters Jul 06 '12 at 08:18
  • Webtail would be nice if nginx allowed websocket reverse proxy. But it doesn't. Any security issue in opening a port for websocket connections only? – Arnaud Jul 06 '12 at 13:19
  • @Tisho please create an answer mentioning webtail, tornado or twisted or any other library handling websockets for Python and I'll accept it 'cause your comment is the closest of the solution I was searching for. – Arnaud Jan 13 '13 at 23:42

2 Answers2

3

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 :)

Tisho
  • 8,320
  • 6
  • 44
  • 52
2

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

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

Community
  • 1
  • 1
urcm
  • 2,274
  • 1
  • 19
  • 45