Compute and derive metrics by watching a log file

Overview

Export Prometheus metrics from your web server's access log

Web servers only offer limited metrics. For example, nginx only offers stub_status unless you pay for NGINX Plus, which will only give a basic count of active connections and requests served across all virtual hosts.

However nearly all web servers are configured to log all requests to a file.

This tool attaches to the log file (like tail -f does) and exposes metrics for Prometheus.

screenshot from Grafana

Project status

This is ready for production use, and deployed to my personal server which hosts multiple services.

How to use

$ ./access-log-to-prometheus-metrics /var/log/nginx/access.log '$host $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'
Starting server at 127.0.0.1:9898
$ curl http://127.0.0.1:9898/
# HELP requests The total number of requests per HTTP status code and virtual host name
# TYPE requests counter
requests{status="200",vhost="app.taguette.org"} 123
requests{status="304",vhost="app.taguette.org"} 27
requests{status="207",vhost="cloud.rampin.org"} 8

Supported log formats

You can pass your NGINX log_format configuration line. If you are using a different web server, you will have to convert your log format to the equivalent NGINX configuration.

The following variables are read:

  • The HTTP status code ($status), used as a label on the requests metric
  • The virtual host name ($host), used as a label on the requests metric
  • The presence of a user name, used as label on the requests metric (yes/no/unk)
  • The time to process the request ($request_time), used in the request_duration metric
  • The size of the response's body ($response_body_size), used in the response_body_size metric

Metrics

  • requests is a counter for requests (e.g. log lines), organized by status (the HTTP status code) and vhost (the virtual host name)
  • request_duration is a histogram for request durations, organized by status (the HTTP status code) and vhost (the virtual host name)
  • response_body_size if a histogram for responses' body sizes in bytes, organized by status (the HTTP status code) and vhost (the virtual host name)

Labels default to the string "unk" if they are unknown (e.g. those variables are not present in your log format).

You might also like...
Log agent to replay time-stamped log stream

replayman Log agent to replay time-stamped log stream. Getting started Installation cargo install replayman Prepare for your data TSV with a header li

⏱ Cross-platform Prometheus style process metrics collector of metrics crate

⏱ metrics-process This crate provides Prometheus style process metrics collector of metrics crate for Linux, macOS, and Windows. Collector code is man

Fiddi is a command line tool that does the boring and complex process of checking and processing/watching transactions on EVM compatible Blockchain.

Fiddi is a command line tool that does the boring and complex process of checking and processing/watching transactions on EVM compatible Blockchain.

zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

A dotfiles manager, with real time fle watching and 100% less sym-links!

Kubo A dotfile manager that watches files in real time. Usage Create a directory called .kubo in $HOME, then create a file called kubo.toml in .kubo.

Plex webhook service to automatically update your Anilist watching list.

anifunnel Plex webhook service to automatically update your Anilist watching list. Description anifunnel is a web server that will consume incoming Pl

Displays the Show/Movie you're currently watching on Discord!
Displays the Show/Movie you're currently watching on Discord!

Jellyfin-RPC Program used to display what you're currently watching on discord. Jellyfin-RPC uses the API to check what you're currently watching, thi

Distributed compute platform implemented in Rust, and powered by Apache Arrow.
Distributed compute platform implemented in Rust, and powered by Apache Arrow.

Ballista: Distributed Compute Platform Overview Ballista is a distributed compute platform primarily implemented in Rust, powered by Apache Arrow. It

Distributed compute platform implemented in Rust, and powered by Apache Arrow.
Distributed compute platform implemented in Rust, and powered by Apache Arrow.

Ballista: Distributed Compute Platform Overview Ballista is a distributed compute platform primarily implemented in Rust, powered by Apache Arrow. It

3d Cellular Automata using WGPU in Rust (for the web and using compute shaders)

3D-Cellular-Automata-WGPU 3d Cellular Automata using WGPU in Rust (for the web and using compute shaders) The branches are very messy... I recommend y

Sample code for compute shader 101 training

Sample code for Compute Shader 101 This repo contains sample code to help you get started writing applications using compute shaders.

Interface definitions for the Compute@Edge platform in witx.

🔗 compute-at-edge-abi This repository contains witx definitions for the Compute@Edge platform ABI. About witx The witx file format is an experimental

Viceroy provides local testing for developers working with Compute@Edge.
Viceroy provides local testing for developers working with Compute@Edge.

