Class: Expri::Metric
- Inherits:
-
Object
- Object
- Expri::Metric
- Defined in:
- lib/expri/metric.rb
Constant Summary collapse
- ATTRIBUTE_DEFAULTS =
{ :frequency => 3 }.freeze
- VALID_ATTRIBUTES =
%w{divisor frequency key percentile predicate predicate2 type window value}.map { |x| x.to_sym }.freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #api ⇒ Object
-
#attributes_without_defaults ⇒ Object
only the attributes that are not at their default value.
- #destroy ⇒ Object
- #get ⇒ Object
-
#initialize(name, attributes = {}, options = {}) ⇒ Metric
constructor
A new instance of Metric.
- #post ⇒ Object
- #put ⇒ Object
Constructor Details
#initialize(name, attributes = {}, options = {}) ⇒ Metric
Returns a new instance of Metric.
14 15 16 17 18 |
# File 'lib/expri/metric.rb', line 14 def initialize(name, attributes={}, ={}) @name = name @options = self.attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/expri/metric.rb', line 7 def attributes @attributes end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/expri/metric.rb', line 7 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/expri/metric.rb', line 7 def @options end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
20 21 22 |
# File 'lib/expri/metric.rb', line 20 def ==(other) attributes_without_defaults == other.attributes_without_defaults end |
#api ⇒ Object
24 25 26 |
# File 'lib/expri/metric.rb', line 24 def api @api ||= Excon.new(api_url) end |
#attributes_without_defaults ⇒ Object
only the attributes that are not at their default value
44 45 46 47 |
# File 'lib/expri/metric.rb', line 44 def attributes_without_defaults attributes = @attributes.dup attributes.delete_if { |k, v| ATTRIBUTE_DEFAULTS[k] == v } end |
#destroy ⇒ Object
49 50 51 52 53 |
# File 'lib/expri/metric.rb', line 49 def destroy puts "destroy name=#{name}" if @options[:verbose] api.delete(path: "/metrics/#{name}", body: MultiJson.encode(@attributes), expects: 200) end |
#get ⇒ Object
55 56 57 58 59 |
# File 'lib/expri/metric.rb', line 55 def get puts "show name=#{name}" if @options[:verbose] self.attributes = MultiJson.decode(api.get(path: "/metrics/#{name}", expects: 200).body) end |
#post ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/expri/metric.rb', line 61 def post puts "create name=#{name}" if @options[:verbose] # exprd's put is like most api's post api.put(path: "/metrics/#{name}", body: MultiJson.encode(@attributes), expects: 200) rescue Excon::Errors::BadRequest => e = MultiJson.decode(e.response.body)["message"] raise() end |