Class: PulseToolbox::Sensor::Manager

Inherits:
Object
  • Object
show all
Extended by:
PulseToolbox::Sensor::Mixins::Iterators
Defined in:
lib/pulse_toolbox/sensor/manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from PulseToolbox::Sensor::Mixins::Iterators

each_group, each_group_with_title, each_sensor, each_sensor_in_group, sensors

Instance Attribute Details

#configuratorPulseMeter::Sensor::Configuration

Returns configurator instance.

Returns:

  • (PulseMeter::Sensor::Configuration)

    configurator instance



23
# File 'lib/pulse_toolbox/sensor/manager.rb', line 23

class_attribute :configurator

#default_optionsHash

Returns default sensor options.

Returns:

  • (Hash)

    default sensor options



17
# File 'lib/pulse_toolbox/sensor/manager.rb', line 17

class_attribute :default_options

#monitoring_layoutPulseMeter::Visualize::DSL::Layout

Returns layout for monitoring page.

Returns:

  • (PulseMeter::Visualize::DSL::Layout)

    layout for monitoring page



26
# File 'lib/pulse_toolbox/sensor/manager.rb', line 26

class_attribute :monitoring_layout

#sensors_configHash

Returns sensors config.

Returns:

  • (Hash)

    sensors config



20
# File 'lib/pulse_toolbox/sensor/manager.rb', line 20

class_attribute :sensors_config

Class Method Details

.add_group(name, title = nil) ⇒ Object

Adds group to config

Parameters:

  • name (Symbol)

    group name

  • title (String) (defaults to: nil)

    group title



212
213
214
215
216
217
218
# File 'lib/pulse_toolbox/sensor/manager.rb', line 212

def add_group(name, title = nil)
  name = name.to_sym
  sensors_config[name] ||= {}
  sensors_config[name][:title] = title if title
  sensors_config[name][:sensors] ||= {}
  return name
end

.add_sensor(group, name, options) ⇒ Object

Adds sensor to group in config

Parameters:

  • group (Symbol)

    group name

  • name (Symbol)

    sensor name

  • options (Hash)

    sensor options



224
225
226
227
228
229
# File 'lib/pulse_toolbox/sensor/manager.rb', line 224

def add_sensor(group, name, options)
  name = name.to_sym
  g = add_group(group)
  sensors_config[g][:sensors][name] = options
  return name_in_group(group, name)
end

.create_sensorsObject

Creates all sensors from sensors_config



161
162
163
164
165
166
167
168
# File 'lib/pulse_toolbox/sensor/manager.rb', line 161

def self.create_sensors
  PulseToolbox.maybe_reconnect
  config = cfg
  self.configurator = PulseMeter::Sensor::Configuration.new(cfg)
  each_sensor do |s|
    s.color = config[s.name.to_sym][:color]
  end
end

.event(sensor, value) ⇒ Object

Sends value to sensor by name

Parameters:

  • sensor (Symbol)

    sensor name

  • value (Float)

    event value



205
206
207
# File 'lib/pulse_toolbox/sensor/manager.rb', line 205

def event(sensor, value)
  lazy_configurator.sensor(sensor).event(value)
end

.layout {|monitoring_layout| ... } ⇒ Object

Returns monitoring page layout

Yields:



232
233
234
235
# File 'lib/pulse_toolbox/sensor/manager.rb', line 232

def layout
  yield(monitoring_layout)
  monitoring_layout
end

.log_request(total_time, payload) ⇒ Object

Logs rails request timing to various sensors

Parameters:

  • total_time (Float)

    total request time

  • view_time (Float)

    view time of request

  • db_time (Float)

    db time of request



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/pulse_toolbox/sensor/manager.rb', line 175

def log_request(total_time, payload)
  view_time = payload[:view_runtime]
  db_time = payload[:db_runtime]

  lazy_configurator
  PulseToolbox.redis.multi do
    {
      max_db_time: db_time,
      max_view_time: view_time,
      max_total_time: total_time,

      p95_db_time: db_time,
      p95_view_time: view_time,
      p95_total_time: total_time,

      p99_db_time: db_time,
      p99_view_time: view_time,
      p99_total_time: total_time,

      status_count: {payload[:status].to_s => 1},
      status_total: 1,

      action_count: {"#{payload[:controller]}##{payload[:action]}" => 1}
    }.each_pair {|name, value| event(name, value)}
  end
end