diff --git a/common.py b/common.py index 3a01b62..44d9be4 100644 --- a/common.py +++ b/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' \ No newline at end of file diff --git a/sargraph.py b/sargraph.py index f7ac1a8..1c79d21 100755 --- a/sargraph.py +++ b/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": diff --git a/watch.py b/watch.py index 0a628ae..e1a9726 100644 --- a/watch.py +++ b/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,