1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 10:39:53 +00:00

Switch to Ruby and MineQuery to remove an extra plugin dependency

Most servers have minequery installed already, no need to also have OnlinePlayers when this is what MineQuery was built for.
This commit is contained in:
Matt Stith 2012-03-05 23:11:27 -05:00
parent ddc46f88fd
commit bc344d005e

View file

@ -1,32 +1,36 @@
#!/bin/sh #!/usr/local/bin/ruby
# Config: # Config:
# [minecraft_players # [minecraft_users]
# playerfile /etc/minecraft/players.txt # env.host awesomeserver.com
# subtract true # env.port 25566
# #
# playerfile - location of player list file, for example from the OnlineUsers
# plugin
# subtract - OnlineUsers has a header above the user list, set this to true
# to subtract 1 from the output to compensate
case $1 in
config)
cat <<'EOM'
graph_title Connected players
graph_vlabel players
players.label players
graph_info Number of players connected to Minecraft
graph_category Minecraft
EOM
exit 0;;
esac
echo -n "players.value " require 'socket'
count=`wc -l ${playerfile} | cut -d' ' -f1` if ARGV[0] == 'config'
if [ $subtract="true" ]; puts "graph_title Connected players"
then puts "graph_vlabel players"
echo -n "$(($count - 1))" puts "players.label players"
else puts "graph_info Number of players connected to Minecraft"
echo $count puts "graph_category Minecraft"
fi exit
end
host = ENV['host']
host = 'localhost' unless host
port = ENV['port']
port = '25566' unless port
socket = TCPSocket.new(host, port)
socket.puts "QUERY"
response = socket.read
response = response.split("\n")
server_port = response[0].split(" ", 2)[1].to_i
player_count = response[1].split(" ", 2)[1].to_i
max_players = response[2].split(" ", 2)[1].to_i
player_list = response[3].split(" ", 2)[1].chomp[1..-2]
puts "players.value #{player_count}"