Skip to content

Commit 844a5dd

Browse files
committed
fix windows流量虚高
1 parent 1c32de5 commit 844a5dd

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

clients/client-psutil.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import platform
3333
from queue import Queue
3434

35+
_net_io_counters_lock = threading.Lock()
36+
3537
def _env_str(name, default):
3638
value = os.getenv(name)
3739
if value is None or value == "":
@@ -146,10 +148,14 @@ def get_cpu_model():
146148
return vendor
147149
return get_platform_cpu_arch()
148150

151+
def _get_net_io_counters():
152+
with _net_io_counters_lock:
153+
return psutil.net_io_counters(pernic=True)
154+
149155
def liuliang():
150156
NET_IN = 0
151157
NET_OUT = 0
152-
net = psutil.net_io_counters(pernic=True)
158+
net = _get_net_io_counters()
153159
for k, v in net.items():
154160
if 'lo' in k or 'tun' in k \
155161
or 'docker' in k or 'veth' in k \
@@ -272,7 +278,7 @@ def _net_speed():
272278
while True:
273279
avgrx = 0
274280
avgtx = 0
275-
for name, stats in psutil.net_io_counters(pernic=True).items():
281+
for name, stats in _get_net_io_counters().items():
276282
if "lo" in name or "tun" in name \
277283
or "docker" in name or "veth" in name \
278284
or "br-" in name or "vmbr" in name \

0 commit comments

Comments
 (0)