6
6
#
7
7
#####################################################################
8
8
9
- import json
9
+ import _pickle as pickle
10
10
import argparse
11
11
import datetime
12
12
import sys
@@ -28,7 +28,7 @@ from collections import namedtuple, OrderedDict
28
28
from natsort import natsorted
29
29
from tabulate import tabulate
30
30
from utilities_common .netstat import ns_diff , table_as_json , STATUS_NA , format_brate , format_prate
31
- from utilities_common .cli import json_serial , UserCache
31
+ from utilities_common .cli import UserCache
32
32
from swsscommon .swsscommon import SonicV2Connector
33
33
34
34
nstat_fields = (
@@ -96,7 +96,7 @@ class Intfstat(object):
96
96
counter_data = self .db .get (self .db .COUNTERS_DB , full_table_id , counter_name )
97
97
if counter_data :
98
98
fields [pos ] = str (counter_data )
99
- cntr = NStats ._make (fields ). _asdict ()
99
+ cntr = NStats ._make (fields )
100
100
return cntr
101
101
102
102
def get_rates (table_id ):
@@ -153,14 +153,14 @@ class Intfstat(object):
153
153
rates = ratestat_dict .get (key , RateStats ._make ([STATUS_NA ] * len (rates_key_list )))
154
154
155
155
table .append ((key ,
156
- data [ ' rx_p_ok' ] ,
156
+ data . rx_p_ok ,
157
157
format_brate (rates .rx_bps ),
158
158
format_prate (rates .rx_pps ),
159
- data [ ' rx_p_err' ] ,
160
- data [ ' tx_p_ok' ] ,
159
+ data . rx_p_err ,
160
+ data . tx_p_ok ,
161
161
format_brate (rates .tx_bps ),
162
162
format_prate (rates .tx_pps ),
163
- data [ ' tx_p_err' ] ))
163
+ data . tx_p_err ))
164
164
165
165
if use_json :
166
166
print (table_as_json (table , header ))
@@ -186,24 +186,24 @@ class Intfstat(object):
186
186
187
187
if old_cntr is not None :
188
188
table .append ((key ,
189
- ns_diff (cntr [ ' rx_p_ok' ] , old_cntr [ ' rx_p_ok' ] ),
189
+ ns_diff (cntr . rx_p_ok , old_cntr . rx_p_ok ),
190
190
format_brate (rates .rx_bps ),
191
191
format_prate (rates .rx_pps ),
192
- ns_diff (cntr [ ' rx_p_err' ] , old_cntr [ ' rx_p_err' ] ),
193
- ns_diff (cntr [ ' tx_p_ok' ] , old_cntr [ ' tx_p_ok' ] ),
192
+ ns_diff (cntr . rx_p_err , old_cntr . rx_p_err ),
193
+ ns_diff (cntr . tx_p_ok , old_cntr . tx_p_ok ),
194
194
format_brate (rates .tx_bps ),
195
195
format_prate (rates .tx_pps ),
196
- ns_diff (cntr [ ' tx_p_err' ] , old_cntr [ ' tx_p_err' ] )))
196
+ ns_diff (cntr . tx_p_err , old_cntr . tx_p_err )))
197
197
else :
198
198
table .append ((key ,
199
- cntr [ ' rx_p_ok' ] ,
199
+ cntr . rx_p_ok ,
200
200
format_brate (rates .rx_bps ),
201
201
format_prate (rates .rx_pps ),
202
- cntr [ ' rx_p_err' ] ,
203
- cntr [ ' tx_p_ok' ] ,
202
+ cntr . rx_p_err ,
203
+ cntr . tx_p_ok ,
204
204
format_brate (rates .tx_bps ),
205
205
format_prate (rates .tx_pps ),
206
- cntr [ ' tx_p_err' ] ))
206
+ cntr . tx_p_err ))
207
207
208
208
if use_json :
209
209
print (table_as_json (table , header ))
@@ -229,17 +229,17 @@ class Intfstat(object):
229
229
230
230
if cnstat_old_dict and cnstat_old_dict .get (rif ):
231
231
old_cntr = cnstat_old_dict .get (rif )
232
- body = body % (ns_diff (cntr [ ' rx_p_ok' ] , old_cntr [ ' rx_p_ok' ] ),
233
- ns_diff (cntr [ ' rx_b_ok' ] , old_cntr [ ' rx_b_ok' ] ),
234
- ns_diff (cntr [ ' rx_p_err' ] , old_cntr [ ' rx_p_err' ] ),
235
- ns_diff (cntr [ ' rx_b_err' ] , old_cntr [ ' rx_b_err' ] ),
236
- ns_diff (cntr [ ' tx_p_ok' ] , old_cntr [ ' tx_p_ok' ] ),
237
- ns_diff (cntr [ ' tx_b_ok' ] , old_cntr [ ' tx_b_ok' ] ),
238
- ns_diff (cntr [ ' tx_p_err' ] , old_cntr [ ' tx_p_err' ] ),
239
- ns_diff (cntr [ ' tx_b_err' ] , old_cntr [ ' tx_b_err' ] ))
232
+ body = body % (ns_diff (cntr . rx_p_ok , old_cntr . rx_p_ok ),
233
+ ns_diff (cntr . rx_b_ok , old_cntr . rx_b_ok ),
234
+ ns_diff (cntr . rx_p_err , old_cntr . rx_p_err ),
235
+ ns_diff (cntr . rx_b_err , old_cntr . rx_b_err ),
236
+ ns_diff (cntr . tx_p_ok , old_cntr . tx_p_ok ),
237
+ ns_diff (cntr . tx_b_ok , old_cntr . tx_b_ok ),
238
+ ns_diff (cntr . tx_p_err , old_cntr . tx_p_err ),
239
+ ns_diff (cntr . tx_b_err , old_cntr . tx_b_err ))
240
240
else :
241
- body = body % (cntr [ ' rx_p_ok' ] , cntr [ ' rx_b_ok' ] , cntr [ ' rx_p_err' ] ,cntr [ ' rx_b_err' ] ,
242
- cntr [ ' tx_p_ok' ] , cntr [ ' tx_b_ok' ] , cntr [ ' tx_p_err' ] , cntr [ ' tx_b_err' ] )
241
+ body = body % (cntr . rx_p_ok , cntr . rx_b_ok , cntr . rx_p_err ,cntr . rx_b_err ,
242
+ cntr . tx_p_ok , cntr . tx_b_ok , cntr . tx_p_err , cntr . tx_b_err )
243
243
244
244
print (header )
245
245
print (body )
@@ -305,20 +305,20 @@ def main():
305
305
if tag_name is not None :
306
306
if os .path .isfile (cnstat_fqn_general_file ):
307
307
try :
308
- general_data = json .load (open (cnstat_fqn_general_file , 'r ' ))
308
+ general_data = pickle .load (open (cnstat_fqn_general_file , 'rb ' ))
309
309
for key , val in cnstat_dict .items ():
310
310
general_data [key ] = val
311
- json .dump (general_data , open (cnstat_fqn_general_file , 'w ' ))
311
+ pickle .dump (general_data , open (cnstat_fqn_general_file , 'wb ' ))
312
312
except IOError as e :
313
313
sys .exit (e .errno )
314
314
# Add the information also to tag specific file
315
315
if os .path .isfile (cnstat_fqn_file ):
316
- data = json .load (open (cnstat_fqn_file , 'r ' ))
316
+ data = pickle .load (open (cnstat_fqn_file , 'rb ' ))
317
317
for key , val in cnstat_dict .items ():
318
318
data [key ] = val
319
- json .dump (data , open (cnstat_fqn_file , 'w ' ))
319
+ pickle .dump (data , open (cnstat_fqn_file , 'wb ' ))
320
320
else :
321
- json .dump (cnstat_dict , open (cnstat_fqn_file , 'w' ), default = json_serial )
321
+ pickle .dump (cnstat_dict , open (cnstat_fqn_file , 'wb' ) )
322
322
except IOError as e :
323
323
sys .exit (e .errno )
324
324
else :
@@ -330,9 +330,9 @@ def main():
330
330
try :
331
331
cnstat_cached_dict = {}
332
332
if os .path .isfile (cnstat_fqn_file ):
333
- cnstat_cached_dict = json .load (open (cnstat_fqn_file , 'r ' ))
333
+ cnstat_cached_dict = pickle .load (open (cnstat_fqn_file , 'rb ' ))
334
334
else :
335
- cnstat_cached_dict = json .load (open (cnstat_fqn_general_file , 'r ' ))
335
+ cnstat_cached_dict = pickle .load (open (cnstat_fqn_general_file , 'rb ' ))
336
336
337
337
print ("Last cached time was " + str (cnstat_cached_dict .get ('time' )))
338
338
if interface_name :
0 commit comments