Repository
Munin (contrib)
Last change
2020-08-25
Graph Categories
Keywords
Language
Ruby

minecraft-users

Sadly there is no documentation for this plugin.

#!/usr/bin/env 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 games'
  exit
end

host = ENV['host']
host ||= 'localhost'

port = ENV['port']
port ||= '25566'

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}"