惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
Microsoft Azure Blog
Microsoft Azure Blog
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LangChain Blog
P
Privacy & Cybersecurity Law Blog
Hugging Face - Blog
Hugging Face - Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
A
Arctic Wolf
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
The GitHub Blog
The GitHub Blog
P
Privacy International News Feed
WordPress大学
WordPress大学
U
Unit 42
S
Securelist
T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Latest news
Latest news
Hacker News: Ask HN
Hacker News: Ask HN
小众软件
小众软件
Know Your Adversary
Know Your Adversary
The Cloudflare Blog
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
Security Latest
Security Latest
Google DeepMind News
Google DeepMind News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - Franky
Y
Y Combinator Blog
博客园 - 叶小钗
Security Archives - TechRepublic
Security Archives - TechRepublic
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
S
Secure Thoughts
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
M
MIT News - Artificial intelligence

杂烩饭

superpowers Nexus仓库搭建记录 Git Merge代码冲突的解决方式 在 Linux 系统中安装与配置 OpenVPN:从入门到精通 使用 Easytier-web 管理 easytier 节点 ingress-nginx 去除指定context path 在macOS上使用MusicPlayer2听本地音乐 Kubernetes 1.34 + RHEL10 + Cilium + kube-vip 高可用集群部署 容器调试工具之BusyBox 无Docker环境进行容器镜像操作 使用kubeadm部署一套高可用k8s集群1.34 for Ubuntu 正在运行的Docker容器增加端口映射 轻量级组网工具WireGuard 在Kubernetes中部署一个单节点Elasticsearch 使用openssl制作自签名双向认证(mTLS)证书 minio自建对象存储 ingress-nginx 使用自定义的nginx配置 P12格式证书与PEM格式转换 使用blackbox-exporter做域名监控 记一次MySQL字符集转换导致的故障 使用双向认证增加git仓库安全性 Prometheus自动监控K8S集群中的service Grafana 查询SQL 自定义变量 使用selenium来实现Grafana的自动截图
使用腾讯云CLS收集TKE(k8s)业务日志
张理坤 · 2026-01-07 · via 杂烩饭

使用 CLS 来采集业务日志的好处有

  1. 运维方便,不用费劲搭建 ELK 系统,传统的 filebeat -> kafka -> logstash -> ElasticSearch 架构复杂
  2. 费用便宜(和 ES、kafka 这一套相比)
  3. 不用担心告警等(如 ES 磁盘使用率等)

开启采集

在集群管理界面,点击 日志 新增采集配置:

PixPin_2026-01-07_21-38-41.png

然后选择日志源、元数据等,点击下一步,配置日志解析方式。

如果是纯 json 日志,就配置成 json 格式解析。业务日志是 Spring Boot,并且包含多行日志,所以选择 多行 - 完全正则 模式来匹配。

PixPin_2026-01-07_21-30-40.png

点击完成后就完成了日志采集。

多行正则模式匹配

假设业务日志格式为:

1
2
3
4
5
6
7
8
2026-01-07 20:58:29.335  INFO [tsp-agent,517f1bd4b38282b2,e66be3ada6f121cf,true] [XNIO-1 task-7] c.example.nub.webmvc.filter.PrintFilter   [145]: 响应
ResponseHeader:
Transfer-Encoding: chunked
Connection: keep-alive
Date: Wed, 07 Jan 2026 12:58:29 GMT
Content-Type: application/json
Body:
{"code":0,"message":"成功","data":{"nkUserId":"158c440b431d482a8a738f82caf2f638","nkUserTicket":"2bb5003769864887a90f615a7381d253","expiresAt":1767790769}}

那么我们需要的日志字段有(按日志顺序):

  1. 2026-01-07 20:58:29.335 日志时间
  2. INFO 日志级别
  3. [服务名,TraceId, SpanId, 不知道是什么字段]
  4. [XNIO-1 task-7] XNIO:是 XNIO 框架的线程池 task-7:线程池中的第 7 个工作线程
  5. c.example.nub.webmvc.filter.PrintFilter 哪个类打印出来的
  6. [145] 上面的 java 类的第 145 行打印的日志
  7. 冒号 : 后面的是日志原文了,多行的

根据这个,写一个正则,然后点击提取验证。

1
(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\s+(\w+)\s+\[([^,\]]*),([^,\]]*),([^,\]]*),[^,\]]*\]\s+\[[^\]]+\]\s+([^\s[]+)\s*\[\d+\]:\s*(.*)

需要的字段,用括号 () 包起来,点击提取验证,下面就会有示例:

PixPin_2026-01-07_21-35-01.png

给提取到的日志起个 Key 名

PixPin_2026-01-07_21-36-00.png

然后到 CLS 日志 -> 检索分析里面,可以看到日志字段都成功解析了。

PixPin_2026-01-07_21-37-40.png

Ingress Nginx 访问日志采集

比如想采集 ingress-nginx 的访问日志,需要先配置 ingress controller 的日志输出格式(Nginx 同理)。然后再进行采集,日志解析格式为 json 即可。

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 杂烩饭