diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2024-05-31 01:41:00 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2024-05-31 01:41:00 -0500 |
commit | 8b30fd8b51875b2a113911e0a99fef2a7e563aa4 (patch) | |
tree | 63bbf241730efda56ca44438a6b4fc192b628dbc /i3blocks/.local | |
parent | ac1d1eea5ca6d57b7261cda8ce48d8b80a0acbfe (diff) |
feat(i3blocks): add system stat blocklets
Diffstat (limited to 'i3blocks/.local')
-rwxr-xr-x | i3blocks/.local/lib/i3blocks/i3blocks-cpu | 26 | ||||
-rwxr-xr-x | i3blocks/.local/lib/i3blocks/i3blocks-disk | 28 | ||||
-rwxr-xr-x | i3blocks/.local/lib/i3blocks/i3blocks-gpu | 30 | ||||
-rwxr-xr-x | i3blocks/.local/lib/i3blocks/i3blocks-memory | 30 | ||||
-rwxr-xr-x | i3blocks/.local/lib/i3blocks/i3blocks-volume | 2 |
5 files changed, 114 insertions, 2 deletions
diff --git a/i3blocks/.local/lib/i3blocks/i3blocks-cpu b/i3blocks/.local/lib/i3blocks/i3blocks-cpu new file mode 100755 index 0000000..3ad1f28 --- /dev/null +++ b/i3blocks/.local/lib/i3blocks/i3blocks-cpu @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import os + +ICON = "\U000f0ee0" # + + +def main(): + with open("/proc/loadavg", "r") as stat: + load, _ = stat.readline().split(None, 1) + load = round(float(load)) + + print(f" {ICON} {load}% \n") + if load > 90: + print(os.environ.get("black", "")) + print(os.environ.get("red", "")) + elif load > 60: + print(os.environ.get("black", "")) + print(os.environ.get("yellow", "")) + elif load > 30: + print(os.environ.get("black", "")) + print(os.environ.get("green", "")) + + +if __name__ == "__main__": + main() diff --git a/i3blocks/.local/lib/i3blocks/i3blocks-disk b/i3blocks/.local/lib/i3blocks/i3blocks-disk new file mode 100755 index 0000000..2971a49 --- /dev/null +++ b/i3blocks/.local/lib/i3blocks/i3blocks-disk @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import os + +ICON = "\U000f02ca" # +GB = 1073741824 + + +def main(): + statvfs = os.statvfs("/") + avail = bytes = statvfs.f_bavail * statvfs.f_frsize + + for unit in ["B", "KB", "MB", "GB", "TB", "PB"]: + if avail < 1024.0 or unit == "PB": + break + avail /= 1024.0 + + print(f" {ICON} {round(avail)}{unit} \n") + if bytes < (20 * GB): + print(os.environ.get("black", "")) + print(os.environ.get("red", "")) + elif bytes < (10 * GB): + print(os.environ.get("black", "")) + print(os.environ.get("yellow", "")) + + +if __name__ == "__main__": + main() diff --git a/i3blocks/.local/lib/i3blocks/i3blocks-gpu b/i3blocks/.local/lib/i3blocks/i3blocks-gpu new file mode 100755 index 0000000..bf1a31d --- /dev/null +++ b/i3blocks/.local/lib/i3blocks/i3blocks-gpu @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import os +import glob + +ICON = "\U000f0379" # + + +def main(): + files = glob.glob("/sys/class/drm/card*/device/gpu_busy_percent") + if not files: + return + + with open(files[0]) as f: + usage = int(f.readline()) + + print(f" {ICON} {usage}% \n") + if usage > 90: + print(os.environ.get("black", "")) + print(os.environ.get("red", "")) + elif usage > 60: + print(os.environ.get("black", "")) + print(os.environ.get("yellow", "")) + elif usage > 30: + print(os.environ.get("black", "")) + print(os.environ.get("green", "")) + + +if __name__ == "__main__": + main() diff --git a/i3blocks/.local/lib/i3blocks/i3blocks-memory b/i3blocks/.local/lib/i3blocks/i3blocks-memory new file mode 100755 index 0000000..ff0d7ae --- /dev/null +++ b/i3blocks/.local/lib/i3blocks/i3blocks-memory @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import os +import linecache + +ICON = "\U000f035b" # + + +def main(): + linecache.getline("/proc/meminfo", 0) + linecache.getline("/proc/meminfo", 2) + + with open("/proc/meminfo", "r") as f: + meminfo = dict( + (i.split()[0].rstrip(":"), int(i.split()[1])) for i in f.readlines() + ) + + used = 100 - round(100 * meminfo["MemAvailable"] / meminfo["MemTotal"]) + + print(f" {ICON} {used}% \n") + if used > 95: + print(os.environ.get("black", "")) + print(os.environ.get("red", "")) + elif used > 80: + print(os.environ.get("black", "")) + print(os.environ.get("yellow", "")) + + +if __name__ == "__main__": + main() diff --git a/i3blocks/.local/lib/i3blocks/i3blocks-volume b/i3blocks/.local/lib/i3blocks/i3blocks-volume index cd7c9c4..c5ff1e2 100755 --- a/i3blocks/.local/lib/i3blocks/i3blocks-volume +++ b/i3blocks/.local/lib/i3blocks/i3blocks-volume @@ -69,8 +69,6 @@ class PulseAudio: output["color"] = os.environ.get("black") output["background"] = os.environ.get("yellow") - output.update(self.color) - match format: case "json": print(json.dumps(output), flush=True) |