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.
The first step is to grab an API key from the Tankerkoenig site.
The exporter supports two different modes of operation:
- Geo-Mode: The exporter will scrape all stations in a given radius around a given location.
- 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
.
The easiest way to run the exporter is by grabbing the latest binary from the release page.
Run the application with the --help
flag to see all available options with
their descriptions and default values (if any).
export TANKERKOENIG_API_KEY="YOUR_API_KEY"
./tankerkoenig --tankerkoenig.location=u0yjje785f4 --tankerkoenig.radius=5
Note: The --tankerkoenig.product
flag is currently not implemented.
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.
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"
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
Feel free to submit PRs or to fill Issues. Every kind of help is appreciated.
© Lukas Malkmus, 2023
Distributed under Apache License (Apache License, Version 2.0
).
See LICENSE for more information.