Skip to content

A prometheus exporter for the Tankerkoenig API (gas prices).

License

Notifications You must be signed in to change notification settings

lukasmalkmus/tankerkoenig_exporter

Repository files navigation

Tankerkoenig API Exporter for Prometheus

Workflow Latest Release License


Introduction

The Tankerkoenig API Exporter is a simple server that scrapes the Tankerkoenig API for gas station prices and exports them via HTTP for Prometheus consumption.

Usage

The first step is to grab an API key from the Tankerkoenig site.

The exporter supports two different modes of operation:

  1. Geo-Mode: The exporter will scrape all stations in a given radius around a given location.
  2. Station-Mode: The exporter will scrape only the stations given by their IDs. To get station IDs, either use the API yourself or checkout the Tankstellen Finder.

Important: Be advised to set a high scrape interval (e.g. 5 minutes). Each scrape performs an API call and to frequent requests can lead to the deauthorization of your API key!

Note: Since tankerkoenig isn't a very handy word, the metric namespace is tk.

Installation

The easiest way to run the exporter is by grabbing the latest binary from the release page.

Using the application

Run the application with the --help flag to see all available options with their descriptions and default values (if any).

Geo-Mode

export TANKERKOENIG_API_KEY="YOUR_API_KEY"
./tankerkoenig --tankerkoenig.location=u0yjje785f4 --tankerkoenig.radius=5

Note: The --tankerkoenig.product flag is currently not implemented.

Station-Mode

export TANKERKOENIG_API_KEY="YOUR_API_KEY"
./tankerkoenig --tankerkoenig.stations="51d4b55e-a095-1aa0-e100-80009459e03a"

Note: The --tankerkoenig.stations flag can be used multiple times to add multiple stations to scrape.

Using docker

Docker images are available on the GitHub Package Registry.

# .env file contains TANKERKOENIG_API_KEY="YOUR_API_KEY"
docker run -p9386:9386/tcp --env-file=.env ghcr.io/lukasmalkmus/tankerkoenig-exporter:0.10.0 --tankerkoenig.stations="51d4b55e-a095-1aa0-e100-80009459e03a"

Querying

The exporter exposes the following Tankerkoenig API related metrics (there are a handful of exporter related metrics as well, like up, etc.):

  • tk_station_price_euro{id, product}: The fuel price in euro per liter.
  • tk_station_open{id}: Whether the station is open (1) or not (0).
  • tk_station_details{id, name, address, city, geohash, brand}: Details of the station.

If you want to add station details when querying the price metric, you can join the two metrics like this:

tk_station_price_euro * on (id) group_left(brand, address) tk_station_details

Contributing

Feel free to submit PRs or to fill Issues. Every kind of help is appreciated.

License

© Lukas Malkmus, 2023

Distributed under Apache License (Apache License, Version 2.0).

See LICENSE for more information.