Sentinel is a robust microservice designed for monitoring Docker containers, collecting logs, parsing them for insights, and providing performance metrics and alerting. It's particularly suited for low-latency environments such as quantitative trading systems.
- Concurrent monitoring of multiple Docker containers
- Sophisticated log parsing and analysis
- Prometheus metrics for log lines, processing time, errors, and latency
- Configurable alerting system
- Extensible architecture for easy addition of new features
- Docker
- Docker Compose
- Go 1.21 or later
-
Clone the repository:
git clone https://github.com/yourusername/sentinel.git cd sentinel
-
Build the Docker image:
docker build -t sentinel .
-
Set up environment variables: Create a
.env
file in the project root and add the following variables:PORT=8080 DB_DATABASE=sentinel DB_USERNAME=user DB_PASSWORD=password DB_PORT=5432
-
Start the services using Docker Compose:
docker-compose up -d
Once the services are up and running, you can access:
- Metrics:
http://localhost:8080/metrics
- Prometheus:
http://localhost:9090
- Grafana:
http://localhost:3000
The service can be configured using environment variables:
METRICS_ADDR
: Address to serve metrics (default: ":8080")DOCKER_HOST
: Docker daemon socket (default: "unix:///var/run/docker.sock")SMTP_HOST
: SMTP server for sending alertsSMTP_PORT
: SMTP server portSMTP_FROM
: Email address to send alerts fromSMTP_PASSWORD
: Password for the email account
To run unit tests:
go test ./...
To run integration tests (requires Docker):
go test ./test/integration -tags=integration
We use golangci-lint for linting. To run the linter:
golangci-lint run
To set up pre-commit hooks:
./scripts/setup_pre_commit.sh
To add more features:
- Create new packages in the
internal/
directory - Add new metrics in
internal/metrics/metrics.go
- Extend the log parsing logic in
internal/logparser/parser.go
- Add new alerts in
internal/alerting/alerting.go
- Update the monitor logic in
internal/monitor/monitor.go
- Update the main function in
cmd/monitor/main.go
as needed
The project uses GitHub Actions for CI/CD. The workflow includes:
- Running tests
- Linting
- Building and pushing Docker images
- Deploying to Kubernetes (including canary deployments)
- Security scanning with CodeQL and Trivy
Contributions are welcome! Please feel free to submit a Pull Request.