Class: Datadog::Core::Cloudwise::ProbeState

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/cloudwise/probe_state.rb

Overview

Manages the probe state (active/suspended) 探针状态管理:追踪所有可能导致数据不采集的条件

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ ProbeState

Returns a new instance of ProbeState.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 9

def initialize(logger:)
  @logger = logger
  @mutex = Mutex.new

  # 初始状态:所有条件都未满足,探针不活跃
  @host_id_ready = false        # Host ID 是否已生成
  @heartbeat_active = false     # 心跳是否正常
  @license_valid = false        # License 是否校验通过(仅传统模式使用,DOCC 模式忽略)
  @app_registered = false       # 应用是否已注册(注册失败不影响采集)

  # 融合模式状态
  @docc_registered = false      # 注册是否成功
  @docc_heartbeat_active = false  #  心跳是否正常
  @docc_operation_active = true   #  操作状态(默认为 true,agent_stop 时为 false)
  @use_docc_mode = false        # 是否使用 模式
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 216

def active?
  can_collect_data?
end

#app_registered?Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 191

def app_registered?
  @mutex.synchronize { @app_registered }
end

#can_collect_data?Boolean

探针是否可以采集数据 如果使用 DOCC 模式:需要 DOCC 心跳 + Operation 都正常(不需要 License) 如果使用传统模式:需要 Host ID + 心跳 + License 都正常

Returns:

  • (Boolean)


168
169
170
171
172
173
174
175
176
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 168

def can_collect_data?
  @mutex.synchronize do
    if @use_docc_mode
      @docc_heartbeat_active && @docc_operation_active
    else
      @host_id_ready && @heartbeat_active && @license_valid
    end
  end
end

#docc_heartbeat_active?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 199

def docc_heartbeat_active?
  @mutex.synchronize { @docc_heartbeat_active }
end

#docc_operation_active?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 203

def docc_operation_active?
  @mutex.synchronize { @docc_operation_active }
end

#docc_registered?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 195

def docc_registered?
  @mutex.synchronize { @docc_registered }
end

#enable_docc_mode!Object

设置使用 DOCC 模式



158
159
160
161
162
163
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 158

def enable_docc_mode!
  @mutex.synchronize do
    @use_docc_mode = true
    Cloudwise.log_debug { 'Cloudwise: Using DOCC integrated mode' }
  end
end

#heartbeat_active?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 183

def heartbeat_active?
  @mutex.synchronize { @heartbeat_active }
end

#host_id_ready?Boolean

检查各个状态的独立方法

Returns:

  • (Boolean)


179
180
181
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 179

def host_id_ready?
  @mutex.synchronize { @host_id_ready }
end

#license_valid?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 187

def license_valid?
  @mutex.synchronize { @license_valid }
end

#mark_app_registered!Object

应用注册相关(不影响采集)



84
85
86
87
88
89
90
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 84

def mark_app_registered!
  @mutex.synchronize do
    return if @app_registered
    @app_registered = true
    Cloudwise.log_debug { 'Cloudwise: Application registered' }
  end
end

#mark_app_unregistered!Object



92
93
94
95
96
97
98
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 92

def mark_app_unregistered!
  @mutex.synchronize do
    return unless @app_registered
    @app_registered = false
    Cloudwise.log_warn { 'Cloudwise: Application not registered' }
  end
end

#mark_docc_heartbeat_active!Object

DOCC 心跳相关



120
121
122
123
124
125
126
127
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 120

def mark_docc_heartbeat_active!
  @mutex.synchronize do
    return if @docc_heartbeat_active
    @docc_heartbeat_active = true
    Cloudwise.log_debug { 'Cloudwise DOCC: Heartbeat active' }
    log_status_change
  end
end

#mark_docc_heartbeat_inactive!Object



129
130
131
132
133
134
135
136
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 129

def mark_docc_heartbeat_inactive!
  @mutex.synchronize do
    return unless @docc_heartbeat_active
    @docc_heartbeat_active = false
    Cloudwise.log_warn { 'Cloudwise DOCC: Heartbeat inactive' }
    log_status_change
  end
end

#mark_docc_operation_active!Object

DOCC 操作相关



139
140
141
142
143
144
145
146
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 139

