2013-03-27 07:11:27 +01:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?php
|
2013-03-28 16:06:49 +01:00
|
|
|
/**
|
|
|
|
* Bukkit/MySQL Munin plugin
|
|
|
|
* ---------------------------------
|
|
|
|
* Passive mob kills per day
|
|
|
|
*
|
|
|
|
* Shows the passive kills of neutral mobs
|
|
|
|
* 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)
|
2014-09-06 15:11:07 +02:00
|
|
|
* GitHub: https://github.com/yeahwhat-mc/munin-bukkit-plugins
|
|
|
|
*
|
2013-03-28 16:06:49 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MySQL configuration
|
|
|
|
*/
|
2013-03-27 07:11:27 +01:00
|
|
|
|
|
|
|
$hostname = 'localhost';
|
|
|
|
$username = 'sql';
|
|
|
|
$password = 'pass';
|
|
|
|
$database = 'sql';
|
|
|
|
$port = 3306;
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
/**
|
|
|
|
* !!! DO NOT EDIT THIS PART BELOW !!!
|
|
|
|
*/
|
|
|
|
|
2013-03-27 07:11:27 +01:00
|
|
|
if ((count($argv) > 1) && ($argv[1] == 'config'))
|
|
|
|
{
|
|
|
|
print("graph_title Bukkit / Statistician - passive mob kills per day
|
2017-02-20 23:53:04 +01:00
|
|
|
graph_category games
|
2013-03-27 07:11:27 +01:00
|
|
|
graph_vlabel passive mob kills per day
|
|
|
|
graph_args --base 1000 -l 0
|
|
|
|
bat.type GAUGE
|
|
|
|
bat.label killed bats
|
|
|
|
chicken.type GAUGE
|
|
|
|
chicken.label killed chickens
|
|
|
|
cow.type GAUGE
|
|
|
|
cow.label killed cows
|
|
|
|
mooshroom.type GAUGE
|
|
|
|
mooshroom.label killed mooshrooms
|
|
|
|
ocelot.type GAUGE
|
|
|
|
ocelot.label killed magma ocelots
|
|
|
|
pig.type GAUGE
|
|
|
|
pig.label killed pigs
|
|
|
|
sheep.type GAUGE
|
|
|
|
sheep.label killed sheeps
|
|
|
|
squid.type GAUGE
|
|
|
|
squid.label killed squids
|
|
|
|
villager.type GAUGE
|
|
|
|
villager.label killed villager
|
|
|
|
");
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2014-12-05 00:37:42 +01:00
|
|
|
// Construct 'minimum' timstamp
|
2013-03-27 07:11:27 +01:00
|
|
|
$current = mktime();
|
|
|
|
$today = mktime(0, 0, 0, date("n", $current), date("j", $current), date("Y", $current));
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Initiate connection
|
2013-03-27 07:11:27 +01:00
|
|
|
$connection = mysqli_connect($hostname, $username, $password, $database, $port);
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Check connection
|
2013-03-27 07:11:27 +01:00
|
|
|
if (mysqli_connect_errno()) {
|
|
|
|
printf("Connect failed: %s\n", mysqli_connect_error());
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for bat kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Bat'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('bat.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for chicken kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Chicken'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('chicken.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for mooshroom kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'MushroomCow'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('mooshroom.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for cow kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Cow'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('cow.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for ocelot kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Ocelot'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('ocelot.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for pig kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Pig'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('pig.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for sheep and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Sheep'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('sheep.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for squid kills and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Squid'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('squid.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Select queries for villager and return the amount of rows
|
2013-03-27 07:11:27 +01:00
|
|
|
if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Villager'")) {
|
2013-03-28 16:06:49 +01:00
|
|
|
// Print values
|
2013-03-27 07:11:27 +01:00
|
|
|
print('villager.value ' . mysqli_num_rows($result) . "\n");
|
|
|
|
}
|
|
|
|
|
2013-03-28 16:06:49 +01:00
|
|
|
// Close connection
|
2013-03-27 07:11:27 +01:00
|
|
|
mysqli_close($connection);
|
2014-09-06 15:11:07 +02:00
|
|
|
?>
|