Class: Bipbip::Storage::Copperegg
- Inherits:
-
Bipbip::Storage
- Object
- Bipbip::Storage
- Bipbip::Storage::Copperegg
- Defined in:
- lib/bipbip/storage/copperegg.rb
Instance Attribute Summary
Attributes inherited from Bipbip::Storage
Instance Method Summary collapse
- #_load_dashboards ⇒ Object
- #_load_metric_groups ⇒ Object
-
#initialize(name, config) ⇒ Copperegg
constructor
A new instance of Copperegg.
- #setup_plugin(plugin) ⇒ Object
- #store_sample(plugin, time, data) ⇒ Object
Methods inherited from Bipbip::Storage
Constructor Details
#initialize(name, config) ⇒ Copperegg
5 6 7 8 |
# File 'lib/bipbip/storage/copperegg.rb', line 5 def initialize(name, config) super(name, config) CopperEgg::Api.apikey = config['api_key'] end |
Instance Method Details
#_load_dashboards ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/bipbip/storage/copperegg.rb', line 59 def _load_dashboards Bipbip.logger.info 'Loading copperegg dashboards' dashboards = CopperEgg::CustomDashboard.find if dashboards.nil? Bipbip.logger.fatal 'Cannot load copperegg dashboards' exit 1 end dashboards end |
#_load_metric_groups ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/bipbip/storage/copperegg.rb', line 49 def _load_metric_groups Bipbip.logger.info 'Loading copperegg metric groups' metric_groups = CopperEgg::MetricGroup.find if metric_groups.nil? Bipbip.logger.fatal 'Cannot load copperegg metric groups' exit 1 end metric_groups end |
#setup_plugin(plugin) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bipbip/storage/copperegg.rb', line 10 def setup_plugin(plugin) @metric_groups ||= _load_metric_groups @dashboards ||= _load_dashboards if ![5, 15, 60, 300, 900, 3600, 21600].include?(plugin.frequency) Bipbip.logger.fatal "Copperegg cannot use frequency #{plugin.frequency}" exit 1 end metric_group = @metric_groups.detect { |m| m.name == plugin.metric_group } if metric_group.nil? || !metric_group.is_a?(CopperEgg::MetricGroup) Bipbip.logger.info "Creating copperegg metric group `#{plugin.metric_group}`" metric_group = CopperEgg::MetricGroup.new(:name => plugin.metric_group, :label => plugin.metric_group, :frequency => plugin.frequency) end metric_group.frequency = plugin.frequency metric_group.metrics = plugin.metrics_schema.map do |sample| { :name => sample[:name], :type => 'ce_' + sample[:type], :unit => sample[:unit], } end metric_group.save dashboard = @dashboards.detect { |d| d.name == plugin.metric_group } if dashboard.nil? Bipbip.logger.info "Creating copperegg dashboard `#{plugin.metric_group}`" metrics = metric_group.metrics || [] CopperEgg::CustomDashboard.create(metric_group, :name => plugin.metric_group, :identifiers => nil, :metrics => metrics) end end |
#store_sample(plugin, time, data) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/bipbip/storage/copperegg.rb', line 42 def store_sample(plugin, time, data) response = CopperEgg::MetricSample.save(plugin.metric_group, plugin.source_identifier, time.to_i, data) if response.code != '200' raise("Cannot store copperegg data `#{data}`. Response code `#{response.code}`, message `#{response.message}`, body `#{response.body}`") end end |