def mark_docc_operation_active!
  @mutex.synchronize do
    return if @docc_operation_active
    @docc_operation_active = true
    Cloudwise.log_info { 'Cloudwise DOCC: Agent started - data collection enabled' }
    log_status_change
  end
end

#mark_docc_operation_inactive!Object



148
149
150
151
152
153
154
155
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 148

def mark_docc_operation_inactive!
  @mutex.synchronize do
    return unless @docc_operation_active
    @docc_operation_active = false
    Cloudwise.log_info { 'Cloudwise DOCC: Agent stopped - data collection disabled' }
    log_status_change
  end
end

#mark_docc_registered!Object

DOCC 注册相关



101
102
103
104
105
106
107
108
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 101

def mark_docc_registered!
  @mutex.synchronize do
    return if @docc_registered
    @docc_registered = true
    Cloudwise.log_debug { 'Cloudwise DOCC: Extension registered' }
    log_status_change
  end
end

#mark_docc_unregistered!Object



110
111
112
113
114
115
116
117
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 110

def mark_docc_unregistered!
  @mutex.synchronize do
    return unless @docc_registered
    @docc_registered = false
    Cloudwise.log_warn { 'Cloudwise DOCC: Extension not registered' }
    log_status_change
  end
end

#mark_heartbeat_active!Object

心跳相关



46
47
48
49
50
51
52
53
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 46

def mark_heartbeat_active!
  @mutex.synchronize do
    return if @heartbeat_active
    @heartbeat_active = true
    Cloudwise.log_debug { 'Cloudwise: Heartbeat active' }
    log_status_change
  end
end

#mark_heartbeat_inactive!Object



55
56
57
58
59
60
61
62
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 55

def mark_heartbeat_inactive!
  @mutex.synchronize do
    return unless @heartbeat_active
    @heartbeat_active = false
    Cloudwise.log_warn { 'Cloudwise: Heartbeat inactive' }
    log_status_change
  end
end

#mark_host_id_failed!Object



36
37
38
39
40
41
42
43
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 36

def mark_host_id_failed!
  @mutex.synchronize do
    return unless @host_id_ready
    @host_id_ready = false
    Cloudwise.log_warn { 'Cloudwise: Host ID not ready' }
    log_status_change
  end
end

#mark_host_id_ready!Object

Host ID 相关



27
28
29
30
31
32
33
34
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 27

def mark_host_id_ready!
  @mutex.synchronize do
    return if @host_id_ready
    @host_id_ready = true
    Cloudwise.log_debug { 'Cloudwise: Host ID ready' }
    log_status_change
  end
end

#mark_license_invalid!Object



74
75
76
77
78
79
80
81
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 74

def mark_license_invalid!
  @mutex.synchronize do
    return unless @license_valid
    @license_valid = false
    Cloudwise.log_warn { 'Cloudwise: License invalid' }
    log_status_change
  end
end

#mark_license_valid!Object

License 相关(仅传统模式使用,DOCC 模式下不需要 License 校验)



65
66
67
68
69
70
71
72
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 65

def mark_license_valid!
  @mutex.synchronize do
    return if @license_valid
    @license_valid = true
    Cloudwise.log_debug { 'Cloudwise: License valid' }
    log_status_change
  end
end

#statusObject

获取当前状态摘要



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 221

def status
  @mutex.synchronize do
    base_status = {
      host_id_ready: @host_id_ready,
      heartbeat_active: @heartbeat_active,
      license_valid: @license_valid,
      app_registered: @app_registered
    }

    if @use_docc_mode
      base_status.merge(
        use_docc_mode: true,
        docc_registered: @docc_registered,
        docc_heartbeat_active: @docc_heartbeat_active,
        docc_operation_active: @docc_operation_active,
        can_collect_data: @docc_heartbeat_active && @docc_operation_active
      )
    else
      base_status.merge(
        use_docc_mode: false,
        can_collect_data: @host_id_ready && @heartbeat_active && @license_valid
      )
    end
  end
end

#suspended?Boolean

兼容旧接口

Returns:

  • (Boolean)


212
213
214
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 212

def suspended?
  !can_collect_data?
end

#using_docc_mode?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/datadog/core/cloudwise/probe_state.rb', line 207

def using_docc_mode?
  @mutex.synchronize { @use_docc_mode }
end