5
5
import psutil
6
6
import time
7
7
import json
8
+ import base64
8
9
import requests
9
10
import subprocess
10
11
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
13
15
from mypylib .mypylib import (
14
16
b2mb ,
15
17
get_timestamp ,
20
22
thr_sleep ,
21
23
Dict
22
24
)
25
+ from mytoninstaller .node_args import get_node_args
23
26
24
27
25
28
def Init (local ):
26
29
# Event reaction
27
30
if ("-e" in sys .argv ):
28
31
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 )
31
34
# end if
32
35
33
36
local .run ()
@@ -46,11 +49,13 @@ def Init(local):
46
49
# end define
47
50
48
51
49
- def Event (local , eventName ):
50
- if eventName == "enableVC" :
52
+ def Event (local , event_name ):
53
+ if event_name == "enableVC" :
51
54
EnableVcEvent (local )
52
- elif eventName == "validator down" :
55
+ elif event_name == "validator down" :
53
56
ValidatorDownEvent (local )
57
+ elif event_name == "enable_ton_storage_provider" :
58
+ enable_ton_storage_provider_event (local )
54
59
local .exit ()
55
60
# end define
56
61
@@ -78,6 +83,15 @@ def ValidatorDownEvent(local):
78
83
# end define
79
84
80
85
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
+
81
95
def Elections (local , ton ):
82
96
use_pool = ton .using_pool ()
83
97
use_liquid_staking = ton .using_liquid_staking ()
@@ -419,6 +433,90 @@ def GetValidatorProcessInfo():
419
433
# end define
420
434
421
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
+ # 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
+
422
520
def Telemetry (local , ton ):
423
521
sendTelemetry = local .db .get ("sendTelemetry" )
424
522
if sendTelemetry is not True :
@@ -442,6 +540,11 @@ def Telemetry(local, ton):
442
540
data ["swap" ] = GetSwapInfo ()
443
541
data ["uname" ] = GetUname ()
444
542
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 ()
445
548
elections = local .try_function (ton .GetElectionEntries )
446
549
complaints = local .try_function (ton .GetComplaints )
447
550
0 commit comments