munin-contrib/plugins/minecraft/bukkit-statistician-players

67 lines
1.5 KiB
PHP

#!/usr/bin/php
<?php
/**
* Bukkit/MySQL Munin plugin
* ---------------------------------
* New players per day
*
* Shows the new players / visitors per day
* via Statistician (http://s.frd.mn/14qKXTM)
*
* Read more about my plugins on my blog:
* http://s.frd.mn/XJsryR
*
* Author: Jonas Friedmann (http://frd.mn)
* GitHub: https://github.com/yeahwhat-mc/munin-bukkit-plugins
*
*/
/**
* MySQL configuration
*/
$hostname = 'localhost';
$username = 'sql';
$password = 'pass';
$database = 'sql';
$port = 3306;
/**
* !!! DO NOT EDIT THIS PART BELOW !!!
*/
if ((count($argv) > 1) && ($argv[1] == 'config'))
{
print("graph_title Bukkit / Statistician - new players per day
graph_category bukkit
graph_vlabel new players per day
graph_args --base 1000 -l 0
players.type GAUGE
players.label new players
");
exit();
}
// Construct 'minimum' timstamp
$current = mktime();
$today = mktime(0, 0, 0, date("n", $current), date("j", $current), date("Y", $current));
// Initiate connection
$connection = mysqli_connect($hostname, $username, $password, $database, $port);
// Check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// Select queries return the amount of rows
if ($result = mysqli_query($connection, "SELECT player_name FROM players WHERE firstever_login > $today")) {
// Print values
print('players.value ' . mysqli_num_rows($result) . "\n");
}
// Close connection
mysqli_close($connection);
?>