Part 131: Monitoring fuel prices with Zabbix

What's up, home? part 131 cover image

This will start my blog series which I spoke about at the Zabbix Summit 2025 -- how and why I monitor my surroundings with Zabbix. The reason is partly conceptual, partly real, to showcase how Zabbix can potentially help you to make figuring out what's going on near you much easier. Let's dive in!

Where to get the price data?

In Finland, we have this community-driven fuel station price tracking site, polttoaine.net. It has been around since forever, but for my kind of Zabbix use purposes, has several downsides: 

  • Price updates are not guaranteed to be real-time. It really is community-driven: people who visit the station, will then update the prices if they remember/have the energy to do so. This means that sometimes the prices are updated the very same day, some days they are not updated at all.
  • Not all the fuel stations are there, at least not all the time.
  • No API, has to scrape the HTML.

All this being said, building this integration was and is fun. Let's start pumping data!

Parsing the HTML

If you look for example the listing of fuel stations in Helsinki and its source code, you will notice the table is built with traditional HTML tables. 

Source code

Not surprisingly, the table rows follow the same pattern. In first cell, there's the name and physical address of the station. That's something I'm interested about. I also need 95E10 price, as that is what our car likes to sip. So, for successful Zabbix integration, we need to grab these two cells.

Zabbix template

Enough site parsing, let's move on to Zabbix. 

I created a very small Zabbix template, which just contains the master item which fetches the URL I want, and then the fuel price.

Template items

In master item, one of the my custom Zabbix macros it uses is {CITY}.

Item config

In template macros, I added some self-descriptive macros to be used in triggers etc.

Template macros

Zabbix hosts

But wait, why in that template macros screenshot above the station name is empty? For the simple reason that the logic for my template is not very scaleable, but a quick proof-of-concept hack. How it works is that I have my hosts added like this:

Stations list

... and if I click on any of the hosts and go to its Macros tab, you will see that there's the exactly same longer name that can be found from polttoaine.net station listing.

Station's detailed name

Now, if I open the config for any fuel station host and click on fuel price item, on its preprocessing tab there's this:

Regular expression

The regular expression as plain text:

.*{$STATION}.*</td>.*<td title=\"95E10\" class=\"[^\"]+\">([0-9]+\.[0-9]+)

Might not be pretty, but it works.

Engine warning lights

Of course we need some alerts, too, so I added alerts which will let me know if it's really cheap or expensive.

Fuel price triggers

Zabbix dashboard

But this would not be any good without a dashboard. So, here's the snippet of the dashboard showing the fuel prices inside my Zabbix.

Fuel prices

 

 

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Buy me a coffee

Like these posts? Support the project and Buy me a coffee