Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'loggregator_emitter'
require 'net/http'
require 'json'
nats_ip = '10.0.16.11'
nats_monitor_port = 4333
metron_port = 3457
@http = Net::HTTP.new(nats_ip, nats_monitor_port)
@get_varz = Net::HTTP::Get.new('/varz')
@emitter = LoggregatorEmitter::Emitter.new("127.0.0.1:#{metron_port}", 'origin', 'NAT')
def emit_metric(name, value)
puts "Emitting metric cf.origin.#{name} = #{value}"
@emitter.emit_value_metric(name, value, '')
end
while true do
response = @http.request(@get_varz)
stats = JSON.load(response.body)
emit_metric 'colin.nats.in_msgs', stats['in_msgs']
emit_metric 'colin.nats.out_msgs', stats['out_msgs']
emit_metric 'colin.nats.connections', stats['connections']
sleep(5)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment