Class: Snmp2mkr::Metric
- Inherits:
-
Object
- Object
- Snmp2mkr::Metric
- Defined in:
- lib/snmp2mkr/metric.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#oid ⇒ Object
readonly
Returns the value of attribute oid.
-
#transformations ⇒ Object
readonly
Returns the value of attribute transformations.
-
#vhost_name ⇒ Object
readonly
Returns the value of attribute vhost_name.
Instance Method Summary collapse
- #evaluate(varbind, state_holder: nil, time: Time.now) ⇒ Object
-
#initialize(vhost, name, oid, mib: nil, transformations: []) ⇒ Metric
constructor
A new instance of Metric.
- #safe_name ⇒ Object
Constructor Details
#initialize(vhost, name, oid, mib: nil, transformations: []) ⇒ Metric
Returns a new instance of Metric.
5 6 7 8 9 10 |
# File 'lib/snmp2mkr/metric.rb', line 5 def initialize(vhost, name, oid, mib: nil, transformations: []) @vhost_name = vhost.name @name = name @oid = oid.kind_of?(Oid) ? oid : Oid.new(oid, mib: mib) @transformations = transformations end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/snmp2mkr/metric.rb', line 12 def name @name end |
#oid ⇒ Object (readonly)
Returns the value of attribute oid.
12 13 14 |
# File 'lib/snmp2mkr/metric.rb', line 12 def oid @oid end |
#transformations ⇒ Object (readonly)
Returns the value of attribute transformations.
12 13 14 |
# File 'lib/snmp2mkr/metric.rb', line 12 def transformations @transformations end |
#vhost_name ⇒ Object (readonly)
Returns the value of attribute vhost_name.
12 13 14 |
# File 'lib/snmp2mkr/metric.rb', line 12 def vhost_name @vhost_name end |
Instance Method Details
#evaluate(varbind, state_holder: nil, time: Time.now) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/snmp2mkr/metric.rb', line 18 def evaluate(varbind, state_holder: nil, time: Time.now) if varbind == SNMP::NoSuchObject || varbind == SNMP::NoSuchInstance return nil end if state_holder state = state_holder.fetch(self) end raw = val = varbind.value.to_i transformations.each do |xfrm| val = transform(xfrm, val, state, time) end if state_holder state_holder.set(self, state.merge(last: val, last_raw: raw, last_at: time)) end return val end |
#safe_name ⇒ Object
14 15 16 |
# File 'lib/snmp2mkr/metric.rb', line 14 def safe_name name.gsub(/[^a-zA-Z0-9._-]/, '-') end |