A lightweight CLI-based log analytics and anomaly detection tool designed for DevOps and SRE environments.
The project simulates application logs, analyzes operational health, maintains a small historical baseline, detects abnormal error patterns using statistical analysis, and exposes meaningful exit codes that can be consumed by automation and CI/CD pipelines.
The goal is simple:
Turn raw application logs into an actionable system health signal.
Applications continuously generate logs containing information about their operational state:
- INFO
- WARNING
- ERROR
- CRITICAL
Manually reviewing these logs becomes inefficient as the volume increases.
This project provides a lightweight automated approach to:
- Generate realistic application logs.
- Analyze log severity patterns.
- Count errors, warnings, and critical events.
- Maintain a rolling historical baseline.
- Calculate statistical deviation using Z-score.
- Detect abnormal application behavior.
- Return meaningful Linux exit codes.
- Automatically test the analyzer.
- Run those tests through GitHub Actions CI.
- Package and release the validated tool.
The project intentionally avoids unnecessary infrastructure and focuses on the core DevOps/SRE problem:
Application Logs
|
v
Log Analysis
|
v
Historical Baseline
|
v
Statistical Analysis
|
v
System Health Status
|
v
Automation / CI
In a production environment, applications can generate thousands of log entries.
A simple approach might be:
ERROR count > 20
|
v
ALERT
However, fixed thresholds do not always represent abnormal behavior.
For example:
Application A
Normal:
5 errors
Current:
15 errors
15 may be a significant increase.
While another application may normally produce:
100 errors
and suddenly produce:
115 errors
The same absolute increase does not necessarily indicate the same level of concern.
Therefore, this project combines:
- Threshold-based detection
- Historical baseline analysis
- Statistical anomaly detection
to provide a more meaningful operational signal.
The project is designed to demonstrate practical DevOps and SRE concepts:
- Linux shell automation
- Python scripting
- Log processing
- Operational monitoring concepts
- Statistical anomaly detection
- Historical baselines
- Exit-code driven automation
- Automated testing
- GitHub Actions CI
- Packaging and release automation
- Clean separation between source, test data, and runtime data
+-------------------+
| generator.py |
| |
| Simulates traffic |
+---------+---------+
|
v
+-------------------+
| app.log |
| |
| Application logs |
+---------+---------+
|
v
+-------------------+
| main.sh |
| |
| Log Analyzer |
+---------+---------+
|
+---------------+---------------+
| | |
v v v
Error Count Critical Count Warnings
| | |
+---------------+---------------+
|
v
Historical Baseline
|
v
Z-Score
|
v
+-------------------+
| System Status |
+-------------------+
|
+----------------+----------------+
| | |
v v v
OK WARNING CRITICAL
|
v
ANOMALY
|
v
Exit Code
|
v
CI/CD Automation
Log-Analytics-ToolKit/
│
├── generator.py
├── main.sh
├── test.sh
├── README.md
├── CHANGELOG.md
├── .gitignore
│
├── test_data/
│ └── sample_app.log
│
└── runtime_logs/
├── app.log
├── run_history.csv
└── script_log.log
Generates simulated application logs.
Stop the generator with:
Ctrl+C
The primary log analysis engine.
It:
- Reads
runtime_logs/app.log. - Counts total log entries.
- Counts ERROR events.
- Counts WARNING events.
- Counts CRITICAL events.
- Maintains historical analysis data.
- Calculates the recent error baseline.
- Calculates standard deviation.
- Calculates Z-score.
- Determines the system status.
- Records the analysis result.
- Returns a meaningful exit code.
Run it with:
./main.shExample output:
========== Log Analysis ==========
Log file : runtime_logs/app.log
Total lines : 525
Errors : 12
Warnings : 18
Critical : 1
Mean errors : 8.40
Std deviation : 1.72
Z-score : 2.09
System status : ANOMALY
===================================
test.sh is the automated test suite for the analyzer.
It validates the expected behavior of the application rather than relying on manual testing.
The current tests cover:
- Healthy application
- Error threshold
- Critical threshold
- History creation
- Runtime logging
Run the test suite:
./test.shExpected result:
========================================
Log Analytics Toolkit Test Suite
========================================
PASS: Healthy application
PASS: Error threshold
PASS: Critical threshold
PASS: History creation
PASS: Runtime logging
========================================
Test Summary
========================================
Passed : 5
Failed : 0
========================================
The test suite creates and removes runtime data automatically so tests do not depend on previous executions.
The repository contains deterministic test data:
test_data/sample_app.log
This file is intentionally committed to Git.
It provides a predictable baseline for testing the analyzer.
This is different from runtime data.
test_data/
|
+-- sample_app.log
|
+-- Version controlled
+-- Deterministic
+-- Used by tests
Runtime-generated files are stored separately:
runtime_logs/
The directory may contain:
runtime_logs/
├── app.log
├── run_history.csv
└── script_log.log
These files are intentionally excluded from Git.
They represent runtime state rather than source code or test fixtures.
The analyzer maintains a rolling history of recent error counts.
The current error count is compared against the historical baseline.
The project uses the Z-score:
Z = (X - μ) / σ
Where:
X = current error count
μ = historical mean
σ = historical standard deviation
The configured anomaly threshold is:
Z_THRESHOLD=2
Therefore, when:
|Z| > 2
the current error rate is considered statistically unusual.
This allows the system to detect changes in behavior rather than relying only on absolute thresholds.
The analyzer currently uses the following priority:
CRITICAL
↓
ERROR THRESHOLD
↓
STATISTICAL ANOMALY
↓
OK
The thresholds are:
ERROR_THRESHOLD=20
CRITICAL_THRESHOLD=5
Z_THRESHOLD=2
Therefore:
CRITICAL >= 5
Result:
SYSTEM STATUS = CRITICAL
EXIT CODE = 2
ERROR >= 20
Result:
SYSTEM STATUS = WARNING
EXIT CODE = 1
|Z-score| > 2
Result:
SYSTEM STATUS = ANOMALY
EXIT CODE = 1
If none of the above conditions are met:
SYSTEM STATUS = OK
EXIT CODE = 0
Exit codes make the tool useful for automation.
| Exit Code | Meaning |
|---|---|
0 |
Healthy / OK |
1 |
Warning or statistical anomaly |
2 |
Critical condition |
2 |
Invalid or missing log input |
Example:
./main.sh
echo $?A CI/CD pipeline can use these exit codes to determine whether a stage should succeed or fail.
A monitoring script becomes much more useful when another system can consume its result.
For example:
main.sh
|
+-- exit 0 --> healthy
|
+-- exit 1 --> warning/anomaly
|
+-- exit 2 --> critical
This makes the tool suitable for:
- CI pipelines
- Scheduled jobs
- Cron
- Server automation
- Health checks
- Monitoring wrappers
- Incident automation
The project uses GitHub Actions to automatically execute the test suite.
The intended CI workflow is:
Developer
|
v
git push / Pull Request
|
v
GitHub Actions
|
v
Checkout repository
|
v
Run test.sh
|
+-------- PASS --------+
| |
v v
CI GREEN CI FAILED
The important principle is that GitHub Actions runs the same test suite used locally.
Local:
./test.shCI:
./test.shThis prevents the CI environment from having a completely different testing process from the developer environment.
The project does not require a traditional production deployment environment.
Instead, the planned Continuous Delivery stage focuses on:
CI
|
v
Tests pass
|
v
Package project
|
v
Create version
|
v
Create release artifact
|
v
Publish release
For example:
log-analytics-toolkit-v1.0.0.tar.gz
The goal is to keep the project in a releasable state.
This demonstrates Continuous Delivery without inventing an unnecessary production deployment environment.
This project follows the Continuous Delivery model.
Code
↓
Test
↓
Package
↓
Release
↓
Ready to deploy
A release may still require manual approval before production deployment.
Code
↓
Test
↓
Package
↓
Release
↓
Automatic production deployment
Continuous Deployment would require an actual deployment target.
For this project, automatic deployment is intentionally outside the current scope.
The analyzer can be executed as part of a pipeline:
./main.shIts exit code can determine whether the pipeline should continue.
The analyzer could be executed periodically:
cron
|
v
main.sh
|
v
Analyze application logs
|
v
Return health status
For a small application running on a Linux server, a lightweight shell-based analyzer can be useful when a full observability platform is unnecessary.
The historical baseline can identify unusual behavior even when an absolute threshold has not been crossed.
For example:
Normal:
5 errors
Current:
15 errors
Absolute threshold:
20
Threshold detection:
OK
Statistical detection:
ANOMALY
This demonstrates why statistical analysis can complement traditional threshold monitoring.
The project intentionally uses both.
Python is responsible for:
- Simulating application behavior
- Generating realistic logs
- Generating controlled anomaly scenarios
Bash is responsible for:
- Linux automation
- Log processing
- Operational analysis
- Exit codes
- CI/CD integration
- Runtime file management
This reflects a practical DevOps approach where different tools are used for different responsibilities.
The project follows a few simple principles.
Source code
≠
Runtime state
Tests should not depend on whatever happened on a developer's machine.
The project deliberately avoids unnecessary dependencies.
Manual test
↓
Automated test
↓
CI validation
The project is intentionally not turning into a large observability platform.
Python 3
Bash
Linux
Git
GitHub
GitHub Actions
AWK
Grep
Core Unix utilities
git clone <repository-url>
cd Log-Analytics-ToolKitchmod +x main.sh
chmod +x test.shRun:
python3 generator.pyStop with:
Ctrl+C
./main.sh./test.shGenerate abnormal traffic:
python3 generator.py --anomalyAllow enough log entries to accumulate and then stop the generator.
Run:
./main.shThe analyzer will evaluate the current log behavior against the historical baseline.
The project currently keeps its core thresholds directly within main.sh.
Current values:
ERROR_THRESHOLD=20
CRITICAL_THRESHOLD=5
Z_THRESHOLD=2
ROLLING_WINDOW=10
MAX_HISTORY_LINES=20
These values control:
- Error threshold
- Critical threshold
- Statistical anomaly threshold
- Historical window size
- Runtime history retention
The configuration is intentionally kept simple for the current project scope.
The project includes several safeguards:
- Missing log file detection
- Controlled exit codes
- Runtime history retention
- Test isolation
- Deterministic test data
- Separate runtime and test data
- Automated regression testing
The analyzer also maintains only a limited amount of history rather than allowing the history file to grow indefinitely.
The overall development workflow is:
1. Develop
|
v
2. Run locally
|
v
3. Run ./test.sh
|
v
4. Push to GitHub
|
v
5. GitHub Actions CI
|
v
6. Package
|
v
7. Release
- Application log simulation
- Normal and anomaly log generation
- CLI log analysis
- Error/warning/critical detection
- Historical baseline
- Z-score anomaly detection
- Exit-code based status
- Automated Bash tests
- Deterministic test data
- GitHub Actions CI
- Continuous Delivery through packaging and release
The project intentionally does not attempt to become a full observability platform.
The following are outside the current scope:
- Kubernetes
- Prometheus
- Grafana
- Elasticsearch
- Logstash
- Kafka
- Cloud infrastructure
- Distributed tracing
- Full production deployment infrastructure
- Complex monitoring dashboards
Those technologies solve different problems and are not required to demonstrate the objective of this project.
Possible future enhancements include:
- Structured JSON log support
- Additional anomaly detection methods
- Configurable thresholds
- More sophisticated test coverage
- Packaging as an installable CLI
- Automated versioning
- GitHub Release automation
- Optional alert integrations
- Additional CI quality checks
These will only be introduced if they provide meaningful value to the project.
This project demonstrates practical understanding of:
- Linux shell scripting
- Bash automation
- Python scripting
- Log processing
- Operational monitoring
- Statistical reasoning
- Z-score anomaly detection
- Historical baselines
- Exit codes
- Automated testing
- Test fixtures
- CI pipelines
- Continuous Delivery
- Release automation
- DevOps/SRE thinking
This project is intended for learning, experimentation, and demonstration of DevOps/SRE concepts.
This project is part of the DevOps Learning Journey by TechWithHer.
Explore the complete course and project series: