in Development, Games, Networking

Graphing Counter-Strike Source FPS/Users in MRTG on Windows

Network Frames per SecondIn my last post, you discovered my obsession for generating statistics on my network usage and my use of MRTG to draw pretty little graphs. Writing that post got me thinking about my Counter-Strike server, and what data I could usefully graph from it. A bit of Googling led me to this page where a Dutch guy had used MRTG to graph the number of users and the network frames per second of his CS:S server – running on Ubuntu Linux.

He used a custom compiled “rcon” binary to talk directly to the game server’s Remote Console port. This is the port that allows an administrator to configure the game, kick players, change maps and generally do all the useful stuff that a game admin needs to do. It’s the protocol used by the hlstats live stats page to determine what is happening right now on the game server. Unfortunately, as far as my Googling shows, such a binary doesn’t exist for win32. There is a perl module (kkrcon.pm) which does the work inside hlstats, but the command line wrapper for kkrcon.pm – kkrcon.pl – doesn’t seem to have been updated since 2001 and so doesn’t work for Source titles.

A little Perl hacking later and I’ve created a version of the kkrcon.pl wrapper that is capable of using the Source rcon protocol. You can download both the module and the wrapper here: source server rcon perl script. This was tested on Windows Server 2003 running ActiveState Perl.

With that done, we can use MRTG to run another Perl script which will run the new kkrcon.pl with the right parameters, request some data from the game server and then parse it into a format that MRTG can understand. The two scripts I used are much the same as I found on the Zokahn site, but tweaked to use my new kkrcon.pl instead of the binary and to pass the parameters in a slightly different way. You can grab the scripts here: MRTG Counter-Strike: Source perl data source scripts.

The last step is the MRTG config file itself, here’s what the CSS Users part of mine looks like:

Target[server.CS-Users]:`.\m_cs-s_users.pl <server_ip> <port> <rcon_password>`
Title[server.CS-Users]: Active Counter-Strike:Source users
PageTop[server.CS-Users]: <H1>Counter-Strike:Source Users</H1>
MaxBytes[server.CS-Users]: 16
ShortLegend[server.CS-Users]: #
YLegend[server.CS-Users]: Active Users
Legend1[server.CS-Users]: Current active CS:Source users
LegendI[server.CS-Users]: Users
LegendO[server.CS-Users]:
Options[server.CS-Users]: growright,nopercent,gauge,integer
Unscaled[server.CS-Users]: ymwd

It’s very important to note that those are back ticks (`) on the first line – NOT apostrophes (‘). This caught me out and stopped MRTG generating data until I’d fixed it.

You can see my graphs here, although there isn’t a lot of data yet – just waiting for the clan to wake up and start playing!

Comments are closed.