This is just a quick update on the previous post about monitoring zabbix, and assumes you already have zabbix set up and monitoring the basic properties of your server. (if you don't, see here.)

We're going to add a simple php script on our minecraft server that queries the number of players online, then return this value to the zabbix server by adding it ot the agent as a UserParameter.

Adding the PHP:

No point in reinventing the wheel, so we're going to grab  xPaw's MinecraftQuery.class.php from here and save it on the minecraft server as "MinecraftQuery.class.php"

Then we need to add our own file which uses this one, queries our server ip and port, and returns the number:

require_once('MineCraftQuery.class.php');

$Query = new MinecraftQuery( );

try
{
//$arg[1] is the argument passed in when calling the php, in this case the port
$Query->Connect( '127.0.0.1', $argv[1] );

$result = $Query->GetInfo( );

echo $result["Players"];
}
catch( MinecraftQueryException $e )
{
//return 0 if something goes wrong
echo 0;
}

unset($Query);
unset($result);
?>

Now we add a custom user parameter to the bottom of /etc/zabbix/zabbix_agentd.conf :

UserParameter=minecraft.players[*],php /home/mc/ServerQuery.php $1

The first part is the key to identify the item in zabbix server: the * in brackets tells the agent to use the values that the server is sending in place of any numbers prepended with $. This means with a single UserParameter on the agent, we can query multiple minecraft servers from the zabbix server, simply by passing a different port in with the trigger. The second part is the command to run our script, change it to match your script's path.

Finally, on the server we need to reload the zabbix agent so it know about the new key:

/etc/init.d/zabbix-agent restart

Adding the Host Item

In the zabbix web interface, go to configuration -> Hosts, select your minecraft server and go to Item -> Create Item.

For the key, enter the key you used as a UserParamter, but replace the * with the server query port.

Thats all you need to do to add the item, but to make it a bit neater you can set the Units to "players" and create a new application group such as "minecraft players"

Here's mine:

Capture

Repeat the above for any extra servers you have, and add all of the items to a graph to display them together (see part 1 for more on graphs) You should end up with something like this:

Capture

To link externally to your graphs you need to enable guest readonly access, and use the following address:

http://mydomain.com/zabbix/chart2.php?graphid=

(you can find the graph ID in the URL when you are configuring the graph)