Class: Dash::Config
Instance Attribute Summary collapse
-
#clusters ⇒ Object
readonly
Returns the value of attribute clusters.
-
#dashboards ⇒ Object
readonly
Returns the value of attribute dashboards.
-
#global_config ⇒ Object
readonly
Returns the value of attribute global_config.
-
#graphs ⇒ Object
readonly
Returns the value of attribute graphs.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #reload! ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/config.rb', line 14 def initialize port = 9292 @rawconfig = {} @confdir = "." optparse = OptionParser.new do |o| o.on("-d", "--config-dir DIR", "location of the config directory (default .)") do |arg| @confdir = arg end o.on("-p", "--port PORT", "port to bind to (default 9292)") do |arg| port = arg.to_i end end optparse.parse! reload! @global_config[:port] = port end |
Instance Attribute Details
#clusters ⇒ Object (readonly)
Returns the value of attribute clusters.
11 12 13 |
# File 'lib/config.rb', line 11 def clusters @clusters end |
#dashboards ⇒ Object (readonly)
Returns the value of attribute dashboards.
8 9 10 |
# File 'lib/config.rb', line 8 def dashboards @dashboards end |
#global_config ⇒ Object (readonly)
Returns the value of attribute global_config.
12 13 14 |
# File 'lib/config.rb', line 12 def global_config @global_config end |
#graphs ⇒ Object (readonly)
Returns the value of attribute graphs.
9 10 11 |
# File 'lib/config.rb', line 9 def graphs @graphs end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
10 11 12 |
# File 'lib/config.rb', line 10 def hosts @hosts end |
Instance Method Details
#reload! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/config.rb', line 34 def reload! configs = Dir.glob("#{@confdir}/*.y{a,}ml") configs.each { |c| @rawconfig.merge!(YAML.load(File.read(c))) } [:graphs, :dashboards, :config].each do |c| if not @rawconfig[c] raise "Missing config name '#{c.to_s}'" end end @global_config = @rawconfig[:config] # do some sanity checking of other configuration parameters [:graphite_url, :url_opts].each do |c| if not @global_config[c] raise "Missing config name '#{c.to_s}'" end end # possibly check more url_opts here as well if @global_config[:url_opts][:start] if !ChronicDuration.parse(@global_config[:url_opts][:start]) raise "bad default timespec in :url_opts" end end @global_config[:default_colors] ||= ["blue", "green", "yellow", "red", "purple", "brown", "aqua", "gold"] if @global_config[:refresh_rate] duration = ChronicDuration.parse(@global_config[:refresh_rate].to_s) if !duration raise "couldn't parse key :refresh_rate" end @global_config[:refresh_rate] = duration end @global_config[:metric_format] ||= "%m.%c.%h" if @global_config[:metric_format] !~ /%m/ raise "missing metric (%m) in :metric_format" elsif @global_config[:metric_format] !~ /%c/ raise "missing cluster (%c) in :metric_format" elsif @global_config[:metric_format] !~ /%h/ raise "missing host (%h) in :metric_format" end graphs_new = [] @rawconfig[:graphs].each do |name, config| graphs_new << Graph.new(name, config.merge(@global_config)) end dashboards_new = [] @rawconfig[:dashboards].each do |name, config| dashboards_new << Dashboard.new(name, config.merge(@global_config)) end hosts_new = Set.new clusters_new = Set.new # generate host and cluster information at init time graphs_new.each do |g| hosts, clusters = g.hosts_clusters hosts.each { |h| hosts_new << h } clusters.each { |h| clusters_new << h } end @dashboards, @graphs = dashboards_new, graphs_new @hosts, @clusters = hosts_new, clusters_new end |