V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
wsgzao
V2EX  ›  Linux

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

  •  
  •   wsgzao ·
    wsgzao · 2021-08-11 15:19:12 +08:00 · 1502 次点击
    这是一个创建于 981 天前的主题,其中的信息可能已经有所发展或是发生改变。

    前言

    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/

    1 条回复    2021-08-11 20:56:28 +08:00
    liuxu
        1
    liuxu  
       2021-08-11 20:56:28 +08:00
    写等于没写,直接看官方文档,挺好,带正则的 log 拆分器,有点 nginx vhost 的味道
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   960 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:46 · PVG 04:46 · LAX 13:46 · JFK 16:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.