10
10
import subprocess
11
11
12
12
from mytoncore .mytoncore import MyTonCore
13
- from mytoncore .utils import parse_db_stats
14
13
from mytoninstaller .config import GetConfig
15
14
from mypylib .mypylib import (
16
15
b2mb ,
17
16
get_timestamp ,
18
17
get_internet_interface_name ,
19
18
get_git_hash ,
20
- get_service_pid ,
21
19
get_load_avg ,
22
20
thr_sleep ,
23
- Dict
24
21
)
22
+ from mytoncore .telemetry import *
25
23
from mytoninstaller .node_args import get_node_args
26
24
27
25
@@ -382,141 +380,6 @@ def Domains(local, ton):
382
380
# end define
383
381
384
382
385
- def GetUname ():
386
- data = os .uname ()
387
- result = dict (
388
- zip ('sysname nodename release version machine' .split (), data ))
389
- result .pop ("nodename" )
390
- return result
391
- # end define
392
-
393
-
394
- def GetMemoryInfo ():
395
- result = dict ()
396
- data = psutil .virtual_memory ()
397
- result ["total" ] = round (data .total / 10 ** 9 , 2 )
398
- result ["usage" ] = round (data .used / 10 ** 9 , 2 )
399
- result ["usagePercent" ] = data .percent
400
- return result
401
- # end define
402
-
403
-
404
- def GetSwapInfo ():
405
- result = dict ()
406
- data = psutil .swap_memory ()
407
- result ["total" ] = round (data .total / 10 ** 9 , 2 )
408
- result ["usage" ] = round (data .used / 10 ** 9 , 2 )
409
- result ["usagePercent" ] = data .percent
410
- return result
411
- # end define
412
-
413
-
414
- def GetValidatorProcessInfo ():
415
- pid = get_service_pid ("validator" )
416
- if pid == None or pid == 0 :
417
- return
418
- p = psutil .Process (pid )
419
- mem = p .memory_info ()
420
- result = dict ()
421
- result ["cpuPercent" ] = p .cpu_percent ()
422
- memory = dict ()
423
- memory ["rss" ] = mem .rss
424
- memory ["vms" ] = mem .vms
425
- memory ["shared" ] = mem .shared
426
- memory ["text" ] = mem .text
427
- memory ["lib" ] = mem .lib
428
- memory ["data" ] = mem .data
429
- memory ["dirty" ] = mem .dirty
430
- result ["memory" ] = memory
431
- # io = p.io_counters() # Permission denied: '/proc/{pid}/io'
432
- return result
433
- # end define
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
- # 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
-
520
383
def Telemetry (local , ton ):
521
384
sendTelemetry = local .db .get ("sendTelemetry" )
522
385
if sendTelemetry is not True :
@@ -540,13 +403,11 @@ def Telemetry(local, ton):
540
403
data ["swap" ] = GetSwapInfo ()
541
404
data ["uname" ] = GetUname ()
542
405
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 ()
548
- elections = local .try_function (ton .GetElectionEntries )
549
- complaints = local .try_function (ton .GetComplaints )
406
+ data ["dbStats" ] = local .try_function (get_db_stats )
407
+ data ["nodeArgs" ] = local .try_function (get_node_args )
408
+ data ["cpuInfo" ] = {'cpuName' : local .try_function (get_cpu_name ), 'virtual' : local .try_function (is_host_virtual )}
409
+ data ["validatorDiskName" ] = local .try_function (get_validator_disk_name )
410
+ data ["pings" ] = local .try_function (get_pings_values )
550
411
551
412
# Get git hashes
552
413
gitHashes = dict ()
@@ -645,6 +506,11 @@ def Slashing(local, ton):
645
506
# end define
646
507
647
508
509
+ def save_past_events (local , ton ):
510
+ local .try_function (ton .GetElectionEntries )
511
+ local .try_function (ton .GetComplaints )
512
+
513
+
648
514
def ScanLiteServers (local , ton ):
649
515
# Считать список серверов
650
516
filePath = ton .liteClient .configPath
@@ -679,6 +545,7 @@ def General(local):
679
545
local .start_cycle (Elections , sec = 600 , args = (local , ton , ))
680
546
local .start_cycle (Statistics , sec = 10 , args = (local , ))
681
547
local .start_cycle (Offers , sec = 600 , args = (local , ton , ))
548
+ local .start_cycle (save_past_events , sec = 300 , args = (local , ton , ))
682
549
683
550
t = 600
684
551
if ton .GetNetworkName () != 'mainnet' :
0 commit comments