Sha256: f9e3145f517469a6d794ce7bef7d2b724f5ce52a3a4ce71f8980703ce0281367
Contents?: true
Size: 1.36 KB
Versions: 21
Compression:
Stored size: 1.36 KB
Contents
require 'elasticsearch' require 'date' require 'uri' class RedisStat class ElasticsearchSink attr_reader :hosts, :info, :index, :client DEFAULT_INDEX = 'redis-stat' def self.parse_url elasticsearch unless elasticsearch.match(%r[^https?://]) elasticsearch = "http://#{elasticsearch}" end uri = URI.parse elasticsearch path = uri.path index = path == '' ? DEFAULT_INDEX : path.split('/').last uri.path = '' [uri.to_s, index] end def initialize hosts, elasticsearch url, @index = elasticsearch @hosts = hosts @client = Elasticsearch::Client.new :url => url end def output info @hosts.each do |host| entries = Hash[info.map { |k, v| if v.has_key?(host) && raw = v[host].last [k, raw] end }.compact] next if entries.empty? time = entries[:at] entry = { :index => index, :type => "redis", :body => entries.merge({ :@timestamp => format_time(time), :host => host, :at => time.to_f }), } client.index entry end end private if RUBY_VERSION.start_with? '1.8.' def format_time time fmt = time.strftime("%FT%T%z") fmt[0..-3] + ':' + fmt[-2..-1] end else def format_time time time.strftime("%FT%T%:z") end end end end
Version data entries
21 entries across 21 versions & 1 rubygems
Version | Path |
---|---|
redis-stat-0.4.4 | lib/redis-stat/elasticsearch.rb |