mtail统计nginx访问日志

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介:

mtail是一个可以从应用程序日志中提取指标,并将其导出到时间序列数据库或时间序列计算器中,以便配置警报和仪表盘的工具。

它的目的在于填补没有导出自己内部状态的应用程序和已有监控系统之间的空白,由于有自定义抽取粘合代码,无修改应用程序或重写相同的框架。

提取由定义了模式和动作的mtail程序来控制。

安装方法

预编译的二进制文件

推荐使用最新的生产版本二进制文件安装mtail。可按需选择对应Windows,OSX和Linux等系统版本。

源码编译

需要安装运行版本不低于1.9的Go环境。如果不想在本地环境中安装Go,也可以选择Dockerfile。

下载编译好的二进制文件后运行即可

# nohup ./mtail -progs /path/to/mtailprograms -logs /path/to/logfile &
# cat /path/to/mtailprograms
counter nginx_line_count
#正则统计访问日志的行数,可以在grafana中配置视图观察访问量趋势
/$/ {
  nginx_line_count++
}
# ./mtail -h
mtail version v3.0.0-rc12 git revision 936050df9856da258f13e5df71a5a0c7f8f6acdc go version go1.10.1

Usage:
  -address string
        Host or IP address on which to bind HTTP listener
  -alsologtostderr
        log to standard error as well as files
  -block_profile_rate int
        Nanoseconds of block time before goroutine blocking events reported. 0 turns off.  See https://golang.org/pkg/runtime/#SetBlockProfileRate
  -collectd_prefix string
        Prefix to use for collectd metrics.
  -collectd_socketpath string
        Path to collectd unixsock to write metrics to.
  -compile_only
        Compile programs only, do not load the virtual machine.
  -dump_ast
        Dump AST of programs after parse (to INFO log).
  -dump_ast_types
        Dump AST of programs with type annotation after typecheck (to INFO log).
  -dump_bytecode
        Dump bytecode of programs (to INFO log).
  -emit_prog_label
        Emit the 'prog' label in variable exports. (default true)
  -graphite_host_port string
        Host:port to graphite carbon server to write metrics to.
  -graphite_prefix string
        Prefix to use for graphite metrics.
  -log_backtrace_at value
        when logging hits line file:N, emit a stack trace
  -log_dir string
        If non-empty, write log files in this directory
  -logfds value
        List of file descriptor numbers to monitor, separated by commas.  This flag may be specified multiple times.
  -logs value
        List of log files to monitor, separated by commas.  This flag may be specified multiple times.
  -logtostderr
        log to standard error instead of files
  -metric_push_interval_seconds int
        Interval between metric pushes, in seconds. (default 60)
  -metric_push_write_deadline duration
        Time to wait for a push to succeed before exiting with an error. (default 10s)
  -mtailDebug int
        Set parser debug level.
  -mutex_profile_fraction int
        Fraction of mutex contention events reported.  0 turns off.  See http://golang.org/pkg/runtime/#SetMutexProfileFraction
  -one_shot
        Compile the programs, then read the contents of the provided logs from start until EOF, print the values of the metrics store and exit. This is a debugging flag only, not for production use.
  -one_shot_metrics
        DEPRECATED: Dump metrics (to stdout) after one shot mode.
  -override_timezone string
        If set, use the provided timezone in timestamp conversion, instead of UTC.
  -port string
        HTTP port to listen on. (default "3903")
  -progs string
        Name of the directory containing mtail programs
  -statsd_hostport string
        Host:port to statsd server to write metrics to.
  -statsd_prefix string
        Prefix to use for statsd metrics.
  -stderrthreshold value
        logs at or above this threshold go to stderr
  -syslog_use_current_year
        Patch yearless timestamps with the present year. (default true)
  -v value
        log level for V logs
  -version
        Print mtail version information.
  -vmodule value
        comma-separated list of pattern=N settings for file-filtered logging

TIM_20180524111731

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
1天前
|
应用服务中间件 nginx Docker
本地通过域名访问虚拟机上nginx的服务、搭建域名访问环境一(反向代理配置)
这篇文章介绍了如何通过域名在本地访问虚拟机上的nginx服务,包括创建nginx容器、修改配置文件、修改本地host文件以及进行访问测试的详细步骤。文章提供了具体的Docker命令来创建并配置nginx容器,展示了配置文件的修改示例,说明了如何在本地系统的hosts文件中添加虚拟机IP和自定义域名,以及如何通过浏览器进行测试访问。
本地通过域名访问虚拟机上nginx的服务、搭建域名访问环境一(反向代理配置)
|
1天前
|
存储 监控 应用服务中间件
查看nginx日志文件
器性能和提高网站可用性。掌握日志文件的路径、查看方法和基本分析技能对于任何服务器管理员来说都是必备技能。
7 1
|
5天前
|
存储 Ubuntu 应用服务中间件
如何在 Ubuntu VPS 上配置 Nginx 的日志记录和日志轮转
如何在 Ubuntu VPS 上配置 Nginx 的日志记录和日志轮转
11 4
|
13天前
|
存储 应用服务中间件 nginx
部署ELK+filebeat收集nginx日志
部署ELK+filebeat收集nginx日志
部署ELK+filebeat收集nginx日志
|
20天前
|
存储 开发框架 前端开发
循序渐进VUE+Element 前端应用开发(31)--- 系统的日志管理,包括登录日志、接口访问日志、实体变化历史日志
循序渐进VUE+Element 前端应用开发(31)--- 系统的日志管理,包括登录日志、接口访问日志、实体变化历史日志
|
6天前
|
应用服务中间件 Linux nginx
Nginx log 日志文件较大,按日期生成 实现日志的切割
Nginx log 日志文件较大,按日期生成 实现日志的切割
27 0
|
12天前
|
应用服务中间件 nginx
[nginx]日志中记录自定义请求头
[nginx]日志中记录自定义请求头
|
12天前
|
应用服务中间件 Shell nginx
shell分析nginx日志的一些指令
shell分析nginx日志的一些指令
|
13天前
|
应用服务中间件 Shell Linux
使用logrotate定期切割nginx日志
使用logrotate定期切割nginx日志
|
1月前
|
监控
查看服务器/IIS日志、log、访问信息基本方法
除了手动查看,你也可以使用日志分析工具,如Log Parser、AWStats等,这些工具可以帮助你更方便地分析日志数据。
44 1