DEV Community

Kanav Gathe
Kanav Gathe

Posted on • Edited on

Day 10/90: Log Analyzer and Report Generator 📊 #90DaysOfDevOps

Day 10: Log Analyzer and Report Generator 🚀

Hello DevOps enthusiasts! 👋 Welcome to Day 10 of the #90DaysOfDevOps challenge. Today, we're creating a log analysis tool.

Log Analyzer Script 💻

#!/bin/bash

# Check arguments
if [ $# -ne 1 ]; then
    echo "Usage: $0 <log_file>"
    exit 1
fi

log_file="$1"
report_file="report_$(date +%Y%m%d_%H%M%S).txt"

# Check if log file exists
if [ ! -f "$log_file" ]; then
    echo "Error: Log file not found"
    exit 1
fi

# Generate report
{
    echo "Log Analysis Report"
    echo "==================="
    echo "Date: $(date)"
    echo "Log File: $log_file"
    echo "Total Lines: $(wc -l < "$log_file")"
    echo "Error Count: $(grep -c "ERROR" "$log_file")"

    echo -e "\nTop 5 Errors:"
    grep "ERROR" "$log_file" | sort | uniq -c | sort -nr | head -5

    echo -e "\nCritical Events:"
    grep -n "CRITICAL" "$log_file"
} > "$report_file"

# Archive log
mkdir -p processed_logs
cp "$log_file" "processed_logs/$(basename "$log_file").$(date +%Y%m%d)"

echo "Report generated: $report_file"
Enter fullscreen mode Exit fullscreen mode

Script Features 🔧

  1. Analysis Capabilities

    • Error counting
    • Critical event detection
    • Top error identification
    • Line counting
  2. Report Generation

    • Timestamped reports
    • Organized sections
    • Statistical analysis
  3. Log Management

    • Automatic archiving
    • Date-based organization
    • Original file preservation

Key Takeaways 💡

  • Log analysis is crucial for troubleshooting
  • Pattern matching helps find issues
  • Reports should be well-organized
  • Archive management is important

Bash #DevOps #Monitoring #Linux #90DaysOfDevOps


This is Day 10 of my #90DaysOfDevOps journey. Keep analyzing and monitoring!

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay