Sha256: e8280279086ac9099cf9b9c51d3829c17163734ceded0834fc57cebcf3ffbd66
Contents?: true
Size: 1.95 KB
Versions: 2
Compression:
Stored size: 1.95 KB
Contents
require 'chaoite/version' require 'json' require 'chaoite/handler' require 'optparse' require 'graphite-api' require 'graphite-api/core_ext/numeric' module Chaoite DEFAULT_OPTIONS = { :config_file => 'config.json', :server => 'localhost', :port => 2003 } def self.run(args) options = DEFAULT_OPTIONS parser = setup_parser(options) parser.parse! if(!File.exists?(options[:config_file])) puts "Config file #{options[:config_file]} does not exist. see --help for usage" exit end configs = JSON.parse(File.read(options[:config_file])) puts "Starting up Chaoite" client = GraphiteAPI.new(:graphite => "#{options[:server]}:#{options[:port]}") client.every 10.seconds do |c| configs.each do |config| metric = Handler.send("#{config["type"]}_#{config["value"]}", config) if(metric) then puts "Sending metric #{metric}" c.metrics(metric) else puts "Empty metric for '#{config["name"]}', not sending." end end end begin sleep 2 while true rescue Interrupt => e puts "Shutting down Chaoite" end end def self.setup_parser(options) OptionParser.new do |opts| opts.banner = "Usage: chaoite [options]" opts.on('-c', '--config-file config_file', "Path to config file. Defaults to #{options[:config_file]}") do |config_file| options[:config_file] = config_file end opts.on('-g', '--graphite-server server', "Graphite server url. Defaults to #{options[:server]}") do |server| options[:server] = server end opts.on('-p', '--graphite-port port', "Graphite port. Defaults to #{options[:port]}") do |port| options[:port] = port end opts.on('-h', '--help', 'Displays Help') do puts opts exit end opts.on('-v', '--version', 'Displays version string') do puts Chaoite::VERSION exit end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chaoite-0.1.5 | lib/chaoite.rb |
chaoite-0.1.4 | lib/chaoite.rb |