@@ -286,6 +286,56 @@ def CalculateNetworkStatistics(zerodata, data):
286286# end define
287287
288288
289+ def save_node_statistics (local , ton ):
290+ status = ton .GetValidatorStatus ()
291+ if status .unixtime is None :
292+ return
293+ data = {'timestamp' : status .unixtime }
294+
295+ def get_ok_error (value : str ):
296+ ok , error = value .split ()
297+ return int (ok .split (':' )[1 ]), int (error .split (':' )[1 ])
298+
299+ if 'total.collated_blocks.master' in status :
300+ master_ok , master_error = get_ok_error (status ['total.collated_blocks.master' ])
301+ shard_ok , shard_error = get_ok_error (status ['total.collated_blocks.shard' ])
302+ data ['collated_blocks' ] = {
303+ 'master' : {'ok' : master_ok , 'error' : master_error },
304+ 'shard' : {'ok' : shard_ok , 'error' : shard_error },
305+ }
306+ if 'total.validated_blocks.master' in status :
307+ master_ok , master_error = get_ok_error (status ['total.validated_blocks.master' ])
308+ shard_ok , shard_error = get_ok_error (status ['total.validated_blocks.shard' ])
309+ data ['validated_blocks' ] = {
310+ 'master' : {'ok' : master_ok , 'error' : master_error },
311+ 'shard' : {'ok' : shard_ok , 'error' : shard_error },
312+ }
313+ if 'total.ext_msg_check' in status :
314+ ok , error = get_ok_error (status ['total.ext_msg_check' ])
315+ data ['ext_msg_check' ] = {'ok' : ok , 'error' : error }
316+ if 'total.ls_queries_ok' in status and 'total.ls_queries_error' in status :
317+ data ['ls_queries' ] = {}
318+ for k in status ['total.ls_queries_ok' ]:
319+ if k .startswith ('TOTAL' ):
320+ data ['ls_queries' ]['ok' ] = k .split (':' )[1 ]
321+ for k in status ['total.ls_queries_error' ]:
322+ if k .startswith ('TOTAL' ):
323+ data ['ls_queries' ]['error' ] = k .split (':' )[1 ]
324+ statistics = local .db .get ("statistics" , dict ())
325+
326+ # statistics['node'] = [stats_from_election_id, stats_from_prev_min, stats_now]
327+
328+ election_id = ton .GetConfig32 ()['startWorkTime' ]
329+ if 'node' not in statistics or len (statistics ['node' ]) < 1 :
330+ statistics ['node' ] = [data ]
331+ elif statistics ['node' ][0 ]['timestamp' ] < election_id :
332+ statistics ['node' ] = [data , data ]
333+ else :
334+ statistics ['node' ] = statistics .get ('node' , []) + [data ]
335+ statistics ['node' ].pop (1 )
336+ local .db ["statistics" ] = statistics
337+
338+
289339def ReadTransData (local , scanner ):
290340 transData = local .buffer .transData
291341 SetToTimeData (transData , scanner .transNum )
@@ -581,6 +631,8 @@ def General(local):
581631
582632 local .start_cycle (ScanLiteServers , sec = 60 , args = (local , ton ,))
583633
634+ local .start_cycle (save_node_statistics , sec = 60 , args = (local , ton , ))
635+
584636 from modules .custom_overlays import CustomOverlayModule
585637 local .start_cycle (CustomOverlayModule (ton , local ).custom_overlays , sec = 60 , args = ())
586638
0 commit comments