mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
commit
27ccc1d3ce
@ -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}"
|
Loading…
Reference in New Issue
Block a user