Skip to content

Commit ddbc67e

Browse files
authored
Merge pull request #223 from yungwine/mytonctrl2_dev
telemetry improves
2 parents 2443018 + 2a8b926 commit ddbc67e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

mytoncore/functions.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
thr_sleep,
2323
Dict
2424
)
25+
from mytoninstaller.node_args import get_node_args
2526

2627

2728
def Init(local):
@@ -473,6 +474,49 @@ def get_db_stats():
473474
# end define
474475

475476

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')[-1].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', 1, 3),
509+
'beacon-apac-01.toncenter.com': do_beacon_ping('beacon-apac-01.toncenter.com', 1, 3)
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+
476520
def Telemetry(local, ton):
477521
sendTelemetry = local.db.get("sendTelemetry")
478522
if sendTelemetry is not True:
@@ -497,6 +541,10 @@ def Telemetry(local, ton):
497541
data["uname"] = GetUname()
498542
data["vprocess"] = GetValidatorProcessInfo()
499543
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()
500548
elections = local.try_function(ton.GetElectionEntries)
501549
complaints = local.try_function(ton.GetComplaints)
502550

0 commit comments

Comments
 (0)