Google mtail 配合 Prometheus 和 Grafana 实现自定义日志监控

2021-08-11 15:19:12 +08:00
 wsgzao

前言

mtail 是一个 Google 开发的日志提取工具,相比 ELK/EFK/Grafana Loki 来说会更轻量。因为我遇到的需求只是为了采集生产日志中的数据,所以采用更为简单的 mtail 配合 Prometheus 和 Grafana 实现自定义日志数据监控。

更新历史

2021 年 08 月 04 日 - 初稿

阅读原文 - https://wsgzao.github.io/post/mtail/


常见的日志监控解决方案

开源的业务日志监控,我重点推荐以下 3 个

值得注意的是 ELK 目前有被 EFK 取代的趋势

1:ELK-“ELK”是三个开源项目的首字母缩写,这三个项目分别是:Elasticsearch 、Logstash 和 Kibana 。

Elasticsearch 是一个搜索和分析引擎。

Logstash 是服务器端数据处理管道,能够同时从多个来源采集数据,转换数据,然后将数据发送到诸如 Elasticsearch 等“存储库”中。

Kibana 则可以让用户在 Elasticsearch 中使用图形和图表对数据进行可视化。

2:Loki,Grafana Labs 团队最新的开源项目,是一个水平可扩展,高可用性,多租户的日志聚合系统。

3:mtail :它是一个 google 开发的日志提取工具,从应用程序日志中提取指标以导出到时间序列数据库或时间序列计算器,

用途就是: 实时读取应用程序的日志、 再通过自己编写的脚本进行分析、 最终生成时间序列指标。

工具适合自己的才是最好的,无论是 EFK 还是 Loki 都是功能齐全的日志采集系统,当然它们也有各自的优势,

Blog 中记录了一些使用经验大家可以参考

Scribe 安装使用 - https://wsgzao.github.io/post/scribe/

使用 ELK(Elasticsearch + Logstash + Kibana) 搭建日志集中分析平台实践 - https://wsgzao.github.io/post/elk/

开源日志管理方案 ELK 和 EFK 的区别 - https://wsgzao.github.io/post/efk/

Grafana Loki 开源日志聚合系统代替 ELK 或 EFK - https://wsgzao.github.io/post/loki/

mtail 简介

mtail - extract whitebox monitoring data from application logs for collection into a timeseries database

mtail is a tool for extracting metrics from application logs to be exported into a timeseries database or timeseries calculator for alerting and dashboarding.

It fills a monitoring niche by being the glue between applications that do not export their own internal state (other than via logs) and existing monitoring systems, such that system operators do not need to patch those applications to instrument them or writing custom extraction code for every such application.

The extraction is controlled by mtail programs which define patterns and actions:

# simple line counter
counter lines_total
/$/ {
  lines_total++
}

Metrics are exported for scraping by a collector as JSON or Prometheus format over HTTP, or can be periodically sent to a collectd, StatsD, or Graphite collector socket.

mtail 是用于从应用程序日志中提取指标以导出到时间序列数据库或时间序列计算器以进行警报和仪表板显示的工具。简单来说,就是实时读取应用程序的日志,并且通过自己编写的脚本实时分析,最终生成时间序列指标的工具。

https://github.com/google/mtail

mtail 安装

下载地址: https://github.com/google/mtail/releases

# check latest version from github
wget https://github.com/google/mtail/releases/download/v3.0.0-rc47/mtail_3.0.0-rc47_Linux_x86_64.tar.gz

tar xf mtail_3.0.0-rc47_Linux_x86_64.tar.gz
# can choose to cp mtail to /usr/local/bin
# cp mtail /usr/local/bin

# 查看 mtail 版本
./mtail --version
mtail version 3.0.0-rc47 git revision 5e0099f843e4e4f2b7189c21019de18eb49181bf go version go1.16.5 go arch amd64 go os linux

# mtail 后台启动
nohup mtail -port 3903 -logtostderr -progs test.mtail -logs test.log &

# 默认端口是 3903
nohup ./mtail -progs test.mtail -logs test.log &

# 查看是否启动成功
ps -ef | grep mtail


内容较多就不全部复制了,各位感兴趣可以再继续阅读原文链接

https://wsgzao.github.io/post/mtail/

1638 次点击
所在节点    Linux
1 条回复
liuxu
2021-08-11 20:56:28 +08:00
写等于没写,直接看官方文档,挺好,带正则的 log 拆分器,有点 nginx vhost 的味道

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/795096

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX