Icecast monitoring from Cacti
juil 1st, 2008 by Prune
I was asked for my Icecast monitoring template for Cacti today. I just realized I made a post in Cacti forums back in 2005 but never released the files.
My plugin is based on a Data Query. You add it to your device then you can discover every stream of your icecast server. Then you can choose the one you want, or chose the “all listeners”.
I also have an aggregation template, not specialy made for icecast but really usefull. You can then aggregate you streams as you like.
This is what I get for some of my streams :

First, get the attached tar file with xml ressource, php script and templates.
Be aware that the PHP script is not originaly from me but I don’t remember the source (I think it was german). I mostly rewrite it to handle my needs. And, as there is xml parsing done by PHP it is not really efficient.
Also note that, as i’m aware of, cacti can’t give “per host” information to a Data Query. What does this mean… it means that you will have to set parameters for each of your host in the XML file OR in the PHP file.
The only parameter I was able to give from the host was the hostname. This is how is made my XML file :
<interface> <name>Get Icecast mountpoint</name> <description>Queries a list of mountpoint in a Icecast streaming server .</description> <script_path>|path_php_binary| -q |path_cacti|/scripts/icecast2-cacti-query/icecast_v2_xml.php</script_path> <arg_prepend>|host_hostname| admin mypassword 8001</arg_prepend>
admin is the login I use on the icecast interface, mypassword is the password and 8001 here is the port of the admin interface.
Doing like this, you MUST have the admin of your icecast servers on the same port and with the same login/password.
Another solution I used first was to code this in the PHP file, or in another file for the port. ex :
if ($host == "10.16.248.42") $port = 8001; else if ($host == "10.16.248.43") $port = 8002; else if ($host == "10.16.248.44") $port = 8003;
This said, I use this script on 4 servers having around 20 streams each and everything is working fine.
So….
Get the tar file. You will find in it :
XML template files
XML ressource file
PHP script
Put the PHP scripts and ressource file (thing under the cacti directory) where they belong to (= same place as in the tar file but in your cacti install folder).
Then, import the template files in cacti. For that, go to your import menu and… heh… import ![]()
You may have some problem due to Cacti versions. My version is actually 0.8.7a
If you can’t import, create everything by hand :
Then the Data Template :

You will have to create 4 Data source items. Use the same name as mine. Also, set the maximum value to 100000 for listeners and list_peak.
The Graph Template : Icecast2 Listener per Mountpoint query


I won’t have time to do a more step-by-step tutorial here. Refer to Cacti doc or other tutorial on the net. In fact, I really don’t remember in which order you have to do all this… I know, lame…
Once you’re all set-up, go to your device, add the Data Query to it and go create new graphs. This is what you should get :
![]()
This will give you a basic graph. One per stream :

Then comes in the aggregation Graph Template…. the one with ‘beautiful’ colors from the start ![]()
It took me some time to understand how to achieve this without beeing too specific. I think i’m pretty close to it.
Here is a 12 times aggregation template. Of course, you can change it to how many you need. I think i started a 32x, but hey, this can take a lot of time and, trust me, it is getting really hard to find that amount of colors, cycling in a good fashion way !!!
Once again, be aware of 2 things :
Changing the Graph Template once you already have used it can lead to strange things. If you encounter this, be prepared to pray, call the A-team (or at least the GhostBusters) or spend some nights playing in mysql tables. Maybe I’ll do a tutorial on this too next time I have a problem.
So, my template is called icecast, but can be used for anything. Import the template and you will find a new Icecast2 - Listeners per Mountpoint (custom 12) entry.
If you prefer to do it by hand, it’s kind of easy… but long and repetitive.
You will have to create a bunch of Graph Template Items, 4 for each value you want to graph. Here are the first two :
![]()
This will generate as much Graph Item Inputs as Graph Template Item. Be sur of that.
SECRET : then, create more Graph Item Inputs by clicking “Add”.
Name it “Legend Text 1″ (Legend Text 2, Legend Text 3…) and select “Text format” as Field Type :

This will enable you to give a name on each entry of the graph when creating it.
The rest of the config is like this :

Then you can create your aggregated graph. You should have 2 otpions here. The one I never tested for Icecast is to go to New graphs, select your host and select the Icecast2 - Listeners per Mountpoint (custom 12) option from the menu in the Graph Templates box. Go down and hit create. You should be able to create the graph.
The other solution is to create the graph owned by “no” server.
For that, go to the Graph Management menu, Hit add. Select no host but the Icecast2 - Listeners per Mountpoint (custom 12) template. Hit Create.
This is pretty slow now, especialy if you have a lot of graphs in your Cacti install.
I forgot to tell you something. When creating a graph like this, you need to define every entries in the graph. If you don’t you may end with unexpected results. For this reason I had to create a “null” or “zero” datasource. This way I am sure I can fill every entries, unused will be “zero”, which is far better than nothing.
You will end with a page with menues. In each menu you will find EVERY datasource availlable. It’s your job to find the good one. Be carefull that, if you named the entries by 1,2…10,11… you will not get them in this order here, as, by name, the ordre is 1,10,11,12,2,3,4….

Fill it, hit save, and your graph is done.
You can come back here and change it, but, as I said, it may have side effect on the resulting graph. In this case, dig in mysql or remove the whole graph and start over, in one shot. Depending on Cacti’s version, the problem may be solved.
You will also find the xml file for this in the tar as cacti_graph_template_icecast2_-_listeners_per_mountpoint_custom_12.xml and the zero data query as cacti_data_template_unix_-_zero.xml.
The zero dataquery is using a shell script, located in cacti_path/scripts/zero.sh. I’m sure it can be done another way, but I did like this in a hurry. It may not be the best, but it’s working. Sometimes a sysadmin have to take quick moves…
#!/bin/bash echo 0 exit 0

I am a recently experienced hacker and whereas I can get the php script to work the templates doesn’t work for me. You should improve the documentation if you have time with a detailed even-a-newbie-can-do-it walk through.
Maybe the problem is, with cacti, some templates are version dependent.
I won’t have the time to do a better step-by-step than this. Cacti is tricky and you need to know it well if you want to be able to get the power out of it. I’m sorry, but it’s not as easy as it should have been…