Viceroy provides local testing for developers working with Compute@Edge. It allows you to run services written against the Compute@Edge APIs on your local development machine, and allows you to configure testing backends for your service to communicate with.

Compute a pairwise SNP distance matrix from one or two alignment(s)
Compute a pairwise SNP distance matrix from one or two alignment(s)

Compute a pairwise SNP distance matrix from one or two alignment(s) Table of Contents Motivation Install cargo conda Precompiled binaries homebrew Con

Python package to compute levensthein distance in rust

Contents Introduction Installation Usage License Introduction Rust implementation of levensthein distance (https://en.wikipedia.org/wiki/Levenshtein_d

Toy library for neural networks in Rust using Vulkan compute shaders

descent Toy library for neural networks in Rust using Vulkan compute shaders. Features Multi-dimensional arrays backed by Vulkan device memory Use Rus

Cross-platform compute shader engine
Cross-platform compute shader engine

wgpu-compute-toy This is the compute shader engine for https://compute.toys As well as running on the web via WebAssembly and WebGPU, it can run nativ

The first compute-centric vector graphic video game
The first compute-centric vector graphic video game

🕹ī¸ Vong This repository contains source code for the first native use of a compute-centric vector graphics video game, inspired by Pong. ✍ī¸ Authors @

Allow DataFusion to resolve queries across remote query engines while pushing down as much compute as possible down.

DataFusion Federation The goal of this repo is to allow DataFusion to resolve queries across remote query engines while pushing down as much compute a

Comments
  • Add custom filters/labels

    Add custom filters/labels

    It would be cool if the user could customize the behavior from the command-line.

    For example:

    • Custom filters, e.g. only process lines where "request starts with /api" or where "vhost is example.org" or "status is 5xx"
    • Custom labels, e.g. "set <version> from request using ^/api/(v[0-9]+)/"

    This needs the log parser to keep the original variables & values in addition to the parsed values.

    enhancement 
    opened by remram44 0
Owner
Remi Rampin
Research Engineer
Remi Rampin
A nginx log explorer

Rhit reads your nginx log files in their standard location(even gzipped), does some analysis and tells you about it in pretty tables in your console,

Canop 700 Dec 27, 2022
A loki logger for the log facade

Loki Logger A loki logger for the log facade. Examples extern crate log; extern crate loki_logger; use log::LevelFilter; #[tokio::main] async fn main

Thomas Nicollet 11 Dec 24, 2022
rt-history: An RT-safe history log with error checking

rt-history: An RT-safe history log with error checking This is a bounded wait-free thread synchronization primitive which allows you to record the tim

Hadrien G. 3 Oct 11, 2022
A cool log library built using rust-lang

RustLog A cool log library built using rust-lang Installation: Cargo.toml rustlog = { git = "https://github.com/krishpranav/rustlog" } log = "0.4.17"

Krisna Pranav 2 Jul 21, 2022
SWC Transform to prefix logs. Useful for adding file and line number to logs

SWC Transform to prefix logs. Useful for adding file and line number to logs

William Tetlow 12 Jan 1, 2023
Firecracker takes your HTTP logs and uses them to map your API flows and to detect anomalies in them.

Who is BLST and what do we do? BLST (Business Logic Security Testing) is a startup company that's developing an automatic penetration tester, replacin

BLST 692 Jan 2, 2023
A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice

sensible-env-logger A pretty, sensible logger for Rust - ideal for running examples and tests on a crate of choice. This is a thin wrapper around pret

Ritvik Nag 3 Aug 9, 2022
A rust library for creating and managing logs of arbitrary binary data

A rust library for creating and managing logs of arbitrary binary data. Presently it's used to collect sensor data. But it should generally be helpful in cases where you need to store timeseries data, in a nearly (but not strictly) append-only fashion.

Yusuf Simonson 1 May 9, 2022
Rall is an incredibly simple and intuitive logger

Really...? Another Logging Library? Yes! :P rall is an incredibly simple and intuitive logger, consider this crate a failure if you can't get setup wi

Hamothy 4 Sep 5, 2022
A dead simple logger that works globally and across threads.

Woody A logger for Rust that's *actually* easy to use. Features Easy to use: Just import the macros and you're good to go. No need to configure anythi

Travis A. Wagner 11 Apr 13, 2023