Skip to content

Commit 34c7970

Browse files
committed
print ls stats to status
refactor
1 parent f5cd1d3 commit 34c7970

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

mytoncore/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def CalculateNetworkStatistics(zerodata, data):
287287

288288

289289
def save_node_statistics(local, ton):
290-
status = ton.GetValidatorStatus()
290+
status = ton.GetValidatorStatus(no_cache=True)
291291
if status.unixtime is None:
292292
return
293293
data = {'timestamp': status.unixtime}

mytoncore/mytoncore.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,11 @@ def parse_stats_from_vc(self, output: str, result: dict):
771771
if name not in result:
772772
result[name] = value
773773

774-
def GetValidatorStatus(self):
774+
def GetValidatorStatus(self, no_cache=False):
775775
# Get buffer
776776
bname = "validator_status"
777777
buff = self.GetFunctionBuffer(bname)
778-
if buff:
778+
if buff and not no_cache:
779779
return buff
780780
#end if
781781

@@ -3038,6 +3038,40 @@ def GetStatistics(self, name, statistics=None):
30383038
return data
30393039
#end define
30403040

3041+
def get_node_statistics(self):
3042+
"""
3043+
:return: stats for collated/validated blocks since round beggining and stats for ls queries for the last minute
3044+
"""
3045+
stats = self.local.db.get('statistics', {}).get('node')
3046+
result = {}
3047+
if stats is not None and len(stats) == 3 and stats[0] is not None:
3048+
collated_ok = 0
3049+
collated_error = 0
3050+
validated_ok = 0
3051+
validated_error = 0
3052+
for k in ['master', 'shard']:
3053+
collated_ok += stats[2]['collated_blocks'][k]['ok'] - stats[0]['collated_blocks'][k]['ok']
3054+
collated_error += stats[2]['collated_blocks'][k]['error'] - stats[0]['collated_blocks'][k]['error']
3055+
validated_ok += stats[2]['validated_blocks'][k]['ok'] - stats[0]['validated_blocks'][k]['ok']
3056+
validated_error += stats[2]['validated_blocks'][k]['error'] - stats[0]['validated_blocks'][k]['error']
3057+
result = {
3058+
'collated': {
3059+
'ok': collated_ok,
3060+
'error': collated_error,
3061+
},
3062+
'validated': {
3063+
'ok': validated_ok,
3064+
'error': validated_error,
3065+
},
3066+
}
3067+
if stats is not None and len(stats) >= 2:
3068+
result['ls_queries'] = {
3069+
'ok': stats[-1]['ls_queries']['ok'] - stats[-2]['ls_queries']['ok'],
3070+
'error': stats[-1]['ls_queries']['error'] - stats[-2]['ls_queries']['error'],
3071+
'time': stats[-1].get('timestamp', 0) - stats[-2].get('timestamp', 0),
3072+
}
3073+
return result
3074+
30413075
def GetSettings(self, name):
30423076
# self.local.load_db()
30433077
result = self.local.db.get(name)

mytonctrl/mytonctrl.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -752,21 +752,16 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
752752
validator_out_of_ser_text = local.translate("local_status_validator_out_of_ser").format(f'{validator_status.out_of_ser} blocks ago')
753753

754754
collated, validated = None, None
755+
ls_queries = None
755756
if ton.using_validator() and validatorIndex != -1:
756-
stats = ton.local.db.get('statistics', {}).get('node')
757-
if stats is not None and len(stats) == 3:
758-
collated_ok = 0
759-
collated_error = 0
760-
validated_ok = 0
761-
validated_error = 0
762-
for k in ['master', 'shard']:
763-
collated_ok += stats[2]['collated_blocks'][k]['ok'] - stats[0]['collated_blocks'][k]['ok']
764-
collated_error += stats[2]['collated_blocks'][k]['error'] - stats[0]['collated_blocks'][k]['error']
765-
validated_ok += stats[2]['validated_blocks'][k]['ok'] - stats[0]['validated_blocks'][k]['ok']
766-
validated_error += stats[2]['validated_blocks'][k]['error'] - stats[0]['validated_blocks'][k]['error']
767-
collated = local.translate['collated_blocks'].format(collated_ok, collated_error)
768-
validated = local.translate['validated_blocks'].format(validated_ok, validated_error)
769-
757+
node_stats = ton.get_node_statistics()
758+
if node_stats and 'collated' in node_stats and 'validated' in node_stats:
759+
collated = local.translate('collated_blocks').format(node_stats['collated']['ok'], node_stats['collated']['error'])
760+
validated = local.translate('validated_blocks').format(node_stats['validated']['ok'], node_stats['validated']['error'])
761+
if ton.using_liteserver():
762+
node_stats = ton.get_node_statistics()
763+
if node_stats and 'ls_queries' in node_stats:
764+
ls_queries = local.translate('ls_queries').format(node_stats['ls_queries']['time'], node_stats['ls_queries']['ok'], node_stats['ls_queries']['error'])
770765

771766
dbSize_text = GetColorInt(dbSize, 1000, logic="less", ending=" Gb")
772767
dbUsage_text = GetColorInt(dbUsage, 80, logic="less", ending="%")
@@ -817,11 +812,13 @@ def PrintLocalStatus(local, ton, adnlAddr, validatorIndex, validatorEfficiency,
817812
print(validator_out_of_sync_text)
818813
print(master_out_of_sync_text)
819814
print(shard_out_of_sync_text)
815+
if validator_out_of_ser_text:
816+
print(validator_out_of_ser_text)
820817
if collated and validated:
821818
print(collated)
822819
print(validated)
823-
if validator_out_of_ser_text:
824-
print(validator_out_of_ser_text)
820+
if ls_queries:
821+
print(ls_queries)
825822
print(dbStatus_text)
826823
print(mtcVersion_text)
827824
print(validatorVersion_text)

mytonctrl/resources/translate.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,19 @@
345345
"zh_TW": "本地驗證者最後一次狀態序列化: {0}"
346346
},
347347
"collated_blocks": {
348-
"en": "Collated blocks since validation round started (success/error): {0}",
349-
"ru": "Собранные блоки с начала раунда валидации (успех/ошибка): {0}",
350-
"zh_TW": "自驗證週期開始以來的彙編區塊 (成功/錯誤): {0}"
348+
"en": "Collated blocks since validation round started (success/error): {0}/{1}",
349+
"ru": "Собранные блоки с начала раунда валидации (успех/ошибка): {0}/{1}",
350+
"zh_TW": "自驗證週期開始以來的彙編區塊 (成功/錯誤): {0}/{1}"
351351
},
352352
"validated_blocks": {
353-
"en": "Validated blocks since validation round started (success/error): {0}",
354-
"ru": "Проверенные блоки с начала раунда валидации (успех/ошибка): {0}",
355-
"zh_TW": "自驗證週期開始以來的驗證區塊 (成功/錯誤): {0}"
353+
"en": "Validated blocks since validation round started (success/error): {0}/{1}",
354+
"ru": "Проверенные блоки с начала раунда валидации (успех/ошибка): {0}/{1}",
355+
"zh_TW": "自驗證週期開始以來的驗證區塊 (成功/錯誤): {0}/{1}"
356+
},
357+
"ls_queries": {
358+
"en": "Liteserver queries for the past {0} sec (success/error): {1}/{2}",
359+
"ru": "Запросы к лайтсерверу за последние {0} сек (успех/ошибка): {1}/{2}",
360+
"zh_TW": "過去 {0} 秒的輕量級服務器查詢 (成功/錯誤): {1}/{2}"
356361
},
357362
"local_status_db": {
358363
"en": "Local validator database size: {0}, {1}",

0 commit comments

Comments
 (0)