Skip to content

Commit 52052ee

Browse files
committed
add rocksdb telemetry
1 parent 92154f8 commit 52052ee

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

mytoncore.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,6 +4064,67 @@ def GetSwapInfo():
40644064
return result
40654065
#end define
40664066

4067+
4068+
def parse_db_stats(path: str):
4069+
with open(path) as f:
4070+
lines = f.readlines()
4071+
result = {}
4072+
for line in lines:
4073+
s = line.strip().split(maxsplit=1)
4074+
items = re.findall(r"(\S+)\s:\s(\S+)", s[1])
4075+
if len(items) == 1:
4076+
item = items[0]
4077+
if float(item[1]) > 0:
4078+
result[s[0]] = float(item[1])
4079+
else:
4080+
if any(float(v) > 0 for k, v in items):
4081+
result[s[0]] = {}
4082+
result[s[0]] = {k: float(v) for k, v in items}
4083+
return result
4084+
# end define
4085+
4086+
4087+
def get_db_stats():
4088+
result = {
4089+
'rocksdb': {
4090+
'ok': True,
4091+
'message': '',
4092+
'data': {}
4093+
},
4094+
'celldb': {
4095+
'ok': True,
4096+
'message': '',
4097+
'data': {}
4098+
},
4099+
}
4100+
rocksdb_stats_path = '/var/ton-work/db/db_stats.txt'
4101+
celldb_stats_path = '/var/ton-work/db/celldb/db_stats.txt'
4102+
if os.path.exists(rocksdb_stats_path):
4103+
try:
4104+
result['rocksdb']['data'] = parse_db_stats(rocksdb_stats_path)
4105+
except Exception as e:
4106+
result['rocksdb']['ok'] = False
4107+
result['rocksdb']['message'] = f'failed to fetch db stats: {e}'
4108+
else:
4109+
result['rocksdb']['ok'] = False
4110+
result['rocksdb']['message'] = 'db stats file is not exists'
4111+
# end if
4112+
4113+
if os.path.exists(celldb_stats_path):
4114+
try:
4115+
result['celldb']['data'] = parse_db_stats(celldb_stats_path)
4116+
except Exception as e:
4117+
result['celldb']['ok'] = False
4118+
result['celldb']['message'] = f'failed to fetch db stats: {e}'
4119+
else:
4120+
result['celldb']['ok'] = False
4121+
result['celldb']['message'] = 'db stats file is not exists'
4122+
# end if
4123+
4124+
return result
4125+
# end define
4126+
4127+
40674128
def GetValidatorProcessInfo():
40684129
pid = get_service_pid("validator")
40694130
if pid == None or pid == 0:
@@ -4108,6 +4169,7 @@ def Telemetry(ton):
41084169
data["swap"] = GetSwapInfo()
41094170
data["uname"] = GetUname()
41104171
data["vprocess"] = GetValidatorProcessInfo()
4172+
data["dbStats"] = get_db_stats()
41114173
elections = local.try_function(ton.GetElectionEntries)
41124174
complaints = local.try_function(ton.GetComplaints)
41134175

0 commit comments

Comments
 (0)