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:
1 2 3 4 5 6
# 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.
# 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 version 3.0.0-rc47 git revision 5e0099f843e4e4f2b7189c21019de18eb49181bf go version go1.16.5 go arch amd64 go os linux
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. -disable_fsnotify DEPRECATED: this flag is no longer in use. (default true) -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_metric_timestamp Emit the recorded timestamp of a metric. If disabled (the default) no explicit timestamp is sent to a collector. -emit_prog_label Emit the 'prog' label in variable exports. (default true) -expired_metrics_gc_interval duration interval between expired metric garbage collection runs (default 1h0m0s) -graphite_host_port string Host:port to graphite carbon server to write metrics to. -graphite_prefix string Prefix to use for graphite metrics. -ignore_filename_regex_pattern string -jaeger_endpoint string If set, collector endpoint URL of jaeger thrift service -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 -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 -max_recursion_depth int The maximum length a mtail statement can be, as measured by parsed tokens. Excessively long mtail expressions are likely to cause compilation and runtime performance problems. (default 100) -max_regexp_length int The maximum length a mtail regexp expression can have. Excessively long patterns are likely to cause compilation and runtime performance problems. (default 1024) -metric_push_interval duration interval between metric pushes to passive collectors (default 1m0s) -metric_push_interval_seconds int DEPRECATED: use --metric_push_interval instead -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. -override_timezone string If set, use the provided timezone in timestamp conversion, instead of UTC. -poll_interval duration Set the interval to poll all log files for data; must be positive, or zero to disable polling. With polling mode, only the files found at mtail startup will be polled. (default 250ms) -port string HTTP port to listen on. (default "3903") -progs string Name of the directory containing mtail programs -stale_log_gc_interval duration interval between stale log garbage collection runs (default 1h0m0s) -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) -trace_sample_period int Sample period for traces. If non-zero, every nth trace will be sampled. -unix_socket string UNIX Socket to listen on -v value log level for V logs -version Print mtail version information. -vm_logs_runtime_errors Enables logging of runtime errors to the standard log. Set to false to only have the errors printed to the HTTP console. (default true) -vmodule value comma-separated list of pattern=N settings for file-filtered logging