logmonitor

command module
v0.0.0-...-93f7a3c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2019 License: MIT Imports: 11 Imported by: 0

README

HTTP log monitoring console program

Build Status Go Report Card Coverage Status GoDoc

Consume an actively written-to w3c-formatted HTTP access log. It should default to reading /var/log/access.log and be overridable. Example log lines:

127.0.0.1 - james [09/May/2018:16:00:39 +0000] "GET /report HTTP/1.0" 200 1234
127.0.0.1 - jill [09/May/2018:16:00:41 +0000] "GET /api/user HTTP/1.0" 200 1234
127.0.0.1 - frank [09/May/2018:16:00:42 +0000] "GET /api/user HTTP/1.0" 200 1234
127.0.0.1 - mary [09/May/2018:16:00:42 +0000] "GET /api/user HTTP/1.0" 200 1234
  • Display stats every 10s about the traffic during those 10s:
  • Make sure a user can keep the app running and monitor the log file continuously
  • Whenever total traffic for the past 2 minutes exceeds a certain number on average, add a message saying that High traffic generated an alert - hits = {value}, triggered at {time}.
    • The default threshold should be 10 requests per second and should be overridable.
  • Whenever the total traffic drops again below that value on average for the past 2 minutes, print or displays another message detailing when the alert recovered.

Run via Docker

Build the Docker container
docker build -t caitlin615:logmonitor .
Run with defaults
docker run --rm -it caitlin615:logmonitor
Run with custom *.log file
docker run --rm -it caitlin615:logmonitor -filename myAccessFile.log
Run with custom high traffic alert threshold (requests per second)
docker run --rm -it -e ALERT_REQ_PER_SECOND_THRESHOLD="30" caitlin615:logmonitor

Generating random log entries

Where myAccessFile.log is the filename where the script should write the logs to.

go run cmd/generate_logs/main.go -filename myAccessFile.log

Or with Docker, run this command to override the entrypoint in the Dockerfile

docker run --rm -it --entrypoint go caitlin615:logmonitor run cmd/generate_logs/main.go -filename myAccessFile.log
Things I didn't get to but would like to have done
  • Mutexes when handling list of logs within goroutines
  • Error channels

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL