Last active
August 29, 2015 14:23
-
-
Save miry/b82eeb413a018b028ad4 to your computer and use it in GitHub Desktop.
Simple script to send metrics from presto to graphite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Install dependicies: | |
# gem install graphite-api | |
# gem install presto-client | |
# gem install presto-metrics | |
require 'rubygems' | |
require 'graphite-api' | |
require 'presto/metrics' | |
require 'logger' | |
GraphiteAPI::Logger.logger = ::Logger.new(STDOUT) | |
GraphiteAPI::Logger.logger.level = ::Logger::DEBUG | |
# 10.0.8.30 | |
c = GraphiteAPI.new( | |
graphite: "10.0.8.30:2003", # required argument | |
prefix: ["stats","prestodb","jmx"] # add example.prefix to each key | |
) | |
client = Presto::Metrics::Client.new(:host => "localhost", :port=>8083) | |
def report(c, col={}, prefix="") | |
col.each do |k, v| | |
key = prefix+"."+k | |
if v.is_a?(Hash) | |
report c, v, key | |
elsif v.is_a?(String) | |
next | |
else | |
c.metrics( key => v) | |
end | |
end | |
end | |
while 1 do | |
client.os_metrics.each do |k, v| | |
next if v.is_a?(Hash) || v.is_a?(String) | |
c.metrics( "os_metrics.#{k}" => v) | |
end | |
client.node_metrics.each do |n| | |
h = n["host"].gsub('.','-') | |
n.each do |k,v| | |
next if k == "host" || v.is_a?(Hash) || v.is_a?(String) | |
c.metrics( "node_metrics.#{h}.#{k}" => v) | |
end | |
end | |
report c, client.gc_g1_metrics, "gc_g1_metrics" | |
sleep 30 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment