Skip to content

Commit 3c3c805

Browse files
committed
improves
1 parent 7acc59a commit 3c3c805

File tree

2 files changed

+41
-35
lines changed

2 files changed

+41
-35
lines changed

mytoncore/functions.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf_8 -*-l
33
import os
4-
import re
54
import sys
65
import psutil
76
import time
87
import json
98
import requests
109
import subprocess
1110

12-
from mytoncore.mytoncore import MyTonCore, Dec2HexAddr
13-
from mytoncore.tonblocksscanner import TonBlocksScanner
11+
from mytoncore.mytoncore import MyTonCore
12+
from mytoncore.utils import parse_db_stats
1413
from mypylib.mypylib import (
1514
b2mb,
1615
get_timestamp,
@@ -420,24 +419,6 @@ def GetValidatorProcessInfo():
420419
# end define
421420

422421

423-
def parse_db_stats(path: str):
424-
with open(path) as f:
425-
lines = f.readlines()
426-
result = {}
427-
for line in lines:
428-
s = line.strip().split(maxsplit=1)
429-
items = re.findall(r"(\S+)\s:\s(\S+)", s[1])
430-
if len(items) == 1:
431-
item = items[0]
432-
if float(item[1]) > 0:
433-
result[s[0]] = float(item[1])
434-
else:
435-
if any(float(v) > 0 for k, v in items):
436-
result[s[0]] = {}
437-
result[s[0]] = {k: float(v) for k, v in items}
438-
return result
439-
440-
441422
def get_db_stats():
442423
result = {
443424
'rocksdb': {
@@ -462,6 +443,8 @@ def get_db_stats():
462443
else:
463444
result['rocksdb']['ok'] = False
464445
result['rocksdb']['message'] = 'db stats file is not exists'
446+
# end if
447+
465448
if os.path.exists(celldb_stats_path):
466449
try:
467450
result['celldb']['data'] = parse_db_stats(celldb_stats_path)
@@ -471,7 +454,10 @@ def get_db_stats():
471454
else:
472455
result['celldb']['ok'] = False
473456
result['celldb']['message'] = 'db stats file is not exists'
457+
# end if
458+
474459
return result
460+
# end define
475461

476462

477463
def Telemetry(local, ton):
@@ -497,7 +483,7 @@ def Telemetry(local, ton):
497483
data["swap"] = GetSwapInfo()
498484
data["uname"] = GetUname()
499485
data["vprocess"] = GetValidatorProcessInfo()
500-
data["db"] = get_db_stats()
486+
data["dbStats"] = get_db_stats()
501487
elections = local.try_function(ton.GetElectionEntries)
502488
complaints = local.try_function(ton.GetComplaints)
503489

mytoncore/utils.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
import json
3+
import re
34

45

56
def str2b64(s):
@@ -49,19 +50,19 @@ def b642hex(input):
4950

5051

5152
def xhex2hex(x):
52-
try:
53-
b = x[1:]
54-
h = b.lower()
55-
return h
56-
except:
57-
return None
53+
try:
54+
b = x[1:]
55+
h = b.lower()
56+
return h
57+
except:
58+
return None
5859
#end define
5960

6061
def hex2base64(h): # TODO: remove duplicates
61-
b = bytes.fromhex(h)
62-
b64 = base64.b64encode(b)
63-
s = b64.decode("utf-8")
64-
return s
62+
b = bytes.fromhex(h)
63+
b64 = base64.b64encode(b)
64+
s = b64.decode("utf-8")
65+
return s
6566
#end define
6667

6768

@@ -73,7 +74,26 @@ def str2bool(str):
7374

7475

7576
def ng2g(ng):
76-
if ng is None:
77-
return
78-
return int(ng)/10**9
77+
if ng is None:
78+
return
79+
return int(ng)/10**9
7980
#end define
81+
82+
83+
def parse_db_stats(path: str):
84+
with open(path) as f:
85+
lines = f.readlines()
86+
result = {}
87+
for line in lines:
88+
s = line.strip().split(maxsplit=1)
89+
items = re.findall(r"(\S+)\s:\s(\S+)", s[1])
90+
if len(items) == 1:
91+
item = items[0]
92+
if float(item[1]) > 0:
93+
result[s[0]] = float(item[1])
94+
else:
95+
if any(float(v) > 0 for k, v in items):
96+
result[s[0]] = {}
97+
result[s[0]] = {k: float(v) for k, v in items}
98+
return result
99+
# end define

0 commit comments

Comments
 (0)