Class: Appsignal::Minutely

Inherits:
Object show all
Defined in:
lib/appsignal/minutely.rb

Defined Under Namespace

Classes: ProbeCollection

Class Method Summary collapse

Class Method Details

.probesProbeCollection

Returns list of probes.

Returns:

See Also:



118
119
120
# File 'lib/appsignal/minutely.rb', line 118

def probes
  @probes ||= ProbeCollection.new
end

.startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/appsignal/minutely.rb', line 123

def start
  stop
  @thread = Thread.new do
    # Advise multi-threaded app servers to ignore this thread
    # for the purposes of fork safety warnings
    if Thread.current.respond_to?(:thread_variable_set)
      Thread.current.thread_variable_set(:fork_safe, true)
    end

    sleep initial_wait_time
    initialize_probes
    loop do
      logger = Appsignal.logger
      logger.debug("Gathering minutely metrics with #{probe_instances.count} probes")
      probe_instances.each do |name, probe|
        begin
          logger.debug("Gathering minutely metrics with '#{name}' probe")
          probe.call
        rescue => ex
          logger.error "Error in minutely probe '#{name}': #{ex}"
          logger.debug ex.backtrace.join("\n")
        end
      end
      sleep wait_time
    end
  end
end

.stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



152
153
154
155
# File 'lib/appsignal/minutely.rb', line 152

def stop
  defined?(@thread) && @thread.kill
  probe_instances.clear
end

.wait_timeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/appsignal/minutely.rb', line 158

def wait_time
  60 - Time.now.sec
end