Class: PulseToolbox::Sensor::Manager
- Inherits:
-
Object
- Object
- PulseToolbox::Sensor::Manager
- Extended by:
- PulseToolbox::Sensor::Mixins::Iterators
- Defined in:
- lib/pulse_toolbox/sensor/manager.rb
Instance Attribute Summary collapse
-
#configurator ⇒ PulseMeter::Sensor::Configuration
Configurator instance.
-
#default_options ⇒ Hash
Default sensor options.
-
#monitoring_layout ⇒ PulseMeter::Visualize::DSL::Layout
Layout for monitoring page.
-
#sensors_config ⇒ Hash
Sensors config.
Class Method Summary collapse
-
.add_group(name, title = nil) ⇒ Object
Adds group to config.
-
.add_sensor(group, name, options) ⇒ Object
Adds sensor to group in config.
-
.create_sensors ⇒ Object
Creates all sensors from sensors_config.
-
.event(sensor, value) ⇒ Object
Sends value to sensor by name.
-
.layout {|monitoring_layout| ... } ⇒ Object
Returns monitoring page layout.
-
.log_request(total_time, payload) ⇒ Object
Logs rails request timing to various sensors.
Methods included from PulseToolbox::Sensor::Mixins::Iterators
each_group, each_group_with_title, each_sensor, each_sensor_in_group, sensors
Instance Attribute Details
#configurator ⇒ PulseMeter::Sensor::Configuration
Returns configurator instance.
23 |
# File 'lib/pulse_toolbox/sensor/manager.rb', line 23 class_attribute :configurator |
#default_options ⇒ Hash
Returns default sensor options.
17 |
# File 'lib/pulse_toolbox/sensor/manager.rb', line 17 class_attribute :default_options |
#monitoring_layout ⇒ PulseMeter::Visualize::DSL::Layout
Returns layout for monitoring page.
26 |
# File 'lib/pulse_toolbox/sensor/manager.rb', line 26 class_attribute :monitoring_layout |
#sensors_config ⇒ Hash
Returns 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
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
224 225 226 227 228 229 |
# File 'lib/pulse_toolbox/sensor/manager.rb', line 224 def add_sensor(group, name, ) name = name.to_sym g = add_group(group) sensors_config[g][:sensors][name] = return name_in_group(group, name) end |
.create_sensors ⇒ Object
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
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
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
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 |