class SnowmanIO::Spider::Mps
Metrics per second
Public Instance Methods
grab()
click to toggle source
# File lib/snowman-io/spider/mps.rb, line 5 def grab # work with raw datapoints for simplicity key = Utils.floor_5min(Time.now) value = Aggregation.where(precision: "5min", at: key).map(&:count).sum/300.0 prev_value = Aggregation.where(precision: "5min", at: key - 5.minutes).map(&:count).sum/300.0 name = "Metrics Per Second" app = App.where(system: true).first metric = app.metrics.where(name: name, kind: "amount").first_or_create! metric.update_attributes!(last_value: value, last_value_updated_at: Time.now) point = metric.data_points.where(at: key).first_or_create! point.update_attributes!(value: value) prev_point = metric.data_points.where(at: key - 5.minutes).first_or_create! prev_point.update_attributes!(value: prev_value) app.touch end