| 用途 | 结构化查询与统计 journal |
|---|---|
| 语法 | journalctl -o json [--output-fields=…] |
| 工具 | jq / python) |
常用示例
常用示例
# 只看需要的字段
journalctl -u nginx -o json --output-fields=_PID,SYSLOG_IDENTIFIER,MESSAGE -n 5 | jq -c .
# 统计某 unit 各优先级条数
journalctl -u myapp -o json --since today | jq -r '._PRIORITY' | sort | uniq -c
# 按错误文本过滤(含 json 转义处理)
journalctl -u myapp -o json --since '1 hour ago' | jq -r 'select(.MESSAGE | test("timeout")) | .MESSAGE'jq 不在最小化系统里时先用 -o json-pretty 人肉看,或导出到本地分析。