Skip to content

Instantly share code, notes, and snippets.

@saliceti
Created October 12, 2016 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saliceti/773e09335042ad4ad7841d6944878fa2 to your computer and use it in GitHub Desktop.
Save saliceti/773e09335042ad4ad7841d6944878fa2 to your computer and use it in GitHub Desktop.
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