Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cloudscopes-setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'fileutils'

basedir = File.expand_path(File.dirname(__FILE__) + "/..")
FileUtils.mkdir_p '/etc/cloudscopes/monitor.d'
FileUtils.mkdir_p '/etc/cloudscopes/metric_definition.d'
FileUtils.cp "#{basedir}/config/cron.config", '/etc/cron.d/cloudscopes-monitoring'
FileUtils.cp "#{basedir}/config/monitoring.yaml", '/etc/cloudscopes/monitor.conf'
FileUtils.chmod 0600, '/etc/cron.d/cloudscopes-monitoring'
2 changes: 1 addition & 1 deletion config/monitoring.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
settings:
configdir: /etc/cloudscopes/monitor.d
metric_definition_dir: /etc/cloudscopes/metric_definition.d
interval: 60
provider: cloudwatch
#key: AWS_KEY_ID
Expand Down
6 changes: 0 additions & 6 deletions lib/cloudscopes.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
require 'rubygems'

#require 'bundler/setup' #if ENV['BUNDLE_GEMFILE'] && File.exists?(ENV['BUNDLE_GEMFILE'])

require 'aws-sdk'
require 'optparse'
require 'ffi'

require 'cloudscopes/version'
Expand Down
25 changes: 20 additions & 5 deletions lib/cloudscopes/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
require 'yaml'
require 'aws-sdk'

module Cloudscopes

class << self
def init
@opts = Cloudscopes::Options.new
configuration = {}
(@opts.files.empty?? [ STDIN ] : @opts.files.collect { |fn| File.new(fn) }).each do |configfile|
configuration.merge! YAML.load(configfile.read)
end
configuration = YAML.load(File.read(@opts.config_file))
@settings = configuration['settings']
configuration['metrics']
@metrics = configuration['metrics'] || {}
if metric_dir = @settings['metric_definition_dir']
merge_metric_definitions(Dir.glob("#{metric_dir}/*").select(&File.method(:file?)))
end
@metrics
end

def should_publish
Expand All @@ -28,5 +32,16 @@ def initClient
def data_dimensions
@settings['dimensions'] || ({ 'InstanceId' => '#{ec2.instance_id}' })
end

private

def merge_metric_definitions(files)
files.each do |metric_file|
YAML.load(File.read(metric_file)).each do |namespace, definitions|
@metrics[namespace] ||= []
@metrics[namespace] += definitions
end
end
end
end
end
16 changes: 12 additions & 4 deletions lib/cloudscopes/options.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
require 'optparse'

module Cloudscopes

class Options

attr_reader :publish, :files
attr_reader :publish, :config_file

def initialize
@publish = true
@files = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options] [<config.yaml>]\n\nOptions:"
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options] <config.yaml>\n\nOptions:"
opts.on("-t", "dump samples to the console instead of publishing, for testing") { @publish = false }
opts.on_tail("-?", "-h", "--help", "Show this message") do
puts(opts)
exit
end
end.parse!
end
arguments = option_parser.parse!
unless arguments.size == 1
$stderr.puts(option_parser)
exit 1
end
@config_file = arguments.first
end
end

Expand Down