Extract structured metrics from unstructured logs using regex patterns, output Prometheus/JSON format. / 使用正则从非结构化日志中提取结构化指标,输出 Prometheus/JSON 格式。
---
name: log-parser-to-metrics
description: "Extract structured metrics from unstructured logs using regex patterns, output Prometheus/JSON format. / 使用正则从非结构化日志中提取结构化指标,输出 Prometheus/JSON 格式。"
version: 1.0.0
topics: [logging,metrics,prometheus,parsing,日志解析,指标提取]
metadata:
openclaw:
requires:
bins:
- bash
- curl
emoji: "📊"
homepage: https://kingai.work/
install: []
---
# 📊 Log Parser to Metrics / 日志转指标工具
> Extract structured metrics from unstructured logs using regex patterns, output Prometheus/JSON format. / 使用正则从非结构化日志中提取结构化指标,输出 Prometheus/JSON 格式。
> 🦁 **由 KingAI.Work 出品** — 智能进化|vip@kingai.work
---
## Overview / 概览
• Parse logs in real-time with custom regex patterns / 支持自定义正则实时解析日志,零延迟提取关键指标数据
• Export to Prometheus format for monitoring integration / 直接输出Prometheus兼容格式,无缝对接主流监控系统
• Support JSON and CSV output for data processing / 输出JSON/CSV格式,方便下游数据清洗和可视化工具使用
• Handle multi-line logs and timestamp normalization / 智能处理多行日志与时间戳标准化,避免解析断层
• Advanced aggregation engine for complex metrics computation (Pro) / 高级聚合引擎支持复杂指标计算,如百分位、滑动窗口统计(Pro专属)
• Batch processing mode for high-volume log files (Pro) / 批量处理模式专为海量日志设计,性能提升10倍(Pro解锁)
## How It Works / 原理
```bash
# Step 1 — check environment
which bash curl && echo "Ready"
# Step 2 — run the tool
tail -f /var/log/nginx/access.log | log-parser-to-metrics --pattern '{ip} - - [{time}] "{method} {path}" {status} {size}' --output prometheus This command streams Nginx access logs and converts each line into a Prometheus metric with labels for IP, method, path, and status. / 该命令实时读取Nginx访问日志,将每行转换为带IP、方法、路径、状态标签的Prometheus指标。
# Step 3 — review output
echo "Done — check the generated output"
```
## Example Scenarios / 示例场景
• Debugging production issues: Engineer needs to monitor specific error patterns across 100+ servers — parse error logs into request-rate and latency metrics instantly / 生产问题排查:工程师需要监控100+台服务器的特定错误模式——即时将错误日志解析为请求率和延迟指标
• Cost optimization: DevOps team wants to identify underutilized API endpoints from massive access logs — extract endpoint call frequency and response sizes / 成本优化:运维团队从海量访问日志中找出低效API端点——提取端点调用频率和响应大小
• Security auditing: Security analyst needs to detect brute-force attacks from auth logs — parse failed login attempts into a time-series metric with attacker IP / 安全审计:安全分析师从认证日志中检测暴力破解——将失败登录解析为含攻击者IP的时间序列指标
## Plans / 版本
| Capability | Free | Pro |
|-----------|:----:|:---:|
| Basics / 基础 | ✅ | ✅ |
| Automation / 自动化 | — | ✅ |
| AI / AI 功能 | — | ✅ |
| Support | Community | Priority |
• Unlock advanced regex engine with named capturing groups and conditional logic
解锁高级正则引擎,支持命名捕获组和条件逻辑,处理复杂日志更高效
• Get access to real-time streaming pipeline with Kafka and WebSocket support
获取Kafka和WebSocket实时流处理能力,秒级响应海量日志涌入
• Enable batch processing with auto-parallelism and compression handling
开启自动并行与压缩处理的批量分析模式,将日志解析性能推向极致\n\n
📦 *Published by King AI — kingai.work*
don't have the plugin yet? install it then click "run inline in claude" again.