2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/minecraft/minecraft-users
Matt Stith bc344d005e 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.
2012-03-05 23:11:27 -05:00

36 lines
No EOL
809 B
Ruby
Executable file

#!/usr/local/bin/ruby
# Config:
# [minecraft_users]
# env.host awesomeserver.com
# env.port 25566
#
require 'socket'
if ARGV[0] == 'config'
puts "graph_title Connected players"
puts "graph_vlabel players"
puts "players.label players"
puts "graph_info Number of players connected to Minecraft"
puts "graph_category Minecraft"
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}"