Commit c119fddd authored by xa's avatar xa

document

parent 01eefc34
......@@ -13,21 +13,33 @@ Create a simple console program that monitors HTTP traffic on your machine:
Please submit here: http://app.greenhouse.io/tests/96367b070da83aae701a828fb7e5708d
## improvements
- allow to read more than 1 file at once
- keep a trace on file sources
- read directly from udp
- add signals (for unix stuff)
- handle truncate files and log rotation
- implement shortcuts :
- (d) display top
- (l) displaying realtime logs
- (r) refresh tops
## improvements
- web console output
- json stream output -> allow to pipe to another program
## how to use it
This program is written in Python 3.5.2 on a mac. It should works also on linux.
The implementation is build on top of async/await syntax introduced in Python 3.5.
It uses two external libraries:
- aiofiles handles files asynchronously
- watchdog observes filesystem changes with inotify... which lets me handle file rotation, removal, creation...
Given that such program is devoted to be used for realtime monitoring, it ignores dates field.
Moreover, it will consume only the logs that are written after start:
- for existing files, it will seek to the end, and listen from here
- new files are read from start
## Improvements
* allow to read more than 1 file at once
* keep a trace on file sources
* read directly from udp
* listen unix signals (SIGINT, SIGTERM, SIGTSTP) for stoping, pausing and resume
* handle truncate files and log rotation (implemented here)
* implement shortcuts for the console view:
* (r) refresh statistics
* (+) increase high traffic check treshold by 10
* (-) decrease high traffic check treshold by 10
* (a) acknowledge high traffic pending alert
* (p) pause/resume monitoring
* display other events than alert, like log rotation, log file creation
* implement a web server output
* implement a json stream output, which would allow to pipe to another program
......@@ -76,17 +76,23 @@ class SmartProducer(Task):
return super().start()
def stop(self, force=True):
tasks = []
if self.running:
self.observer.stop()
self.observer.join()
self.observer.unschedule_all()
for producer in self.producers.values():
producer.stop(force=force)
task = producer.stop(force=force)
tasks.append(task)
self.producers.clear()
if self.waiter and not self.waiter.done():
self.waiter.set_result(None)
self.waiter = None
return super().stop(force=force)
task = super().stop(force=force)
tasks.append(task)
tasks = [task for task in tasks if task is not None]
if tasks:
return asyncio.wait(tasks, loop=self.loop)
async def run(self):
if not self.running:
......
......@@ -88,7 +88,7 @@ async def test_full(event_loop):
await asyncio.sleep(.1, loop=event_loop)
assert task.files == set([filename3])
task.stop()
await task.stop(force=False)
result = []
while not queue.empty():
_, log = await queue.get()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment