Class: NewRelic::Agent::HealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/health_check.rb

Constant Summary collapse

HEALTHY =
{healthy: true, last_error: 'NR-APM-000', message: 'Healthy'}.freeze
INVALID_LICENSE_KEY =
{healthy: false, last_error: 'NR-APM-001', message: 'Invalid license key (HTTP status code 401)'}.freeze
MISSING_LICENSE_KEY =
{healthy: false, last_error: 'NR-APM-002', message: 'License key missing in configuration'}.freeze
FORCED_DISCONNECT =
{healthy: false, last_error: 'NR-APM-003', message: 'Forced disconnect received from New Relic (HTTP status code 410)'}.freeze
HTTP_ERROR =
{healthy: false, last_error: 'NR-APM-004', message: 'HTTP error response code [%s] recevied from New Relic while sending data type [%s]'}.freeze
MISSING_APP_NAME =
{healthy: false, last_error: 'NR-APM-005', message: 'Missing application name in agent configuration'}.freeze
APP_NAME_EXCEEDED =
{healthy: false, last_error: 'NR-APM-006', message: 'The maximum number of configured app names (3) exceeded'}.freeze
PROXY_CONFIG_ERROR =
{healthy: false, last_error: 'NR-APM-007', message: 'HTTP Proxy configuration error; response code [%s]'}.freeze
AGENT_DISABLED =
{healthy: false, last_error: 'NR-APM-008', message: 'Agent is disabled via configuration'}.freeze
FAILED_TO_CONNECT =
{healthy: false, last_error: 'NR-APM-009', message: 'Failed to connect to New Relic data collector'}.freeze
FAILED_TO_PARSE_CONFIG =
{healthy: false, last_error: 'NR-APM-010', message: 'Agent config file is not able to be parsed'}.freeze
SHUTDOWN =
{healthy: true, last_error: 'NR-APM-099', message: 'Agent has shutdown'}.freeze

Instance Method Summary collapse

Constructor Details

#initializeHealthCheck

Returns a new instance of HealthCheck.


8
9
10
11
12
13
14
15
16
# File 'lib/new_relic/agent/health_check.rb', line 8

def initialize
  @start_time = nano_time
  @continue = true
  @status = HEALTHY
  # the following assignments may set @continue = false if they are invalid
  set_enabled
  set_delivery_location
  set_frequency
end

Instance Method Details

#create_and_run_health_check_loopObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/new_relic/agent/health_check.rb', line 31

def create_and_run_health_check_loop
  return unless health_checks_enabled? && @continue

  NewRelic::Agent.logger.debug('Agent Control health check conditions met. Starting health checks.')
  NewRelic::Agent.record_metric('Supportability/AgentControl/Health/enabled', 1)

  Thread.new do
    while @continue
      begin
        sleep @frequency
        write_file
        @continue = false if @status == SHUTDOWN
      rescue StandardError => e
        NewRelic::Agent.logger.error("Aborting Agent Control health check. Error raised: #{e}")
        @continue = false
      end
    end
  end
end

#healthy?Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/new_relic/agent/health_check.rb', line 58

def healthy?
  @status == HEALTHY
end

#update_status(status, options = []) ⇒ Object


51
52
53
54
55
56
# File 'lib/new_relic/agent/health_check.rb', line 51

def update_status(status, options = [])
  return unless @continue

  @status = status.dup
  update_message(options) unless options.empty?
end