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.
English | 中文
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
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
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
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
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
更多技能請訪問小蔥技能站7w4.net。
/var/log/, application logs are determined by deployment location)grep/awk for timestamp filtering (logic description only)tail/head for segmented readingAnalysis 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 |
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)
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.
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
Below is the logic description for common log filtering operations, no actual scripts included:
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
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)
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) 框架,提供系統化的日誌分析工作流。
觸發條件: 當以下情況時使用本技能: - 使用者要求「檢查日誌」 - 使用者要求「分析系統執行情況」 - 使用者要求「總結報錯」 - 使用者要求「分享日誌報告」 - 需要排查系統異常問題
支援按以下方式篩選日誌:
- 指定絕對時間範圍(YYYY-MM-DD 到 YYYY-MM-DD)
- 相對時間範圍(今天、昨天、近 3 天、近一週、近一小時等)
- 對於大日誌檔案,按行數偏移讀取
基於 SRE 最佳實踐對異常進行分類: - 可用性異常:服務宕機、5xx 錯誤、連線超時 - 延遲異常:慢查詢、請求耗時過高 - 資源異常:CPU/記憶體使用率過高、磁碟滿、OOM - 限流降級:觸發熔斷、流量被限流 - 依賴異常:第三方服務呼叫失敗、資料庫連線錯誤
基於錯誤率、異常頻次給出 1-5 的系統健康評分: - 5 分:執行良好,無嚴重異常 - 4 分:存在輕微問題,不影響整體可用性 - 3 分:存在中度異常,需要關注 - 2 分:存在嚴重異常,影響部分服務 - 1 分:服務不可用,需要立即處理
根據分析結果,結合 Google SRE 原則給出建議: - 短期措施:緊急處理方案 - 中期措施:監控告警最佳化、容量規劃調整 - 長期措施:架構最佳化、冗餘設計、錯誤預算調整
/var/log/,應用日誌根據部署位置確定)grep/awk 進行時間戳篩選(僅邏輯描述)tail/head 分段讀取基於 Google SRE 框架分析維度:
| 分析維度 | 檢查內容 |
|---|---|
| 錯誤率 | 錯誤日誌佔總日誌比例 |
| 錯誤型別分佈 | 按錯誤型別聚合統計 |
| 錯誤時序 | 錯誤發生的時間分佈,是否突發 |
| 資源使用 | 是否存在資源耗盡情況 |
| 依賴狀態 | 是否因外部依賴故障引發 |
將同類異常合併,避免重複報告: - 按錯誤關鍵詞分組聚合 - 統計每組異常發生次數 - 按影響程度排序(嚴重程度降序)
輸出結構化報告,包含: 1. 分析概覽:分析時間範圍、日誌檔案、資料量 2. 健康評分:整體健康狀況評分 3. 執行總結:正常執行情況概述 4. 異常詳情:按嚴重程度排序的異常列表 5. 改善建議:分短期/中期/長期給出建議
參考輸出模板請見 references/report-template.md
根據使用者需求: - 直接在對話中輸出報告 - 如果需要儲存,可以匯出為 Markdown 檔案 - 可進一步建立為飛書雲文件分享
以下是常見日誌過濾操作的邏輯描述,不包含實際指令碼:
邏輯步驟:
1. 輸入: 日誌檔案路徑, 開始時間, 結束時間
2. 初始化空結果列表
3. 遍歷日誌檔案每一行:
a. 從行中提取時間戳字串
b. 將時間戳解析為日期時間物件
c. 如果 開始時間 <= 日期時間 <= 結束時間:
i. 將行新增到結果列表
4. 輸出: 結果列表
邏輯步驟:
1. 輸入: 日誌行列表
2. 初始化空錯誤列表
3. 定義錯誤關鍵詞: ["ERROR", "FATAL", "SEVERE", "Exception", "Error:"]
4. 遍歷日誌每一行:
a. 如果任何關鍵詞匹配該行:
i. 將行新增到錯誤列表
5. 輸出: 錯誤列表, 錯誤計數 = len(錯誤列表)
邏輯步驟:
1. 輸入: 錯誤行列表
2. 初始化空聚合字典
3. 遍歷每個錯誤行:
a. 從行中提取錯誤型別關鍵詞 (例如: OOM, connection refused, timeout)
b. 如果關鍵詞已在聚合中:
i. 聚合[關鍵詞].count += 1
ii. 將行新增到聚合[關鍵詞].samples
c. 否則:
i. 在聚合中建立新條目,count = 1, samples = [line]
4. 按計數降序排序聚合 (或按嚴重程度)
5. 輸出: 排序後的聚合結果
這個技能整體質量較好,勝在基於專業的 SRE 方法論提供了系統化的日誌分析思路和清晰的改善建議框架。不過它更像一份詳細的設計文件而非可直接使用的工具,需要使用者自行寫程式碼實現核心功能才能真正執行。如果你具備一定技術能力,能按文件指引實現日誌解析指令碼,這個技能會很有價值;如果你期望下載後直接分析日誌,可能會有所失望。