Linux Log Analyzer
Overview
Analyzes any Linux log content and produces a structured report: log type detection, event timeline, error/warning summary, security threat detection, anomaly flagging, and prioritized recommendations. Writes the full report to disk and prints only the key findings summary.
Language: Respond in the user's language. Report content in English.
When to Use
- User pastes log content and wants it analyzed
- User asks "what's wrong with my server?" and provides logs
- User wants to find brute force attacks, failed logins, unusual IPs
- User wants to understand why a service crashed or behaved unexpectedly
- User wants a summary of a long log file
- User asks about errors in nginx, sshd, Docker, cron, kernel logs
When NOT to Use
- User wants to set up centralized log management → use /linux-monitoring-setup
- User wants to write a script that parses logs → use /linux-shell-scriptor
- User wants to audit a config file → use /linux-config-auditor
Step 1 — Accept Input
Three input methods:
| Method |
What user provides |
| Paste |
Copies log lines directly into the chat |
| Path |
Gives a file path like /var/log/auth.log — read it with the Read tool |
| Description |
Describes the log and problem — ask them to paste relevant lines |
If the user describes a problem without pasting logs, ask:
"Paste the relevant log lines (or the full log file content) and I'll analyze them."
Step 2 — Detect Log Type
Auto-detect from content patterns. Never ask the user what log type it is unless completely ambiguous.
| Log type |
Detection pattern |
auth.log / secure |
sshd, pam_unix, sudo, useradd, passwd, Failed password, Accepted publickey |
syslog / messages |
Generic kernel:, systemd, cron, mixed daemon messages |
kern.log |
kernel:, oom-killer, EXT4-fs, NVMe, hardware errors |
nginx access |
GET /, POST /, HTTP/1.1, status codes, IP + user-agent pattern |
nginx error |
[error], [warn], [crit], upstream, connect() failed |
apache access |
Same as nginx access with Apache-style combined log format |
apache error |
[Mon, [error], AH0 error codes |
journalctl |
-- Boot, systemd[1], kernel: mixed with unit names |
fail2ban |
fail2ban.actions, Ban, Unban, Found |
docker |
Container name prefix, level=, JSON log format |
cron |
CRON[, CMD, crond |
mysql/postgres |
ERROR, FATAL, PANIC, query patterns, slow query |
mongodb |
SEVERE, ERROR, WARNING, WiredTiger, getLastError, connection refused |
redis |
WARNING, NOTICE, #, ERR, maxmemory-policy, RDB/AOF |
ufw/iptables |
UFW BLOCK, IN=, OUT=, SRC=, DST= |
Step 3 — Analysis Framework
Run all analysis passes. Adjust depth to the log volume.
Pass 1 — Error & Warning Summary
Count and categorize by severity:
| Severity |
Keywords to scan for |
| 🔴 FATAL / CRITICAL |
FATAL, PANIC, critical, oom-killer, kernel panic, segfault |
| 🟠 ERROR |
ERROR, error, [error], failed, Failed, refused, denied |
| 🟡 WARNING |
warn, WARNING, [warn], deprecated, timeout, retrying |
| 🔵 INFO |
Informational events worth noting (restarts, connections, auth successes) |
Pass 2 — Security Threat Detection
Always run for auth.log, syslog, nginx, ufw logs:
| Threat |
Signal |
| Brute force SSH |
>5 Failed password from same IP within short window |
| Successful breach after failures |
Accepted login from IP that previously had failures |
| Root login attempt |
Failed password for root or Accepted publickey for root |
| Invalid user attempts |
Invalid user — enumerate usernames being tried |
| Port scanning |
Many different ports hit from same IP in ufw/iptables logs |
| Web scanning / probing |
Many 404s, /wp-admin, /.env, /phpMyAdmin, shell upload patterns |
| Privilege escalation |
Unexpected sudo usage, su for unusual accounts |
| Account changes |
useradd, usermod, passwd outside expected windows |
| Cron injection |
Unexpected new cron entries in syslog |
Pass 3 — Performance & Stability Issues
| Issue |
Signal |
| OOM kills |
oom-killer, Out of memory — note which process and how much RAM |
| Service crashes / restarts |
start request repeated too quickly, failed + restarting |
| Disk errors |
I/O error, EXT4-fs error, Buffer I/O error — flag as urgent |
| High load / slow queries |
DB slow query, lock wait timeout, nginx upstream timed out |
| Network issues |
connection refused, No route to host, name resolution failure |
| Certificate expiry |
certificate has expired, SSL_ERROR, certificate verify failed |
Pass 4 — Timeline of Notable Events
Extract the 10–20 most significant events in chronological order with timestamps.
Pass 5 — IP Intelligence
For any log containing IP addresses:
- List top 10 IPs by request/event count
- Flag IPs with >10 failed auth attempts
- Flag IPs that appear in both failures and successes (potential breach)
- Note any internal vs external IP patterns
- Classify IPs: private RFC1918 (
10.x, 172.16–31.x, 192.168.x) vs public
- Flag known bad ranges (Tor exit nodes, common scanner ASNs like Shodan, Censys)
Pass 6 — Extended Analysis
Run these deeper passes when the log has enough data (>50 lines or contains meaningful time range):
Frequency & Spike Detection
- Bucket events by hour or minute and calculate the baseline rate
- Flag any window where the event rate is >3× the average — these are anomalous spikes
- Example output: "Error rate spiked 8× at 03:14 — 47 errors in 60 seconds vs. average of 6/min"
Cross-Event Correlation
Link related events that occurred close in time (within 60 seconds):
- SSH failure burst → followed by successful login = credential stuffing / breach attempt
- Service restart → followed by error spike = crash loop with side effects
- OOM kill → followed by slow query or timeout = resource starvation cascade
- UFW block spike → followed by auth failures = coordinated attack from same actor
Trend Analysis
If the log spans more than 1 hour:
- Is the error rate increasing, decreasing, or stable?
- Are any IPs showing escalating activity (first scans, then auth attempts, then exploits)?
- Any recurring patterns (same error every hour = likely a broken cron job)?
Filesystem & Kernel Extended Analysis (ext2/ext3/ext4, hardware)
Specifically for kern.log and syslog:
| Signal |
Meaning |
Urgency |
EXT4-fs error / EXT3-fs error |
Filesystem corruption |
🔴 Immediate — backup and run fsck |
Buffer I/O error on dev |
Disk read/write failure |
🔴 Disk may be dying — run smartctl |
SCSI error / ata exception |
Storage controller error |
🔴 Hardware issue |
MCE hardware error |
CPU/memory hardware fault |
🔴 Critical hardware failure |
EDAC MC errors |
ECC memory errors |
🟠 RAM degrading |
soft lockup / hard lockup |
Kernel deadlock or hung task |
🟠 System instability |
RCU stall |
Real-Time Clock stall — kernel hang |
🟠 Investigate running processes |
segfault at address |
Process memory violation |
🟠 App crash or exploit attempt |
oom-killer |
Out-of-memory process kill |
🟠 RAM exhaustion |
ip_tables: ... table is full |
Firewall rule table overflow |
🟡 Tune conntrack limits |
For each filesystem/hardware finding, include the exact recommended command to diagnose further.
HTTP / Web Log Pattern Analysis
For nginx and Apache access logs only:
- Status code distribution: count 2xx / 3xx / 4xx / 5xx — high 5xx = app problem, high 4xx = scanners/bad clients
- Top requested paths: list top 20 URLs — flag any that look like vulnerability scanning (
/.env, /wp-login.php, /admin, /shell, /phpinfo.php)
- Response size anomalies: unusually large responses could indicate data exfiltration
- User-agent analysis: flag empty user-agents, known scanner agents (Nikto, sqlmap, masscan, zgrab), and headless browser signatures
- Request rate per IP per minute: flag IPs exceeding 60 req/min as potential DDoS or scrapers
- Slow requests: flag any
request_time > 5s if log format includes it
Database Log Extended Analysis
For MySQL, PostgreSQL, MongoDB logs:
- List slow queries (>1s) with count and average duration
- Flag
lock wait timeout — identifies transaction conflicts
- Flag
too many connections — indicates connection pool exhaustion
- Flag
deadlock found — requires query/index review
- Replication errors:
Slave_IO_Running: No, replication lag
Step 4 — Write Report
Write the full report to ./log-analysis/report-<log-type>-<YYYYMMDD>.md in the current working directory.
Report structure:
# Log Analysis Report
**Log type:** [detected type]
**Lines analyzed:** [count]
**Time range:** [first timestamp] → [last timestamp]
**Generated:** [date]
## Executive Summary
[2–3 sentences: what was found, severity, most important action]
## Findings by Severity
### 🔴 Critical / Fatal ([count])
[table: timestamp | message | count]
### 🟠 Errors ([count])
[table: timestamp | message | count]
### 🟡 Warnings ([count])
[table: top entries]
## Security Events
[table: threat type | source IP | count | first seen | last seen | verdict]
## Top IPs
[table: IP | requests | failed auths | successful auths | verdict]
## Service / Stability Events
[list of crashes, restarts, OOM events with timestamps]
## Filesystem & Hardware Events
[ext4 errors, disk I/O errors, kernel panics, MCE errors — with recommended diagnostic commands]
## Extended Analysis
### Anomalous Spikes
[hourly event rate table — flag windows >3× average]
### Correlated Event Chains
[linked event sequences with timestamps and interpretation]
### Trend
[is the situation stable, improving, or worsening?]
### HTTP Pattern Analysis (if web log)
[status code distribution, top paths, scanner activity, suspicious user-agents]
### Database Analysis (if DB log)
[slow queries, lock waits, connection issues]
## Notable Events Timeline
[chronological list of the 10–20 most significant events]
## Recommendations
[numbered, prioritized list — most urgent first]
Step 5 — Chat Output
Print ONLY this after writing the report:
✅ Log analysis complete → ./log-analysis/report-[type]-[date].md
📊 Summary ([N] lines · [time range]):
🔴 Critical: [count]
🟠 Errors: [count]
🟡 Warnings: [count]
🔵 Notable: [count]
🔒 Security: [one line — e.g. "47 brute force attempts from 3.4.5.6 — IP should be blocked"]
⚡ Top issue: [one line — e.g. "nginx upstream timeout 23 times between 02:00–03:00"]
▶ Recommended actions:
1. [most urgent action]
2. [second action]
3. [third action]
💡 Next: /linux-security-hardener to block attack vectors · /linux-config-auditor to fix misconfigs
If no issues were found:
✅ Log analysis complete → ./log-analysis/report-[type]-[date].md
No critical issues found. [N] lines analyzed, [time range].
Quick Reference — Common Findings & Actions
| Finding |
Recommended action |
| SSH brute force from IP X |
ufw deny from X or add to fail2ban blocklist |
| Root login accepted |
Disable PermitRootLogin in sshd_config immediately |
| OOM kill of process X |
Check RAM usage, add swap, tune process memory limits |
| Disk I/O errors |
Run smartctl -a /dev/sdX — disk may be failing |
| Nginx upstream timeout |
Check app server health, tune proxy_read_timeout |
| SSL certificate expired |
Run certbot renew or check renewal cron job |
| Service restart loop |
Check service logs: journalctl -u service-name -n 100 |
| DB slow queries |
Enable slow query log, add indexes, check connection pool |
1---2name: linux-log-analyzer3description: Use when user wants to analyze, review, parse, or understand Linux log files — auth.log, syslog, kern.log, nginx access or error logs, Apache logs, journalctl output, fail2ban logs, Docker container logs, cron logs, or any system or application log — to find errors, anomalies, security events, brute force attempts, crashes, or performance issues.4---56# Linux Log Analyzer78## Overview910Analyzes any Linux log content and produces a structured report: log type detection, event timeline, error/warning summary, security threat detection, anomaly flagging, and prioritized recommendations. Writes the full report to disk and prints only the key findings summary.1112**Language:** Respond in the user's language. Report content in English.1314---1516## When to Use1718- User pastes log content and wants it analyzed19- User asks "what's wrong with my server?" and provides logs20- User wants to find brute force attacks, failed logins, unusual IPs21- User wants to understand why a service crashed or behaved unexpectedly22- User wants a summary of a long log file23- User asks about errors in nginx, sshd, Docker, cron, kernel logs2425## When NOT to Use2627- User wants to set up centralized log management → use /linux-monitoring-setup28- User wants to write a script that parses logs → use /linux-shell-scriptor29- User wants to audit a config file → use /linux-config-auditor3031---3233## Step 1 — Accept Input3435Three input methods:3637| Method | What user provides |38|--------|-------------------|39| **Paste** | Copies log lines directly into the chat |40| **Path** | Gives a file path like `/var/log/auth.log` — read it with the Read tool |41| **Description** | Describes the log and problem — ask them to paste relevant lines |4243If the user describes a problem without pasting logs, ask:44> "Paste the relevant log lines (or the full log file content) and I'll analyze them."4546---4748## Step 2 — Detect Log Type4950Auto-detect from content patterns. Never ask the user what log type it is unless completely ambiguous.5152| Log type | Detection pattern |53|----------|------------------|54| `auth.log` / `secure` | `sshd`, `pam_unix`, `sudo`, `useradd`, `passwd`, `Failed password`, `Accepted publickey` |55| `syslog` / `messages` | Generic `kernel:`, `systemd`, `cron`, mixed daemon messages |56| `kern.log` | `kernel:`, `oom-killer`, `EXT4-fs`, `NVMe`, hardware errors |57| `nginx access` | `GET /`, `POST /`, `HTTP/1.1`, status codes, IP + user-agent pattern |58| `nginx error` | `[error]`, `[warn]`, `[crit]`, `upstream`, `connect() failed` |59| `apache access` | Same as nginx access with Apache-style combined log format |60| `apache error` | `[Mon`, `[error]`, `AH0` error codes |61| `journalctl` | `-- Boot`, `systemd[1]`, `kernel:` mixed with unit names |62| `fail2ban` | `fail2ban.actions`, `Ban`, `Unban`, `Found` |63| `docker` | Container name prefix, `level=`, JSON log format |64| `cron` | `CRON[`, `CMD`, `crond` |65| `mysql/postgres` | `ERROR`, `FATAL`, `PANIC`, query patterns, `slow query` |66| `mongodb` | `SEVERE`, `ERROR`, `WARNING`, `WiredTiger`, `getLastError`, `connection refused` |67| `redis` | `WARNING`, `NOTICE`, `#`, `ERR`, `maxmemory-policy`, `RDB/AOF` |68| `ufw/iptables` | `UFW BLOCK`, `IN=`, `OUT=`, `SRC=`, `DST=` |6970---7172## Step 3 — Analysis Framework7374Run all analysis passes. Adjust depth to the log volume.7576### Pass 1 — Error & Warning Summary7778Count and categorize by severity:7980| Severity | Keywords to scan for |81|----------|---------------------|82| 🔴 FATAL / CRITICAL | `FATAL`, `PANIC`, `critical`, `oom-killer`, `kernel panic`, `segfault` |83| 🟠 ERROR | `ERROR`, `error`, `[error]`, `failed`, `Failed`, `refused`, `denied` |84| 🟡 WARNING | `warn`, `WARNING`, `[warn]`, `deprecated`, `timeout`, `retrying` |85| 🔵 INFO | Informational events worth noting (restarts, connections, auth successes) |8687### Pass 2 — Security Threat Detection8889Always run for auth.log, syslog, nginx, ufw logs:9091| Threat | Signal |92|--------|--------|93| **Brute force SSH** | >5 `Failed password` from same IP within short window |94| **Successful breach after failures** | `Accepted` login from IP that previously had failures |95| **Root login attempt** | `Failed password for root` or `Accepted publickey for root` |96| **Invalid user attempts** | `Invalid user` — enumerate usernames being tried |97| **Port scanning** | Many different ports hit from same IP in ufw/iptables logs |98| **Web scanning / probing** | Many 404s, `/wp-admin`, `/.env`, `/phpMyAdmin`, shell upload patterns |99| **Privilege escalation** | Unexpected `sudo` usage, `su` for unusual accounts |100| **Account changes** | `useradd`, `usermod`, `passwd` outside expected windows |101| **Cron injection** | Unexpected new cron entries in syslog |102103### Pass 3 — Performance & Stability Issues104105| Issue | Signal |106|-------|--------|107| OOM kills | `oom-killer`, `Out of memory` — note which process and how much RAM |108| Service crashes / restarts | `start request repeated too quickly`, `failed` + `restarting` |109| Disk errors | `I/O error`, `EXT4-fs error`, `Buffer I/O error` — flag as urgent |110| High load / slow queries | DB `slow query`, `lock wait timeout`, nginx `upstream timed out` |111| Network issues | `connection refused`, `No route to host`, `name resolution failure` |112| Certificate expiry | `certificate has expired`, `SSL_ERROR`, `certificate verify failed` |113114### Pass 4 — Timeline of Notable Events115116Extract the 10–20 most significant events in chronological order with timestamps.117118### Pass 5 — IP Intelligence119120For any log containing IP addresses:121- List top 10 IPs by request/event count122- Flag IPs with >10 failed auth attempts123- Flag IPs that appear in both failures and successes (potential breach)124- Note any internal vs external IP patterns125- Classify IPs: private RFC1918 (`10.x`, `172.16–31.x`, `192.168.x`) vs public126- Flag known bad ranges (Tor exit nodes, common scanner ASNs like Shodan, Censys)127128### Pass 6 — Extended Analysis129130Run these deeper passes when the log has enough data (>50 lines or contains meaningful time range):131132#### Frequency & Spike Detection133- Bucket events by hour or minute and calculate the baseline rate134- Flag any window where the event rate is >3× the average — these are anomalous spikes135- Example output: "Error rate spiked 8× at 03:14 — 47 errors in 60 seconds vs. average of 6/min"136137#### Cross-Event Correlation138Link related events that occurred close in time (within 60 seconds):139- SSH failure burst → followed by successful login = **credential stuffing / breach attempt**140- Service restart → followed by error spike = **crash loop with side effects**141- OOM kill → followed by slow query or timeout = **resource starvation cascade**142- UFW block spike → followed by auth failures = **coordinated attack from same actor**143144#### Trend Analysis145If the log spans more than 1 hour:146- Is the error rate increasing, decreasing, or stable?147- Are any IPs showing escalating activity (first scans, then auth attempts, then exploits)?148- Any recurring patterns (same error every hour = likely a broken cron job)?149150#### Filesystem & Kernel Extended Analysis (ext2/ext3/ext4, hardware)151Specifically for kern.log and syslog:152153| Signal | Meaning | Urgency |154|--------|---------|---------|155| `EXT4-fs error` / `EXT3-fs error` | Filesystem corruption | 🔴 Immediate — backup and run `fsck` |156| `Buffer I/O error on dev` | Disk read/write failure | 🔴 Disk may be dying — run `smartctl` |157| `SCSI error` / `ata exception` | Storage controller error | 🔴 Hardware issue |158| `MCE hardware error` | CPU/memory hardware fault | 🔴 Critical hardware failure |159| `EDAC MC` errors | ECC memory errors | 🟠 RAM degrading |160| `soft lockup` / `hard lockup` | Kernel deadlock or hung task | 🟠 System instability |161| `RCU stall` | Real-Time Clock stall — kernel hang | 🟠 Investigate running processes |162| `segfault` at address | Process memory violation | 🟠 App crash or exploit attempt |163| `oom-killer` | Out-of-memory process kill | 🟠 RAM exhaustion |164| `ip_tables: ... table is full` | Firewall rule table overflow | 🟡 Tune conntrack limits |165166For each filesystem/hardware finding, include the exact recommended command to diagnose further.167168#### HTTP / Web Log Pattern Analysis169For nginx and Apache access logs only:170- **Status code distribution**: count 2xx / 3xx / 4xx / 5xx — high 5xx = app problem, high 4xx = scanners/bad clients171- **Top requested paths**: list top 20 URLs — flag any that look like vulnerability scanning (`/.env`, `/wp-login.php`, `/admin`, `/shell`, `/phpinfo.php`)172- **Response size anomalies**: unusually large responses could indicate data exfiltration173- **User-agent analysis**: flag empty user-agents, known scanner agents (Nikto, sqlmap, masscan, zgrab), and headless browser signatures174- **Request rate per IP per minute**: flag IPs exceeding 60 req/min as potential DDoS or scrapers175- **Slow requests**: flag any `request_time` > 5s if log format includes it176177#### Database Log Extended Analysis178For MySQL, PostgreSQL, MongoDB logs:179- List slow queries (>1s) with count and average duration180- Flag `lock wait timeout` — identifies transaction conflicts181- Flag `too many connections` — indicates connection pool exhaustion182- Flag `deadlock found` — requires query/index review183- Replication errors: `Slave_IO_Running: No`, `replication lag`184185---186187## Step 4 — Write Report188189Write the full report to `./log-analysis/report-<log-type>-<YYYYMMDD>.md` in the current working directory.190191Report structure:192```markdown193# Log Analysis Report194**Log type:** [detected type]195**Lines analyzed:** [count]196**Time range:** [first timestamp] → [last timestamp]197**Generated:** [date]198199## Executive Summary200[2–3 sentences: what was found, severity, most important action]201202## Findings by Severity203### 🔴 Critical / Fatal ([count])204[table: timestamp | message | count]205206### 🟠 Errors ([count])207[table: timestamp | message | count]208209### 🟡 Warnings ([count])210[table: top entries]211212## Security Events213[table: threat type | source IP | count | first seen | last seen | verdict]214215## Top IPs216[table: IP | requests | failed auths | successful auths | verdict]217218## Service / Stability Events219[list of crashes, restarts, OOM events with timestamps]220221## Filesystem & Hardware Events222[ext4 errors, disk I/O errors, kernel panics, MCE errors — with recommended diagnostic commands]223224## Extended Analysis225### Anomalous Spikes226[hourly event rate table — flag windows >3× average]227228### Correlated Event Chains229[linked event sequences with timestamps and interpretation]230231### Trend232[is the situation stable, improving, or worsening?]233234### HTTP Pattern Analysis (if web log)235[status code distribution, top paths, scanner activity, suspicious user-agents]236237### Database Analysis (if DB log)238[slow queries, lock waits, connection issues]239240## Notable Events Timeline241[chronological list of the 10–20 most significant events]242243## Recommendations244[numbered, prioritized list — most urgent first]245```246247---248249## Step 5 — Chat Output250251Print ONLY this after writing the report:252253```254✅ Log analysis complete → ./log-analysis/report-[type]-[date].md255256📊 Summary ([N] lines · [time range]):257 🔴 Critical: [count]258 🟠 Errors: [count]259 🟡 Warnings: [count]260 🔵 Notable: [count]261262🔒 Security: [one line — e.g. "47 brute force attempts from 3.4.5.6 — IP should be blocked"]263⚡ Top issue: [one line — e.g. "nginx upstream timeout 23 times between 02:00–03:00"]264265▶ Recommended actions:266 1. [most urgent action]267 2. [second action]268 3. [third action]269270💡 Next: /linux-security-hardener to block attack vectors · /linux-config-auditor to fix misconfigs271```272273If no issues were found:274```275✅ Log analysis complete → ./log-analysis/report-[type]-[date].md276 No critical issues found. [N] lines analyzed, [time range].277```278279---280281## Quick Reference — Common Findings & Actions282283| Finding | Recommended action |284|---------|-------------------|285| SSH brute force from IP X | `ufw deny from X` or add to fail2ban blocklist |286| Root login accepted | Disable `PermitRootLogin` in sshd_config immediately |287| OOM kill of process X | Check RAM usage, add swap, tune process memory limits |288| Disk I/O errors | Run `smartctl -a /dev/sdX` — disk may be failing |289| Nginx upstream timeout | Check app server health, tune `proxy_read_timeout` |290| SSL certificate expired | Run `certbot renew` or check renewal cron job |291| Service restart loop | Check service logs: `journalctl -u service-name -n 100` |292| DB slow queries | Enable slow query log, add indexes, check connection pool |