一,mtail的用途?

mtail :从应用程序日志中提取指标以导出到时间序列数据库或时间序列计算器
它是一个google开发的日志提取工具,用途就是:
实时读取应用程序的日志、
再通过自己编写的脚本进行分析、
最终生成时间序列指标
 

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,下载mtail

1,mtail的官方站:
https://github.com/google/mtail
2,下载:
[root@SearchCacheServer ~]# cd /usr/local/source/
[root@SearchCacheServer source]# mkdir mtail
[root@SearchCacheServer source]# cd mtail/
[root@SearchCacheServer mtail]# wget https://github.com/google/mtail/releases/download/v3.0.0-rc35/mtail_v3.0.0-rc35_linux_amd64

三,安装mtail

1,增加可执行权限
[root@SearchCacheServer mtail]# chmod 744 mtail_v3.0.0-rc35_linux_amd64
2,把mtail可执行程序移动到安装目录
[root@SearchCacheServer mtail]# mkdir /usr/local/soft/mtail_v3.0.0-rc35_linux_amd64
[root@SearchCacheServer mtail]# mv mtail_v3.0.0-rc35_linux_amd64 /usr/local/soft/mtail_v3.0.0-rc35_linux_amd64/mtail
3,测试程序是否可以运行?查看mtail版本
[root@SearchCacheServer mtail]# /usr/local/soft/mtail_v3.0.0-rc35_linux_amd64/mtail --version
mtail version v3.0.0-rc35 git revision a33283598c4b7a70fc2f113680318f29d5826cca go version go1.14 go arch amd64 go os linux

四,运行mtail

1,创建目录,保存mtail程序
[root@SearchCacheServer phplogs]# mkdir -p /data/mtail/prog
[root@SearchCacheServer phplogs]# cd /data/mtail/prog/
[root@SearchCacheServer prog]# vi error_count.mtail
内容:
counter error_count

/ERROR/ {
error_count++
}

说明:error_count变量值统计了包含ERROR字串的行

说明:
mtail的例子,请参考:
https://github.com/google/mtail/tree/master/examples
2,运行mtail
[root@SearchCacheServer prog]# nohup /usr/local/soft/mtail_v3.0.0-rc35_linux_amd64/mtail -logtostderr -progs /data/mtail/prog/error_count.mtail -logs /data/logs/phplogs/prd_mobile_php_errors.log &
3,检查启动是否成功
[root@SearchCacheServer prog]# ss -lntp | grep mtail
LISTEN 0 128 *:3903 *:* users:(("mtail",27642,11))
已经守护在了3903
 
4,查看mtail的相关信息
http://121.122.123.118:3903/
mtail输出的metrics
http://121.122.123.118:3903/metrics

五,配置prometheus

[root@blog ~]# cd /usr/local/soft/prometheus-2.18.1.linux-amd64/
[root@blog prometheus-2.18.1.linux-amd64]# vi prometheus.yml
在scrape_configs下新增一个job
  - job_name: '118mtail'
static_configs:
- targets: ['121.122.123.118:3903'] 
 
重启prometheus服务
[root@blog prometheus-2.18.1.linux-amd64]# systemctl restart prometheus.service
我们可以通过prometheus查询error_count的值:
访问:注意把ip换成自己机器的ip
http://121.122.123.47:9090/graph
如图:
 
 

六,增加对alertmanager报警的配置

1,在rule文件中增加新的报警配置
[root@blog rules]# pwd
/data/prometheus/rules
[root@blog rules]# vi rule.yml
内容:
  - alert: ErrorlogStatus # alert 名字
expr: error_count{job="118mtail"} > 0 # 判断条件
for: 10s # 条件保持 10s 才会发出 alter
labels: # 设置 alert 的标签
severity: "critical"
annotations: # alert 的其他标签,但不用于标识 alert
description: php log error more than 20s
summary: php have error

说明:error_count>0是触发报警的条件

 
2,检查配置:
[root@blog prometheus-2.18.1.linux-amd64]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 1 rule files found Checking /data/prometheus/rules/rule.yml
SUCCESS: 2 rules found
说明:也可以只检查rule配置文件:
[root@blog prometheus-2.18.1.linux-amd64]# ./promtool check rules /data/prometheus/rules/rule.yml
Checking /data/prometheus/rules/rule.yml
SUCCESS: 2 rules found
3,重启prometheus服务
[root@blog rules]# systemctl restart prometheus.service   
配置alertmanager部分请参考这一篇:
https://www.cnblogs.com/architectforest/p/13065262.html

七,查看prometheus的版本

[root@blog ~]# /usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus --version
prometheus, version 2.18.1 (branch: HEAD, revision: ecee9c8abfd118f139014cb1b174b08db3f342cf)
build user: root@2117a9e64a7e
build date: 20200507-16:51:47
go version: go1.14.2

八,查看linux的版本

