I recently had a thought…I wonder if Zabbix can graph the fuel prices near me.
This thought was triggered by a news article I read about how the petrol station cycles have changed so that the cheapest fuel is on a Monday rather than a Wednesday like it used to be.
Since I already had a Zabbix install going, I had no desire to install any other graphing engine and whatnot just to graph some simple numbers, so I came up with a way to graph the local fuel prices with Zabbix. Not really the intended use case of Zabbix, but hey, it worked!
This could be applied to any number of situations where a number online needs graphing and you already have Zabbix going, but I’m using local fuel prices as a real world example.
For my petrol graphing needs, the Western Australian Government conveniently provides a service called Fuelwatch that provides a “RSS feed” that I can use to retrieve the prices for today. I built a small Python script that allows me to pull the price of fuel for any petrol station, which I then use with the Zabbix agent’s
system.run functionality to pull in numbers.
I’ve used the Zabbix server for my scripts since that’s one of the few servers where I have the Zabbix agent installed. I put the script named prices.py into
/opt/scripts, and then created a Zabbix agent active item with the following key –
system.run[/opt/scripts/prices.py "BP 2go Noranda"]
This means “Run the script /opt/scripts/prices.py with the parameter BP 2go Noranda”, which then pulls the price for BP Ultimate into Zabbix.
The script will return a number similar to this one – 150.9 – so I’ve set the Type of information for the item to “Numeric (float)” so I can capture the decimal place. This results in a graph like this –
You could then potentially set up a graph with multiple items and compare values, or just have history like what I have.