Counting the Icecast stream eyeballs

I’m at home. And battling to cover costs of moving home, finishing renovations (garden), and playing breadwinner for wife and child. Despite working, finances weren’t there in time for me to attend the always fabulous Linux.conf.au in Brisbane this year, much to my disappointment, so I stayed home and, around work, watching the video streams.

Let’s start with a big thank you to the guys and girls who worked the A/V kit; ensured audio was there, video was focused and framed, slides were pulled in, and streams happened.

Icecast admin interface example
The Icecast administration interface

Which got me to thinking; how many people are watching? All very nice to know after the show, but what about real time, so that the director, team and even presenter knows where there audience is. Each icecast server does show this information when the server’s admin logs in. Neat.

However, to distibute content, you need a lot of severs to distribute the streams, and quite probably, these servers are being run by Other People, who probably don’t want to give you their admin password to log into their icecast server.

We need a way of having something take the values from the admin interface, and expose that so we can collect these statistics.

Thus I scribbled down two scripts: one a CGI script to fetch the data from the local icecast server and serve it as a CGI in JSON format, and a second to collect multiple instacnes of this CGI’s output in parallel.

The first script would be run by the same admin who runs the remote icecast server, as the script needs to have the icecast admin password. It uses XPath expressions to fetch relevent pieces of information, and return it as JSON, a pretty compact format.

The second currently just fetches this data and displays, it, but with a little more hacking it could pump these results into an RRD, thereby giving us the option of graphing the results.

It’s very much a poll, and probably something to repeat every 15, 30 or 60 seconds. It would need to dynamically handle the adding (and removing) of individual icecast servers as they are brought online. But it’s a start.

Code can be found in my pseronal SVN repo.

Brought to you by the Perl modules CGI, JSON, HTML::Treebuilder::XPath, WWW::Curl::Multi, and others.

While I’m here, I think next year we should arrange to have an Icecast server in each city of Australia. If I had to pick one issue, I was having to connect to the US or European relays when the one public one at UQ was full or “having a moment”. I’d urge each LUG around the country to, if they have a server on decent bandwidth, offer to relay the streams; if not publicly, then at least to their members.

Perth busses suck

Its not the vehicles; its the very loose schedule. Zone 1, 6pm on a normal Friday, and its 45 mins between services. At the best of times there are 4 busses an hour. I miss a bus Everett 5 – 10 mins. Least I don’t do this often…

MySQL Partitioning Automation

This is one cool post.

It’s a shame that MySQL doesnt have the ability to automatically add partitions based upon date. For example, if result of a function should generate a new partition:

PARTITION BY YEARWEEK(MyDateTimeCol)

And hey presto, a bunch of new partitions would appear every time you insert new data thats in a new range. YEARWEEK() may be too course for your massive amount of data – perhaps TO_DAYS(). Perhaps it’s not that massive a data set, so just YEAR() would suffice. But having the new partitions created upon INSERT of data that matches would be great. As would deletion of partitions when a partion is empty. Nice bit of housekeeping.

Train lines

With the exception of city centre termini, train lines don’t end somewhere interesting and exciting, but where demand and excitement has dropped off so far they can’t be bothered going any further.