[root@blog ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

linux(centos8):prometheus使用mtail监控错误日志的更多相关文章

  1. MS SQL 监控错误日志的告警信息

    SQL Server的错误消息(Error Message)按照消息的严重级别一共划分25个等级,级别越高,表示严重性也越高.但是如果你统计sys.messages,你会发现,实际上只有16(SQL ...

  2. 2. SQL Server数据库状态监控 - 错误日志

    原文:2. SQL Server数据库状态监控 - 错误日志 无论是操作系统 (Unix 或者Windows),还是应用程序 (Web 服务,数据库系统等等) ,通常都有自身的日志机制,以便故障时追溯 ...

  3. linux(centos8):zabbix配置邮件报警(监控错误日志)(zabbix5.0)

    一,zabbix5.0发邮件报警的准备工作: zabbix5.0在linux平台上的安装:参见这一篇: https://www.cnblogs.com/architectforest/p/129125 ...

  4. linux(centos8):prometheus使用alertmanager发送报警邮件(prometheus 2.18.1/alertmanager 0.20.0)

    一,alertmanager的用途 1,Alertmanager的作用: Alertmanager是一个独立的报警模块, 它接收Prometheus等客户端发来的警报,并通过分组.删除重复等处理, 通 ...

  5. Python自动监控错误日志

    平时在查看日志的时候打开满屏的日志,看上去有点凌乱.于是写个Python脚本过滤出想要看的错误的日志.直接上脚本 脚本示例 def read_log(logname,keyword): tell = ...

  6. mtail 提取应用日志数据到时序数据库的工具-支持prometheus

    mtail 是谷歌开源的一款很不错的应用日志提取工具,我们可以方便的用来提取应用的数据 到常见的监控系统(prometheus,stats,collectd,gragphite....) 说明: de ...

  7. 记-Windows环境下Prometheus+alertmanager+windows_exporter+mtail监控部署

    1.概述 最近因项目需要统计服务的负载情况及机器的负载情况,但是项目里面却没有相关统计而服务所在的机器也没有相关的监控,因为工期原因就选择了相对轻量级的prometheus方案.其中windows_e ...

  8. 在Linux系统上查看Apache服务器的错误日志

    错误日志和访问日志文件为系统管理员提供了有用的信息,比如,为 Web 服务器排障,保护系统不受各种各样的恶意活动侵犯,或者只是进行各种各样的分析以监控 HTTP 服务器.根据你 Web 服务器配置的不 ...

  9. Grafana+Prometheus通过node_exporter监控Linux服务器信息

    Grafana+Prometheus通过node_exporter监控Linux服务器信息 一.Grafana+Prometheus通过node_exporter监控Linux服务器信息 1.1nod ...

随机推荐

  1. python 手把手教你基于搜索引擎实现文章查重

    前言 文章抄袭在互联网中普遍存在,很多博主都收受其烦.近几年随着互联网的发展,抄袭等不道德行为在互联网上愈演愈烈,甚至复制.黏贴后发布标原创屡见不鲜,部分抄袭后的文章甚至标记了一些联系方式从而使读者获 ...

  2. python中gui编程的模块之一:tkinter(python3.x中是tkinter,小写的t)

    一.tkinter是python的标准gui库,tkinter是内置在python的安装包之中的,所以安装好python之后就可以import导入tkinter模块了 二.创建一个GUI程序 1.导入 ...

  3. [Codeforces1174B]Ehab Is an Odd Person

    题目链接 https://codeforces.com/contest/1174/problem/B 题意 给一个数组,只能交换和为奇数的两个数,问最终能得到的字典序最小的序列. 题解 内心OS:由题 ...

  4. (数据科学学习手札95)elyra——jupyter lab最强插件

    本文示例文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 jupyter lab是我最喜欢的编辑器,在过往 ...

  5. spring标签之SCOPEprototype

    默认情况下,从 bean工厂所取得的实例为Singleton(bean的singleton属性) Singleton: Spring容器只存在一个共享的bean实例,默认的配置. Prototype: ...

  6. springboot maven项目运行常见报错 及ajax请求报错

    如图所示 tomcat运行后直接停止,也不报错 原因:我的原因是controller路径配置重名或者service没有配置@Service 遇见这错找了好久问题,网上也搜不到,特此记录一下 问题2 a ...

  7. get 跟post的区别

    get参数通过url传递,post放在request body中 :get请求在url中传递的参数是有长度限制的,而post没有.

  8. SpringBoot-03-JSR303数据校验和多环境切换

    3.3 JSR303数据校验 先看如何使用 ​ Springboot中可以用@Validated来校验数据,如果数据异常则统一抛出异常,方便异常中心统一处理. ​ 这里我们写个注解让name只支持Em ...

  9. Activiti工作流系统环境搭建

    一.创建Activiti工程,并导入Activiti包及数据库驱动包 二.用代码方式创建 流程引擎 1 @Test 2 public void createProcessEngineWithCode( ...

  10. matlab中polyfit

    来源:https://ww2.mathworks.cn/help/matlab/ref/polyfit.html?searchHighlight=polyfit&s_tid=doc_srcht ...