oceanbase / obdiag

obdiag (OceanBase Diagnostic Tool) is designed to help OceanBase users quickly gather necessary information and analyze the root cause of the problem.
https://www.oceanbase.com/docs/obdiag-cn
Mulan Permissive Software License, Version 2
138 stars 32 forks source link

[Enhancement]: 提供trace_id参数时精确锁定节点去获取日志 #279

Closed Teingi closed 1 month ago

Teingi commented 4 months ago

Description

  1. obdiag gather scene run --scene=observer.perf_sql --env "{db_connect='-h127.0.0.1 -P2881 -utest@test -p** -Dtest', trace_id='Yxx'}"
  2. obdiag gather scene run --scene=observer.sql_err --env "{db_connect='-h127.0.0.1 -P2881 -utest@test -p** -Dtest', trace_id='Yxx'}"

这两个场景的信息收集的时候都提供了trace_id,通过trace_id就可以反向锁定节点了,精确节点收集,没必要全部节点都搜索一遍。

Teingi commented 4 months ago
def get_observer_ip_from_trace_id(content):
    if content[0] == 'Y' and len(content) >= 12:
        sep = content.find('-')
        uval = int(content[1:sep], 16)
        ip = uval & 0xFFFFFFFF
        port = (uval >> 32) & 0xFFFF
        return "%d.%d.%d.%d:%d" % ((ip >> 24 & 0xFF), (ip >> 16 & 0xFF), (ip >> 8 & 0xFF), (ip >> 0 & 0xFF), port)
    else:
        return ""

# 示例trace_id,你需要替换为实际的trace_id
trace_id = "YB42AC1E81CB-00060AF2025B8782"

# 调用函数并打印结果
result = get_observer_ip_from_trace_id(trace_id)
if result:
    print(f"Parsed IP and Port: {result}")
else:
    print("Invalid trace_id format")