Class: LanGrove::Metrix::Base
Instance Attribute Summary collapse
-
#capsule ⇒ Object
readonly
Maintains a capsule ‘image’ of runtime state.
-
#key ⇒ Object
Persists the capsule.
-
#persistor ⇒ Object
readonly
Returns the value of attribute persistor.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(root) ⇒ Base
constructor
A new instance of Base.
- #register_sampler(spec) ⇒ Object
- #sample ⇒ Object
- #sample_adaptors ⇒ Object
- #sample_handlers ⇒ Object
- #start(daemon) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(root) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/langrove/root/metrix.rb', line 20 def initialize( root ) super( root ) @config = root.config.get_daemon_config( DAEMON_NAME, :metrix ) I.show @config @capsule = { :id => "#{DAEMON_NAME}@#{Socket.gethostname}" } @persistor = nil # # register_sampler() informs this with sampler objects # to process the daemon components # @samplers = {} @interval = @config[:interval].nil? ? 60 * 5 : @config[:interval] if @config[:persistor].nil? # # Defaults to persist runtime state 'image' # to a yaml file at: # # daemon_root//log/daemon_name@hostname # @persistor = LanGrove::ClassLoader.create( { :module => 'Plugin', :class => 'YamlFile' } ).new( root, { :basedir => DAEMON_ROOT, :database => '', :table => 'log', :key => { :filename => :id } }, nil ) else # # But can use any configured persistor plugin # @persistor = root.config.get_plugin( @config[:persistor] ) end raise config_exception( "#{self.class} requires :persistor: to specify a configured persistor plugin." ) unless @persistor.is_a?( LanGrove::Plugin::Persistor ) end |
Instance Attribute Details
#capsule ⇒ Object (readonly)
Maintains a capsule ‘image’ of runtime state
12 13 14 |
# File 'lib/langrove/root/metrix.rb', line 12 def capsule @capsule end |
#key ⇒ Object
Persists the capsule
17 18 19 |
# File 'lib/langrove/root/metrix.rb', line 17 def key @key end |
#persistor ⇒ Object (readonly)
Returns the value of attribute persistor.
18 19 20 |
# File 'lib/langrove/root/metrix.rb', line 18 def persistor @persistor end |
Instance Method Details
#register_sampler(spec) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/langrove/root/metrix.rb', line 87 def register_sampler( spec ) type = :handler filter = '*' accumulator = nil sampler = nil spec.each do |key, value| case key when :type type = value when :sampler sampler = value when :filter filter = value when :accumulator # # Allows for an alternative accumulator callback # accumulator = value end end @samplers[type] = {} if @samplers[type].nil? @samplers[type][filter] = [] if @samplers[type][filter].nil? @samplers[type][filter] << [accumulator, sampler] end |
#sample ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/langrove/root/metrix.rb', line 149 def sample sample_handlers sample_adaptors I.show @capsule @persistor.store( self ) end |
#sample_adaptors ⇒ Object
190 191 192 193 194 195 196 197 198 |
# File 'lib/langrove/root/metrix.rb', line 190 def sample_adaptors @samplers[:adaptor]['*'].each do |sampler| sampler[1].sample_accumulate( :adaptor, @daemon.adaptor, @capsule ) end unless @samplers[:adaptor].nil? end |
#sample_handlers ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/langrove/root/metrix.rb', line 161 def sample_handlers @samplers[:handler]['*'].each do |sampler| # # sampler[0] contains the alternative accumulator callback proc # sampler[1] contains the sampler object # @daemon.server.each_handler do |handler| if sampler[0].nil? sampler[1].sample_accumulate( :handler, handler, @capsule ) else sampler[0].yield( :handler, handler, @capsule ) end end sampler[1].sample_collate( :handler, @capsule ) end unless @samplers[:handler].nil? end |
#start(daemon) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/langrove/root/metrix.rb', line 127 def start( daemon ) @logger.debug "#{self.class}.start( #{daemon} )" # # Start the sample event loop # @daemon = daemon if defined?( EM ) and EM::reactor_running? EM::add_periodic_timer(@interval) do sample end end end |