Browse Source

[#85496] Prepare support for windows

main
Przemysław Barcicki 3 months ago
parent
commit
ec637f8423
  1. 3
      common.py
  2. 4
      sargraph.py
  3. 8
      watch.py

3
common.py

@ -97,3 +97,6 @@ def is_version_ge(a, b):
def is_darwin():
return platform.system() == 'Darwin'
def is_windows():
return platform.system() == 'Windows'

4
sargraph.py

@ -50,7 +50,7 @@ def create_session():
fail(f"No device is mounted on {args.fspath}")
params = (args.session, args.fsdev, args.iface, args.tmpfs, args.cache, args.udp, args.udp_cookie)
if is_darwin() or args.psutil:
if is_darwin() or args.psutil or is_windows():
watcher = watch.PsUtilWatcher(*params)
else:
watcher = watch.SarWatcher(*params)
@ -59,7 +59,7 @@ def create_session():
sys.exit(0)
# Check if sar is available
if not is_darwin():
if not (is_darwin() or is_windows()):
p = run_or_fail("sar", "-V", stdout=subprocess.PIPE)
if args.name != "data":

8
watch.py

@ -102,8 +102,10 @@ def read_iface_stats(iface):
return rx, tx
def get_socket(session):
# TODO: when using on other platforms make sure this path exist; namely windows
path = f"/tmp/sargraph-{session}.sock"
if is_windows():
path = fr"\\.\pipe\sargraph-{session}"
else:
path = f"/tmp/sargraph-{session}.sock"
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
return sock, path
@ -215,7 +217,7 @@ class Watcher(abc.ABC):
used = (ram_data.total - ram_data.free)
if used // 1024 > MAX_USED_RAM:
MAX_USED_RAM = used // 1024
if is_darwin():
if isinstance(self, PsUtilWatcher):
line = [
date + "-" + daytime,
100 * ram_data.free / ram_data.total,

Loading…
Cancel
Save