From ad3abf2f8c4dd1973868dff3742efb93549093f2 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 28 Mar 2024 16:08:36 +0800 Subject: [PATCH 1/2] add cpu info to telemetry --- mytoncore/functions.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mytoncore/functions.py b/mytoncore/functions.py index ffb9a3ef..f300099c 100755 --- a/mytoncore/functions.py +++ b/mytoncore/functions.py @@ -20,6 +20,7 @@ thr_sleep, Dict ) +from mytoninstaller.node_args import get_node_args def Init(local): @@ -460,6 +461,26 @@ def get_db_stats(): # end define +def get_cpu_name(): + with open('/proc/cpuinfo') as f: + for line in f: + if line.strip(): + if line.rstrip('\n').startswith('model name'): + return line.rstrip('\n').split(':')[1].strip() + return None + + +def is_host_virtual(): + try: + with open('/sys/class/dmi/id/product_name') as f: + product_name = f.read().strip().lower() + if 'virtual' in product_name or 'kvm' in product_name or 'qemu' in product_name or 'vmware' in product_name: + return {'virtual': True, 'product_name': product_name} + return {'virtual': False, 'product_name': product_name} + except FileNotFoundError: + return {'virtual': None, 'product_name': None} + + def Telemetry(local, ton): sendTelemetry = local.db.get("sendTelemetry") if sendTelemetry is not True: @@ -484,6 +505,8 @@ def Telemetry(local, ton): data["uname"] = GetUname() data["vprocess"] = GetValidatorProcessInfo() data["dbStats"] = get_db_stats() + data["nodeArgs"] = get_node_args() + data["cpuInfo"] = {'cpuName': get_cpu_name(), 'virtual': is_host_virtual()} elections = local.try_function(ton.GetElectionEntries) complaints = local.try_function(ton.GetComplaints) From 2a8b926c0dec567abe4fcfd61c0452d6556eea3e Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 28 Mar 2024 23:23:07 +0800 Subject: [PATCH 2/2] telemetry improves --- mytoncore/functions.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mytoncore/functions.py b/mytoncore/functions.py index f300099c..134d94d2 100755 --- a/mytoncore/functions.py +++ b/mytoncore/functions.py @@ -481,6 +481,29 @@ def is_host_virtual(): return {'virtual': None, 'product_name': None} +def do_beacon_ping(host, count, timeout): + args = ['ping', '-c', str(count), '-W', str(timeout), host] + process = subprocess.run(args, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout) + output = process.stdout.decode("utf-8") + avg = output.split('\n')[-1].split('=')[1].split('/')[1] + return float(avg) + + +def get_pings_values(): + return { + 'beacon-eu-01.toncenter.com': do_beacon_ping('beacon-eu-01.toncenter.com', 1, 3), + 'beacon-apac-01.toncenter.com': do_beacon_ping('beacon-apac-01.toncenter.com', 1, 3) + } + + +def get_validator_disk_name(): + process = subprocess.run("df -h /var/ton-work/ | sed -n '2 p' | awk '{print $1}'", stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3, shell=True) + output = process.stdout.decode("utf-8") + return output.strip() + + def Telemetry(local, ton): sendTelemetry = local.db.get("sendTelemetry") if sendTelemetry is not True: @@ -507,6 +530,8 @@ def Telemetry(local, ton): data["dbStats"] = get_db_stats() data["nodeArgs"] = get_node_args() data["cpuInfo"] = {'cpuName': get_cpu_name(), 'virtual': is_host_virtual()} + data["validatorDiskName"] = get_validator_disk_name() + data["pings"] = get_pings_values() elections = local.try_function(ton.GetElectionEntries) complaints = local.try_function(ton.GetComplaints)