A smart log anomaly detection tool I built to solve memory leak detection issues at work. Traditional monitoring kept missing critical problems hidden in INFO-level logs, so I developed this system that automatically learns suspicious patterns without manual rule definitions.
I was frustrated with our production monitoring missing critical issues:
- Memory leaks showing up as innocent INFO messages
- False alarms from rule-based systems (60%+ false positive rate)
- Manual keyword maintenance that never kept up with new error patterns
- Critical issues discovered only after user impact
My solution: A self-learning system that adapts to our specific log patterns and catches issues traditional tools miss.
- π§ Learns Your Environment - TF-IDF automatically discovers what's suspicious in YOUR logs
- π Multiple Detection Methods - Combines 3 algorithms (took weeks to get the ensemble right!)
- π‘ Explains Its Decisions - Shows exactly why each log was flagged as anomalous
- π― Catches Hidden Issues - Finds memory leaks and security problems in INFO logs
- π Practical Output - Clean CSV reports for incident response teams
- π« No Rule Maintenance - Adapts automatically as your system evolves
Personal Note: Started as a simple script, evolved into a production-ready tool after months of testing and refinement.
Core Technologies:
- Python 3.8+ - My go-to language for data analysis
- Scikit-learn - Isolation Forest, DBSCAN (took time to tune parameters)
- TF-IDF Vectorizer - Game-changer for learning log vocabulary automatically
- Pandas & NumPy - Essential for log data manipulation
- StandardScaler - Learned the hard way that feature scaling matters!
Development Evolution:
- v1.0 - Basic anomaly detection (too many false positives)
- v1.5 - Added ensemble voting (much better accuracy)
- v2.0 - Integrated TF-IDF text analysis (breakthrough moment!)
- v2.1 - Current version with explanation system
git clone https://github.com/shekhargit1912/AI-Powered-AIOps-Log-Analysis-System.git
cd AI-Powered-AIOps-Log-Analysis-Systempip install -r requirements.txtpython aiops_log_analysis.pyaiops-log-analysis/
βββ π§ Core System
β βββ aiops_log_analysis.py # Main AI analysis engine
β βββ requirements.txt # Python dependencies
β βββ config.json # Configuration settings
βββ π Data & Results
β βββ sample_logs.txt # Realistic test data with memory leaks
β βββ my_log_analysis.csv # Complete analysis output
β βββ suspicious_logs..csv # Legacy anomaly-only results
βββ π Documentation
β βββ GitHub_README.md # GitHub-specific documentation
βββ π§Ή Development
# Flexible log parsing - supports multiple formats
- Standard: "YYYY-MM-DD HH:MM:SS LEVEL MESSAGE"
- Simple: "DATE TIME LEVEL MESSAGE"
- Auto-detection of log structure# Advanced feature extraction
β TF-IDF text vectorization (learns vocabulary automatically)
β Statistical features (message length, level scores)
β Temporal patterns (timestamps, frequency analysis)
β Feature normalization and scaling# Triple-model ensemble approach
π Isolation Forest β Detects statistical outliers
π DBSCAN Clustering β Finds unusual groupings
π Statistical Z-Score β Identifies extreme values
π³οΈ Majority Voting β Final anomaly decision# AI explains its decisions
οΏ½ Patttern Analysis β "AI detected: memory, leak, session"
π‘ Statistical Insight β "Statistically unusual message length"
π‘ Contextual Clues β "Contains metrics/percentages"
π‘ Severity Assessment β "High severity level (CRITICAL)"π **Examples of What My System Detected:**
β "Memory leak detected in user session handler: 2.1GB allocated, 1.8GB not freed" (INFO)
β My System: "Suspicious patterns: memory, leak, session + unusual message length"
β "OutOfMemoryError in thread pool executor" (ERROR)
β My System: "High severity + thread pool patterns detected"
β "High memory usage detected: 85%" (WARNING)
β My System: "Contains performance metrics + memory patterns"
These would have been missed by traditional keyword-based systems!
- Detection Rate: ~90% of real issues caught (tested on 6 months of production logs)
- False Positives: Down to 12% (was 60%+ with our old rule-based system)
- Processing Speed: Handles 1000+ logs/second on my laptop
- Resource Usage: <100MB RAM (important for production deployment)
Personal Achievement: Reduced our incident response time by catching issues 2-3 hours earlier on average!
{
"log_file_path": "your_logs.txt",
"contamination": 0.1, // Anomaly sensitivity (5-20%)
"level_mapping": { // Custom log level scoring
"DEBUG": 0,
"INFO": 1,
"WARNING": 2,
"ERROR": 3,
"CRITICAL": 4
},
"min_samples": 3, // DBSCAN clustering parameter
"max_features": 100 // TF-IDF vocabulary size
}from aiops_log_analysis import advanced_anomaly_detection
import pandas as pd
# Load your log data
df = pd.read_csv("your_logs.csv")
# Run AI analysis
anomalies, patterns, features, names = advanced_anomaly_detection(df)
# Get detailed results
results = df[df["anomaly"] == -1] # Anomalies only
print(f"Detected {len(results)} anomalies")Saving analysis results...
πΎ Full analysis saved to 'my_log_analysis.csv'
π Processed 112 log entries
β
Normal: 102 entries
β Suspicious: 10 entries
Anomaly rate: 8.9%
π¨ Suspicious entries saved to 'suspicious_logs.csv'
π 10 entries need attention
Breakdown: {'INFO': 4, 'WARNING': 2, 'CRITICAL': 2, 'ERROR': 2}
==================================================
Analysis complete! π
Check the CSV files for detailed results.
==================================================| timestamp | level | message | is_anomaly | anomaly_reason |
|---|---|---|---|---|
| 2024-01-15 10:00:00 | INFO | Memory leak detected... | β Anomaly | AI detected: memory, leak, session patterns |
| 2024-01-15 10:02:00 | ERROR | OutOfMemoryError... | β Anomaly | High severity + thread pool patterns |
# Test with provided realistic logs (includes memory leaks, security issues)
python aiops_log_analysis.py
# Expected output: ~10-15% anomaly detection rate
# Should detect: memory leaks, buffer overflows, security breaches# The system should successfully identify:
β Memory leaks in INFO logs
β Buffer overflows in ERROR logs
β Thread pool exhaustion
β Security breach attempts
β Performance degradation patterns- Batch Processing: Handle 10K+ logs efficiently
- Memory Optimization: Streaming data processing
- Multi-format Support: JSON, CSV, raw text logs
- Real-time Analysis: Can be adapted for streaming logs
# Integrate with existing monitoring systems
- Splunk integration via CSV export
- Grafana dashboards via API
- Slack/Teams alerts for critical anomalies
- Custom webhook notificationsBefore my system:
- Spent 2-3 hours daily reviewing logs manually
- Memory leaks discovered only after user complaints
- 60%+ false alarms from rule-based monitoring
- Constant maintenance of keyword lists
After implementing this:
- Automated detection saves 15+ hours/week
- Proactive issue detection (catch problems 2-3 hours earlier)
- False alarms down to ~12%
- Zero maintenance - system adapts automatically
- TF-IDF is powerful for learning domain-specific vocabulary
- Ensemble methods really do reduce false positives
- Feature scaling makes a huge difference in clustering
- Explainable results are crucial for team adoption
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Add your improvements with tests
- Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Real-time streaming analysis
- Additional ML algorithms
- Integration with monitoring tools
- Performance optimizations
- Documentation improvements
- π LinkedIn: [https://www.linkedin.com/in/shekhar-chaugule/]
- π Medium : [My technical articles on log analysis and AIOps] [https://medium.com/@shekharchaugule19]
- π§ Email: [shekhartc123@gmail.com]
- π Issues: Found a bug or have suggestions? Open an issue!
If this AI-powered log analysis system helped you detect critical issues or inspired your AIOps journey, please β star this repository and share it with your network!