11#!/usr/bin/env python3
22# -*- coding: utf_8 -*-l
33import os
4+ import re
45import sys
56import psutil
67import time
@@ -419,6 +420,55 @@ def GetValidatorProcessInfo():
419420# end define
420421
421422
423+ def parse_db_stats (path : str ):
424+ with open (path ) as f :
425+ lines = f .readlines ()
426+ result = {}
427+ for line in lines :
428+ s = line .strip ().split (maxsplit = 1 )
429+ result [s [0 ]] = {}
430+ items = re .findall (r"(\S+)\s:\s(\S+)" , s [1 ])
431+ for k , v in items :
432+ result [s [0 ]][k ] = v
433+ return result
434+
435+
436+ def get_db_stats ():
437+ result = {
438+ 'rocksdb' : {
439+ 'ok' : True ,
440+ 'message' : '' ,
441+ 'data' : {}
442+ },
443+ 'celldb' : {
444+ 'ok' : True ,
445+ 'message' : '' ,
446+ 'data' : {}
447+ },
448+ }
449+ rocksdb_stats_path = '/var/ton-work/db/db_stats.txt'
450+ celldb_stats_path = '/var/ton-work/db/celldb/db_stats.txt'
451+ if os .path .exists (rocksdb_stats_path ):
452+ try :
453+ result ['rocksdb' ]['data' ] = parse_db_stats (rocksdb_stats_path )
454+ except Exception as e :
455+ result ['rocksdb' ]['ok' ] = False
456+ result ['rocksdb' ]['message' ] = f'failed to fetch db stats: { e } '
457+ else :
458+ result ['rocksdb' ]['ok' ] = False
459+ result ['rocksdb' ]['message' ] = 'db stats file is not exists'
460+ if os .path .exists (celldb_stats_path ):
461+ try :
462+ result ['celldb' ]['data' ] = parse_db_stats (celldb_stats_path )
463+ except Exception as e :
464+ result ['celldb' ]['ok' ] = False
465+ result ['celldb' ]['message' ] = f'failed to fetch db stats: { e } '
466+ else :
467+ result ['celldb' ]['ok' ] = False
468+ result ['celldb' ]['message' ] = 'db stats file is not exists'
469+ return result
470+
471+
422472def Telemetry (local , ton ):
423473 sendTelemetry = local .db .get ("sendTelemetry" )
424474 if sendTelemetry is not True :
@@ -442,6 +492,7 @@ def Telemetry(local, ton):
442492 data ["swap" ] = GetSwapInfo ()
443493 data ["uname" ] = GetUname ()
444494 data ["vprocess" ] = GetValidatorProcessInfo ()
495+ data ["db" ] = get_db_stats ()
445496 elections = local .try_function (ton .GetElectionEntries )
446497 complaints = local .try_function (ton .GetComplaints )
447498
0 commit comments