Table of Contents
[TOC]
https://github.com/google/mtail
This is a way of getting metrics out of logs.
To do so we will be using regexes and a program called mtail that will be watching these log files to parse and execute counts as the files are being written.
- Pick the log file you want to be parsing
- Code the
prog
you need for parsing this file referring to https://github.com/google/mtail/blob/master/docs/Programming-Guide.md - Configure the mtail prog files in gitlab-prometheus, such that
- There is a file that defines the parsing job stored in
files/default/mtail/<job_name>.mtail
- There is a recipe that configures mtail to copy this file into the progs folder, for ex:
recipes/mtail-nginx.rb
(check this file) - There is a spec file that checks that the file is correctly configured.
- You bump the cookbook version and install
- Deploy to production
Using a local folder such as ~/tmp
- Capture a log file so you can use it, store it with a name like log-source in the tmp folder.
- In this same folder store the
prog.mtail
file that describes how to parse and count things. - Using docker start a container such that
docker run --name mtail -v ${HOME}/tmp:/tmp -p 3903:3903 --rm dylanmei/mtail -progs /tmp --logs /tmp/<logfile-you-expect>
curl -s localhost:3903/metrics
, you should only see a comment with the names of the metrics, nothing should have been accounted for.- cat the source file into the expected log file to make mtail detect that something was written down, for example:
# cat log-source > logfile-you-expect
curl -s localhost:3903/metrics
, you should now see that mtail is counting things- rinse and repeat