diff --git a/plugins/minecraft/jsonapi/README.md b/plugins/minecraft/jsonapi/README.md new file mode 100644 index 00000000..3385293b --- /dev/null +++ b/plugins/minecraft/jsonapi/README.md @@ -0,0 +1,55 @@ +# munin-bukkit-plugins + +This repository contains some useful [Munin](http://munin-monitoring.org/) plugins to monitor and observe a [Bukkit](http://bukkit.org) server: + +* **mcjsonplayers** - players currently online +* **mcjsonramusage** - RAM usage +* **mcjsontps** - TPS (ticks per second) +* **mcsqls2killshostile** - hostile mob kills +* **mcsqls2killsneutral** - neutral mob kills +* **mcsqls2killspassive** - passive mob kills +* **mcsqls2players** - new players per day +* **mcsqlubshame** - kicks/bans/mutes/etc. per day + +mcjson* requires [JSONAPI](https://github.com/alecgorge/jsonapi/) +mcsqls2* requires [Statistician](http://dev.bukkit.org/server-mods/statisticianv2/) +mcsqlub* requires [Ultrabans](http://dev.bukkit.org/server-mods/ultrabans/) + +Read more in my [blog post](http://blog.frd.mn/munin-bukkit-plugins/). + +## Requirements + +* Web server with `PHP` support and Munin (2) +* Bukkit server with JSONAPI for the JSONAPI plugins (`mcjson*`) +* Bukkit server with Ultrabans for the Ultrabans plugins (`mcsqlub*`) +* Bukkit server with Statistician for the MySQL plugins (`mcsqls2*`) +* MySQL server for the SQL plugins + +## Configuration + +1. Clone this repository: `git clone git@github.com:frdmn/munin-bukkit-plugins.git` +1. Adjust the JSONAPI variables in the mcjson* files +1. Adjust the MySQL variables in the mcsql* files +1. Make sure the `PHP` binary in the Shebang line is executable + +## Installation + +1. Perform your configuration (see above) +1. Move the plugins into the Munin plugin directory: `mv mc* /usr/share/munin/plugins/` +1. Change the ownership: `chown munin:munin /usr/share/munin/plugins/mc*` +1. Make sure they are exectuable: `chmod 755 /usr/share/munin/plugins/mc*` +1. Enable the plugins: `ln -s /usr/share/munin/plugins/mc* /etc/munin/plugins/` +1. Restart your munin-node: `service munin-node restart` +1. Run your cron: `su - munin --shell=/bin/sh -c /usr/bin/munin-cron` + +## Alerts and limits? + +To setup alerts and limits add the following lines in your specific node in the `munin.conf` file: + + [kotor.yeahwh.at] + address 5.9.115.5 + [...] + mctps_main.warning 19.9: # Warning alert on < 19.9 + mctps_main.critical 19: # Critical alert on < 19.0 + mcplayer_main.warning 20 # Warning alert when there are 20 players online + mcplayer_main.critical 30 # Critical alert when there are more than 30 players online \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcjsonplayers b/plugins/minecraft/jsonapi/mcjsonplayers new file mode 100644 index 00000000..49781c1b --- /dev/null +++ b/plugins/minecraft/jsonapi/mcjsonplayers @@ -0,0 +1,55 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / JSONAPI - players online +graph_category bukkit_jsonapi +graph_vlabel players +graph_args --base 1000 -l 0 +players.type GAUGE +players.label players +"); +exit(); +} + +// Include JSONAPI.php SDK (get this file here: https://github.com/alecgorge/jsonapi/raw/master/sdk/php/JSONAPI.php) +require('/var/cache/munin/JSONAPI.php'); + +// Prepare API call +$api = new JSONAPI($hostname, $port, $username, $password, $salt); +$result = $api->call("getPlayerCount"); + +// Check for success +if ($result['result'] == 'success'){ + // Print values + print('players.value ' . $result['success'] . "\n"); +} +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcjsonramusage b/plugins/minecraft/jsonapi/mcjsonramusage new file mode 100644 index 00000000..5255320a --- /dev/null +++ b/plugins/minecraft/jsonapi/mcjsonramusage @@ -0,0 +1,64 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / JSONAPI - RAM usage +graph_category bukkit_jsonapi +graph_vlabel RAM usage in GB +graph_args --base 1024 -l 0 +total.label total +total.type GAUGE +used.label used +used.type GAUGE +"); +exit(); +} + +// Include JSONAPI.php SDK (get this file here: https://github.com/alecgorge/jsonapi/raw/master/sdk/php/JSONAPI.php) +require('/var/cache/munin/JSONAPI.php'); + +// Prepare API call +$api = new JSONAPI($hostname, $port, $username, $password, $salt); +$result = $api->callMultiple(array( + "system.getJavaMemoryUsage", + "system.getJavaMemoryTotal" + ), array( + array(), + array(), +)); + +// Check for success +if ($result['result'] == 'success'){ + // Print values + print('used.value ' . round($result['success'][0]['success']/1000,2) . "\n"); + print('total.value ' . round($result['success'][1]['success']/1000,2) . "\n"); +} +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcjsontps b/plugins/minecraft/jsonapi/mcjsontps new file mode 100644 index 00000000..226d3400 --- /dev/null +++ b/plugins/minecraft/jsonapi/mcjsontps @@ -0,0 +1,55 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / JSONAPI - ticks per second (TPS) +graph_category bukkit_jsonapi +graph_vlabel ticks per second +graph_args --base 1000 -l 0 +tps.type GAUGE +tps.label TPS +"); +exit(); +} + +// Include JSONAPI.php SDK (get this file here: https://github.com/alecgorge/jsonapi/raw/master/sdk/php/JSONAPI.php) +require('/var/cache/munin/JSONAPI.php'); + +// Prepare API call +$api = new JSONAPI($hostname, $port, $username, $password, $salt); +$result = $api->call("system.getServerClockDebug"); + +// Check for success +if ($result['result'] == 'success'){ + // Print values + print('tps.value ' . round($result['success']['clockRate'], 2) . "\n"); +} +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcsqls2killshostile b/plugins/minecraft/jsonapi/mcsqls2killshostile new file mode 100644 index 00000000..46ec0617 --- /dev/null +++ b/plugins/minecraft/jsonapi/mcsqls2killshostile @@ -0,0 +1,161 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / Statistician - hostile mob kills per day +graph_category bukkit_sql_kills +graph_vlabel hostile mob kills per day +graph_args --base 1000 -l 0 +blaze.type GAUGE +blaze.label killed blazes +spider.type GAUGE +spider.label killed spiders +creeper.type GAUGE +creeper.label killed creepers +ghast.type GAUGE +ghast.label killed ghasts +magmacube.type GAUGE +magmacube.label killed magma cubes +silverfish.type GAUGE +silverfish.label killed silverfish +skeleton.type GAUGE +skeleton.label killed skeletons +slime.type GAUGE +slime.label killed slimes +witch.type GAUGE +witch.label killed witches +zombie.type GAUGE +zombie.label killed zombies +irongolem.type GAUGE +irongolem.label killed iron golems +enderdragon.type GAUGE +enderdragon.label killed ender dragons +wither.type GAUGE +wither.label killed withers +"); +exit(); +} + +## Construct 'minumum' 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 for blaze kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Blaze'")) { + ## Print values + print('blaze.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for spider kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = '%Spider'")) { + ## Print values + print('spider.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for creeper kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = '%reeper%'")) { + ## Print values + print('creeper.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for ghast kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Ghast'")) { + ## Print values + print('ghast.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for magma cube kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'MagmaCube'")) { + ## Print values + print('magmacube.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for silverfish and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Silverfish'")) { + ## Print values + print('silverfish.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for skeleton kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Skeleton'")) { + ## Print values + print('skeleton.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for slime kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Slime'")) { + ## Print values + print('slime.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for witch kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Witch'")) { + ## Print values + print('witch.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for zombie kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Zombie'")) { + ## Print values + print('zombie.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for iron golem kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = '%ron%'")) { + ## Print values + print('irongolem.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for ender dragon kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'EnderDragon'")) { + ## Print values + print('enderdragon.value ' . mysqli_num_rows($result) . "\n"); +} + +## Select queries for wither kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Wither'")) { + ## Print values + print('wither.value ' . mysqli_num_rows($result) . "\n"); +} + +## Close connection +mysqli_close($connection); +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcsqls2killsneutral b/plugins/minecraft/jsonapi/mcsqls2killsneutral new file mode 100644 index 00000000..2f222f92 --- /dev/null +++ b/plugins/minecraft/jsonapi/mcsqls2killsneutral @@ -0,0 +1,89 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / Statistician - neutral mob kills per day +graph_category bukkit_sql_kills +graph_vlabel neutral mob kills per day +graph_args --base 1000 -l 0 +enderman.type GAUGE +enderman.label killed endermen +wolf.type GAUGE +wolf.label killed wolf +zombiepigman.type GAUGE +zombiepigman.label killed zombie pigmen +snowman.type GAUGE +snowman.label killed snowmen +"); +exit(); +} + +// Construct 'minumum' 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 for enderman and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Enderman'")) { + // Print values + print('enderman.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for wolf kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Wolf'")) { + // Print values + print('wolf.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for zombie pigman kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Zombie Pigman'")) { + // Print values + print('zombiepigman.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for zombie snowman kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Snowman'")) { + // Print values + print('snowman.value ' . mysqli_num_rows($result) . "\n"); +} + +// Close connection +mysqli_close($connection); +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcsqls2killspassive b/plugins/minecraft/jsonapi/mcsqls2killspassive new file mode 100644 index 00000000..b0e5b430 --- /dev/null +++ b/plugins/minecraft/jsonapi/mcsqls2killspassive @@ -0,0 +1,129 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / Statistician - passive mob kills per day +graph_category bukkit_sql_kills +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(); +} + +// Construct 'minumum' 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 for bat kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Bat'")) { + // Print values + print('bat.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for chicken kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Chicken'")) { + // Print values + print('chicken.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for mooshroom kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'MushroomCow'")) { + // Print values + print('mooshroom.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for cow kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Cow'")) { + // Print values + print('cow.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for ocelot kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Ocelot'")) { + // Print values + print('ocelot.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for pig kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Pig'")) { + // Print values + print('pig.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for sheep and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Sheep'")) { + // Print values + print('sheep.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for squid kills and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Squid'")) { + // Print values + print('squid.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for villager and return the amount of rows +if ($result = mysqli_query($connection, "SELECT id FROM killchart WHERE time > $today AND killed_creature_type = 'Villager'")) { + // Print values + print('villager.value ' . mysqli_num_rows($result) . "\n"); +} + +// Close connection +mysqli_close($connection); +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcsqls2players b/plugins/minecraft/jsonapi/mcsqls2players new file mode 100644 index 00000000..4b44d470 --- /dev/null +++ b/plugins/minecraft/jsonapi/mcsqls2players @@ -0,0 +1,65 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / Statistician - new players per day +graph_category bukkit_sql +graph_vlabel new players per day +graph_args --base 1000 -l 0 +players.type GAUGE +players.label new players +"); +exit(); +} + +// Construct 'minumum' 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); +?> \ No newline at end of file diff --git a/plugins/minecraft/jsonapi/mcsqlubshame b/plugins/minecraft/jsonapi/mcsqlubshame new file mode 100644 index 00000000..302203c8 --- /dev/null +++ b/plugins/minecraft/jsonapi/mcsqlubshame @@ -0,0 +1,140 @@ +#!/usr/bin/php + 1) && ($argv[1] == 'config')) +{ +print("graph_title Bukkit / Ultrabans - shame per day +graph_category bukkit_sql +graph_vlabel amount of shame per day +graph_args --base 1000 -l 0 +unban.type GAUGE +unban.label unbans +kick.type GAUGE +kick.label kicks +warning.type GAUGE +warning.label warnings +ban.type GAUGE +ban.label bans +ipban.type GAUGE +ipban.label ipbans +fine.type GAUGE +fine.label fines +jail.type GAUGE +jail.label jails +permban.type GAUGE +permban.label permbans +mute.type GAUGE +mute.label mutes +"); +exit(); +} + +// Construct 'minumum' 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 for unbans return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 5 AND time > $today")) { + // Print values + print('unban.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for kicks return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 3 AND time > $today")) { + // Print values + print('kick.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for warnings return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 2 AND time > $today")) { + // Print values + print('warning.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for bans return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 0 AND time > $today")) { + // Print values + print('ban.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for ipbans return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 1 AND time > $today")) { + // Print values + print('ipban.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for fines return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 4 AND time > $today")) { + // Print values + print('fine.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for jails return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 6 AND time > $today")) { + // Print values + print('jail.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for permbans return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 9 AND time > $today")) { + // Print values + print('permban.value ' . mysqli_num_rows($result) . "\n"); +} + +// Select queries for mutes - part 1 return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 7 AND time > $today")) { + // Store result + $tmp1 = mysqli_num_rows($result); +} + +// Select queries for mutes - part 2 return the amount of rows +if ($result = mysqli_query($connection, "SELECT name FROM banlist WHERE type = 8 AND time > $today")) { + // Store result + $tmp2 = mysqli_num_rows($result); +} + +$mutes = $tmp1 + $tmp2; + +print('mute.value ' . $mutes . "\n"); + +// Close connection +mysqli_close($connection); +?> \ No newline at end of file