您好我正在使用psutil我想访问bytes_sent
net = psutil.net_io_counters(pernic=True)
output =>
{'lo': iostat(bytes_sent=122424, bytes_recv=122424, packets_sent=1408, packets_recv=1408, errin=0, errout=0, dropin=0, dropout=0), 'kvnet': iostat(bytes_sent=3594694, bytes_recv=25226835, packets_sent=28971, packets_recv=29051, errin=0, errout=0, dropin=0, dropout=0), 'eth0': iostat(bytes_sent=5591347, bytes_recv=29589927, packets_sent=33000, packets_recv=46178, errin=0, errout=0, dropin=0, dropout=0)}
当我这样做时:
sent = psutil.net_io_counters().bytes_sent()
receved = psutil.net_io_counters().bytes_recv()
我收到错误
TypeError: 'int' object is not callable
问题是什么?
答案 0 :(得分:0)
psutil.net_io_counters(pernic=True)
返回包含所有接口统计信息的dict。
为了获得个人结果,您需要执行以下操作:
net = psutil.net_io_counters(pernic=True)
# Notice no brackets in the end
sent = net['lo'].bytes_sent
received = net['lo'].bytes_recv
# or with the eth0 interface
sent = net['eth0'].bytes_sent
received = net['eth0'].bytes_recv
答案 1 :(得分:0)
摆脱引号:-
psutil.net_io_counters().bytes_sent