Class: Atatus::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/collector/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Builder

Returns a new instance of Builder.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/atatus/collector/builder.rb', line 7

def initialize(config)
  @config = config
  @metadata = Metadata::SystemInfo.new(config)
  @container_id = nil
  if
    !@metadata.container.nil? &&
    @metadata.container.key?(:id)
  then
    @container_id = @metadata.container[:id]
  end

  @real_hostname = Socket.gethostname
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



21
22
23
# File 'lib/atatus/collector/builder.rb', line 21

def config
  @config
end

Instance Method Details

#analytics(start_time, end_time, analytics_data) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/atatus/collector/builder.rb', line 95

def analytics(start_time, end_time, analytics_data)
  payload = common()
  payload[:startTime] = start_time
  payload[:endTime] = end_time
  payload[:requests] = analytics_data
  payload
end

#commonObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/atatus/collector/builder.rb', line 23

def common()
  common = {
    appName: @config.app_name,
    licenseKey: @config.license_key,
    agent: {
      name: AGENT_NAME,
      version: VERSION
    },
    hostname: @metadata.hostname,
    hostId: @metadata.hwinfo.hostid,
    releaseStage: @config.environment
  }
  if !@container_id.nil?
    common[:containerId] = @container_id
  end
  common
end

#error_metrics(start_time, end_time, metrics_data, requests_data) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/atatus/collector/builder.rb', line 72

def error_metrics(start_time, end_time, metrics_data, requests_data)
  payload = common()
  payload[:startTime] = start_time
  payload[:endTime] = end_time
  payload[:errorMetrics] = build_error_metrics_obj(metrics_data)
  payload[:errorRequests] = build_error_requests_obj(requests_data)
  payload
end

#errors(start_time, end_time, error_data) ⇒ Object



81
82
83
84
85
# File 'lib/atatus/collector/builder.rb', line 81

def errors(start_time, end_time, error_data)
  payload = common()
  payload[:errors] = build_errors_obj(error_data)
  payload
end

#hostinfo(start_time) ⇒ Object



41
42
43
44
45
46
# File 'lib/atatus/collector/builder.rb', line 41

def hostinfo(start_time)
  payload = common()
  payload[:timestamp] = start_time
  payload[:environment] = build_hostinfo_obj()
  payload
end

#metrics(start_time, end_time, metric_data) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/atatus/collector/builder.rb', line 87

def metrics(start_time, end_time, metric_data)
  payload = common()
  payload[:startTime] = start_time
  payload[:endTime] = end_time
  payload[:ruby] = metric_data
  payload
end

#traces(start_time, end_time, data) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/atatus/collector/builder.rb', line 64

def traces(start_time, end_time, data)
  payload = common()
  payload[:startTime] = start_time
  payload[:endTime] = end_time
  payload[:traces] = build_traces_obj(data)
  payload
end

#txn_hist(start_time, end_time, data) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/atatus/collector/builder.rb', line 56

def txn_hist(start_time, end_time, data)
  payload = common()
  payload[:startTime] = start_time
  payload[:endTime] = end_time
  payload[:transactions] = build_txn_hist_obj(data)
  payload
end

#txns(start_time, end_time, data) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/atatus/collector/builder.rb', line 48

def txns(start_time, end_time, data)
  payload = common()
  payload[:startTime] = start_time
  payload[:endTime] = end_time
  payload[:transactions] = build_txns_obj(data)
  payload
end