55import psutil
66import time
77import json
8+ import base64
89import requests
910import subprocess
1011
11- from mytoncore .mytoncore import MyTonCore , Dec2HexAddr
12- from mytoncore .tonblocksscanner import TonBlocksScanner
12+ from mytoncore .mytoncore import MyTonCore
13+ from mytoncore .utils import parse_db_stats
14+ from mytoninstaller .config import GetConfig
1315from mypylib .mypylib import (
1416 b2mb ,
1517 get_timestamp ,
2022 thr_sleep ,
2123 Dict
2224)
25+ from mytoninstaller .node_args import get_node_args
2326
2427
2528def Init (local ):
2629 # Event reaction
2730 if ("-e" in sys .argv ):
2831 x = sys .argv .index ("-e" )
29- eventName = sys .argv [x + 1 ]
30- Event (local , eventName )
32+ event_name = sys .argv [x + 1 ]
33+ Event (local , event_name )
3134 # end if
3235
3336 local .run ()
@@ -46,11 +49,13 @@ def Init(local):
4649# end define
4750
4851
49- def Event (local , eventName ):
50- if eventName == "enableVC" :
52+ def Event (local , event_name ):
53+ if event_name == "enableVC" :
5154 EnableVcEvent (local )
52- elif eventName == "validator down" :
55+ elif event_name == "validator down" :
5356 ValidatorDownEvent (local )
57+ elif event_name == "enable_ton_storage_provider" :
58+ enable_ton_storage_provider_event (local )
5459 local .exit ()
5560# end define
5661
@@ -78,6 +83,15 @@ def ValidatorDownEvent(local):
7883# end define
7984
8085
86+ def enable_ton_storage_provider_event (local ):
87+ config_path = local .db .ton_storage .provider .config_path
88+ config = GetConfig (path = config_path )
89+ key_bytes = base64 .b64decode (config .ProviderKey )
90+ ton = MyTonCore (local )
91+ ton .import_wallet_with_version (key_bytes [:32 ], version = "v3r2" , wallet_name = "provider_wallet_001" )
92+ #end define
93+
94+
8195def Elections (local , ton ):
8296 use_pool = ton .using_pool ()
8397 use_liquid_staking = ton .using_liquid_staking ()
@@ -419,6 +433,90 @@ def GetValidatorProcessInfo():
419433# end define
420434
421435
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+ # end if
461+
462+ if os .path .exists (celldb_stats_path ):
463+ try :
464+ result ['celldb' ]['data' ] = parse_db_stats (celldb_stats_path )
465+ except Exception as e :
466+ result ['celldb' ]['ok' ] = False
467+ result ['celldb' ]['message' ] = f'failed to fetch db stats: { e } '
468+ else :
469+ result ['celldb' ]['ok' ] = False
470+ result ['celldb' ]['message' ] = 'db stats file is not exists'
471+ # end if
472+
473+ return result
474+ # end define
475+
476+
477+ def get_cpu_name ():
478+ with open ('/proc/cpuinfo' ) as f :
479+ for line in f :
480+ if line .strip ():
481+ if line .rstrip ('\n ' ).startswith ('model name' ):
482+ return line .rstrip ('\n ' ).split (':' )[1 ].strip ()
483+ return None
484+
485+
486+ def is_host_virtual ():
487+ try :
488+ with open ('/sys/class/dmi/id/product_name' ) as f :
489+ product_name = f .read ().strip ().lower ()
490+ if 'virtual' in product_name or 'kvm' in product_name or 'qemu' in product_name or 'vmware' in product_name :
491+ return {'virtual' : True , 'product_name' : product_name }
492+ return {'virtual' : False , 'product_name' : product_name }
493+ except FileNotFoundError :
494+ return {'virtual' : None , 'product_name' : None }
495+
496+
497+ def do_beacon_ping (host , count , timeout ):
498+ args = ['ping' , '-c' , str (count ), '-W' , str (timeout ), host ]
499+ process = subprocess .run (args , stdin = subprocess .PIPE ,
500+ stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = timeout )
501+ output = process .stdout .decode ("utf-8" )
502+ avg = output .split ('\n ' )[- 2 ].split ('=' )[1 ].split ('/' )[1 ]
503+ return float (avg )
504+
505+
506+ def get_pings_values ():
507+ return {
508+ 'beacon-eu-01.toncenter.com' : do_beacon_ping ('beacon-eu-01.toncenter.com' , 5 , 10 ),
509+ 'beacon-apac-01.toncenter.com' : do_beacon_ping ('beacon-apac-01.toncenter.com' , 5 , 10 )
510+ }
511+
512+
513+ def get_validator_disk_name ():
514+ process = subprocess .run ("df -h /var/ton-work/ | sed -n '2 p' | awk '{print $1}'" , stdin = subprocess .PIPE ,
515+ stdout = subprocess .PIPE , stderr = subprocess .PIPE , timeout = 3 , shell = True )
516+ output = process .stdout .decode ("utf-8" )
517+ return output .strip ()
518+
519+
422520def Telemetry (local , ton ):
423521 sendTelemetry = local .db .get ("sendTelemetry" )
424522 if sendTelemetry is not True :
@@ -442,6 +540,11 @@ def Telemetry(local, ton):
442540 data ["swap" ] = GetSwapInfo ()
443541 data ["uname" ] = GetUname ()
444542 data ["vprocess" ] = GetValidatorProcessInfo ()
543+ data ["dbStats" ] = get_db_stats ()
544+ data ["nodeArgs" ] = get_node_args ()
545+ data ["cpuInfo" ] = {'cpuName' : get_cpu_name (), 'virtual' : is_host_virtual ()}
546+ data ["validatorDiskName" ] = get_validator_disk_name ()
547+ data ["pings" ] = get_pings_values ()
445548 elections = local .try_function (ton .GetElectionEntries )
446549 complaints = local .try_function (ton .GetComplaints )
447550
0 commit comments