SRE Log Analytics

👤 rory yu 📦 v0.1.0 ⭐ 4.1 ⬇️ 756 下載
🔒 IT運維與安全 免費

📖 技能介紹


name: system-log-analytics description: 系統日誌分析技能,基於 Google SRE 框架對特定時間段的日誌進行檢查、總結系統執行情況、分析主要報錯異常,並給出改善意見。使用場景:需要檢查系統日誌、分享執行總結、排查異常問題、獲取最佳化建議。System log analytics skill, based on Google SRE framework, checks logs for specific time periods, summarizes system operation, analyzes major errors and exceptions, and provides improvement suggestions. Usage scenarios: need to check system logs, share operation summary, troubleshoot exceptions, get optimization suggestions.


System Log Analytics | 系統日誌分析

English | 中文


English

Overview

This skill provides a systematic log analysis workflow based on Google SRE (Site Reliability Engineering) framework.

Trigger Conditions: Use this skill when: - User asks to "check logs" - User asks to "analyze system operation" - User asks to "summarize errors" - User asks to "share a log report" - Need to troubleshoot abnormal system problems

Core Capabilities

1. Time Range Filtering

Support filtering logs by the following methods: - Specify absolute time range (YYYY-MM-DD to YYYY-MM-DD) - Relative time range (today, yesterday, last 3 days, last week, last hour, etc.) - Read by line offset for large log files

2. Exception Classification and Aggregation

Classify exceptions based on SRE best practices: - Availability exceptions: Service outage, 5xx errors, connection timeout - Latency exceptions: Slow queries, high request latency - Resource exceptions: High CPU/memory usage, disk full, OOM - Rate limiting & degradation: Circuit breaker triggered, traffic throttled - Dependency exceptions: Third-party service call failure, database connection error

3. Health Scoring

Give a 1-5 system health score based on error rate and exception frequency: - 5 points: Running well, no serious exceptions - 4 points: Minor issues exist, does not affect overall availability - 3 points: Moderate exceptions exist, needs attention - 2 points: Serious exceptions exist, affects partial services - 1 point: Service unavailable, needs immediate handling

4. Improvement Suggestions

Provide suggestions based on Google SRE principles: - Short-term measures: Emergency handling plan - Mid-term measures: Monitoring and alert optimization, capacity planning adjustment - Long-term measures: Architecture optimization, redundancy design, error budget adjustment

Workflow

Step 1: Get Logs

更多技能請訪問小蔥技能站7w4.net。

  1. Determine the log file path (system logs are usually in /var/log/, application logs are determined by deployment location)
  2. Filter log content according to time range
  3. Use grep/awk for timestamp filtering (logic description only)
  4. For large log files, use tail/head for segmented reading

Step 2: Structured Analysis

Analysis dimensions based on Google SRE framework:

Analysis Dimension Check Content
Error Rate Proportion of error logs in total logs
Error Type Distribution Aggregate statistics by error type
Error Timing Time distribution of errors, whether sudden
Resource Usage Whether resource exhaustion exists
Dependency Status Whether it is caused by external dependency failure

Step 3: Exception Aggregation

Merge similar exceptions to avoid duplicate reporting: - Group by error keyword - Count the number of occurrences of each group of exceptions - Sort by impact (descending order of severity)

Step 4: Generate Report

Output structured report including: 1. Analysis Overview: Analysis time range, log file, data volume 2. Health Score: Overall health score 3. Operation Summary: Overview of normal operation 4. Exception Details: Sorted list of exceptions by severity 5. Improvement Suggestions: Short-term/mid-term/long-term suggestions

See references/report-template.md for reference output template.

Step 5: Share Report

According to user needs: - Output the report directly in the conversation - If you need to save, you can export it as a Markdown file - Can be further created as a Feishu cloud document for sharing

Filtering Logic Description

Below is the logic description for common log filtering operations, no actual scripts included:

1. Filter by Time Range

Logic Steps:
1. Input: log_file_path, start_time, end_time
2. Initialize empty result list
3. For each line in log_file:
   a. Extract timestamp string from the line
   b. Parse timestamp to datetime object
   c. If start_time <= datetime <= end_time:
       i. Add line to result list
4. Output: result list

2. Extract Error Logs

Logic Steps:
1. Input: log_lines
2. Initialize empty error list
3. Define error keywords: ["ERROR", "FATAL", "SEVERE", "Exception", "Error:"]
4. For each line in log_lines:
   a. If any keyword matches the line:
       i. Add line to error list
5. Output: error list, error_count = len(error_list)

3. Aggregate Exceptions by Keyword

Logic Steps:
1. Input: error_lines
2. Initialize empty aggregation dictionary
3. For each line in error_lines:
   a. Extract error type keyword from line (e.g., OOM, connection refused, timeout)
   b. If keyword exists in aggregation:
       i. aggregation[keyword].count += 1
       ii. Add line to aggregation[keyword].samples
   c. Else:
       i. Create new entry in aggregation with count = 1, samples = [line]
4. Sort aggregation by count descending (or by severity)
5. Output: sorted aggregation result

中文

概述

本技能基於 Google SRE (Site Reliability Engineering) 框架,提供系統化的日誌分析工作流。

觸發條件: 當以下情況時使用本技能: - 使用者要求「檢查日誌」 - 使用者要求「分析系統執行情況」 - 使用者要求「總結報錯」 - 使用者要求「分享日誌報告」 - 需要排查系統異常問題

