Turn logs into Nightingale metrics with mtail
Categraf embeds mtail: extract counters, gauges and histograms from log files with regular expressions and expressions, without shipping the logs to a log system first.
Last reviewed
The mtail input turns logs into metrics. Input is a log file, output is a set of counters, gauges and histograms defined in mtail syntax; underneath it is Go regular expressions plus expression evaluation. It suits cases such as status-code distribution from Nginx access logs or error counts from application logs, with no need to ship the logs into Elasticsearch or Loki first.
Each [[instances]] block points at a set of progs (mtail program files or a directory) and the log paths to follow. Give different instances different progs, or distinguish them with labels, or their metrics will collide.
What's in the template
- Categraf collector config:
input.mtail
How to connect
-
Install Categraf, put the config below in
conf/input.mtail/mtail.toml, fill in your own address and credentials, and restart Categraf. The startup log printsinput: local.mtail startedonce the plugin is loaded.[[instances]]# progs = "/path/to/prog1" # prog dir1# logs = ["/path/to/a.log", "path/to/b.log"]# override_timezone = "Asia/Shanghai"# emit_metric_timestamp = "true" #string type# [[instances]]# progs = "/path/to/prog2" # prog dir2# logs = ["/path/to/logdir/"]# override_timezone = "Asia/Shanghai"# emit_metric_timestamp = "true" # string type
Related
- Mtail template source: the raw JSON for dashboards, rules and collector config. Pull requests welcome.
- Import dashboards and alert rules
- Verify that metrics are stored
- All integrations