File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232import platform
3333from queue import Queue
3434
35+ _net_io_counters_lock = threading .Lock ()
36+
3537def _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+
149155def 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 \
You can’t perform that action at this time.
0 commit comments