核心能力

1. 時間範圍過濾

支援按以下方式篩選日誌: - 指定絕對時間範圍(YYYY-MM-DDYYYY-MM-DD) - 相對時間範圍(今天、昨天、近 3 天、近一週、近一小時等) - 對於大日誌檔案,按行數偏移讀取

2. 異常分類與聚合

基於 SRE 最佳實踐對異常進行分類: - 可用性異常:服務宕機、5xx 錯誤、連線超時 - 延遲異常:慢查詢、請求耗時過高 - 資源異常:CPU/記憶體使用率過高、磁碟滿、OOM - 限流降級:觸發熔斷、流量被限流 - 依賴異常:第三方服務呼叫失敗、資料庫連線錯誤

3. 執行狀況評分

基於錯誤率、異常頻次給出 1-5 的系統健康評分: - 5 分:執行良好,無嚴重異常 - 4 分:存在輕微問題,不影響整體可用性 - 3 分:存在中度異常,需要關注 - 2 分:存在嚴重異常,影響部分服務 - 1 分:服務不可用,需要立即處理

4. 改善建議輸出

根據分析結果,結合 Google SRE 原則給出建議: - 短期措施:緊急處理方案 - 中期措施:監控告警最佳化、容量規劃調整 - 長期措施:架構最佳化、冗餘設計、錯誤預算調整

工作流

步驟 1: 獲取日誌

  1. 確定日誌檔案路徑(系統日誌通常在 /var/log/,應用日誌根據部署位置確定)
  2. 根據時間範圍過濾日誌內容
  3. 使用 grep/awk 進行時間戳篩選(僅邏輯描述)
  4. 對於大日誌檔案,使用 tail/head 分段讀取

步驟 2: 結構化分析

基於 Google SRE 框架分析維度:

分析維度 檢查內容
錯誤率 錯誤日誌佔總日誌比例
錯誤型別分佈 按錯誤型別聚合統計
錯誤時序 錯誤發生的時間分佈,是否突發
資源使用 是否存在資源耗盡情況
依賴狀態 是否因外部依賴故障引發

步驟 3: 異常聚合

將同類異常合併,避免重複報告: - 按錯誤關鍵詞分組聚合 - 統計每組異常發生次數 - 按影響程度排序(嚴重程度降序)

步驟 4: 生成報告

輸出結構化報告,包含: 1. 分析概覽:分析時間範圍、日誌檔案、資料量 2. 健康評分:整體健康狀況評分 3. 執行總結:正常執行情況概述 4. 異常詳情:按嚴重程度排序的異常列表 5. 改善建議:分短期/中期/長期給出建議

參考輸出模板請見 references/report-template.md

步驟 5: 分享報告

根據使用者需求: - 直接在對話中輸出報告 - 如果需要儲存,可以匯出為 Markdown 檔案 - 可進一步建立為飛書雲文件分享

過濾邏輯描述

以下是常見日誌過濾操作的邏輯描述,不包含實際指令碼:

1. 按時間範圍過濾

邏輯步驟:
1. 輸入: 日誌檔案路徑, 開始時間, 結束時間
2. 初始化空結果列表
3. 遍歷日誌檔案每一行:
   a. 從行中提取時間戳字串
   b. 將時間戳解析為日期時間物件
   c. 如果 開始時間 <= 日期時間 <= 結束時間:
       i. 將行新增到結果列表
4. 輸出: 結果列表

2. 提取錯誤日誌

邏輯步驟:
1. 輸入: 日誌行列表
2. 初始化空錯誤列表
3. 定義錯誤關鍵詞: ["ERROR", "FATAL", "SEVERE", "Exception", "Error:"]
4. 遍歷日誌每一行:
   a. 如果任何關鍵詞匹配該行:
       i. 將行新增到錯誤列表
5. 輸出: 錯誤列表, 錯誤計數 = len(錯誤列表)

3. 按關鍵詞聚合異常

邏輯步驟:
1. 輸入: 錯誤行列表
2. 初始化空聚合字典
3. 遍歷每個錯誤行:
   a. 從行中提取錯誤型別關鍵詞 (例如: OOM, connection refused, timeout)
   b. 如果關鍵詞已在聚合中:
       i. 聚合[關鍵詞].count += 1
       ii. 將行新增到聚合[關鍵詞].samples
   c. 否則:
       i. 在聚合中建立新條目,count = 1, samples = [line]
4. 按計數降序排序聚合 (或按嚴重程度)
5. 輸出: 排序後的聚合結果

🤖 AI 評測

這個技能整體質量較好,勝在基於專業的 SRE 方法論提供了系統化的日誌分析思路和清晰的改善建議框架。不過它更像一份詳細的設計文件而非可直接使用的工具,需要使用者自行寫程式碼實現核心功能才能真正執行。如果你具備一定技術能力,能按文件指引實現日誌解析指令碼,這個技能會很有價值;如果你期望下載後直接分析日誌,可能會有所失望。

📊 多維度評分

適應性4
規範性4
有效性4.1
可靠性3.7
可信度5

📁 包含檔案 (5 個)

📄 README.md 5.9 KB
📄 SKILL.md 10 KB
📄 _meta.json 136 B
📄 references/report-template.md 1.4 KB
📄 references/sre-principles.md 7.4 KB