Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Pull stats from Statsd's mgmt_server #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions lib/mgmt_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'socket'

class Statsd
class MgmtServer

METHODS_ALLOWED = ["counters", "timers", "gauges", "sets"]

def initialize(host="localhost", port=8126)
@host = host
@port = port
end

def request_server(stat)
@mgmt_server ||= TCPSocket.new(@host, @port)
@mgmt_server.puts stat
parse_response
end

def parse_response
#return if @parsing_stats
#@parsing_stats = true

response = @mgmt_server.gets.strip
#return ERROR if statsd returns error
return "ERROR" if ( response == "ERROR" )

#concatenate the data to a string and return
#statsd returns END on completion
while( (l = @mgmt_server.gets.strip) != "END")
response += l
end
#@parsing_stats = false
response
end

def method_missing(m, *args)
raise NoMethodError if !(METHODS_ALLOWED.include?(m.to_s))
Statsd::MgmtServer.new.send(:request_server, m.to_sym)
end
end
end