Skip to main content

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​

  1. 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 prints input: local.mtail started once 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