Add functions for fetching information about CPU, RAM and Disk usage
I'm trying to build like a dashboard for my system using AGS for displaying CPU, RAM and disk usage as well as wifi, bluetooth, and monitor settings and other utilities.
There's no builtin function for getting CPU usage, memory usage and disks that are mounted on the system so I'll have to build those myself reading directly from /proc which is not ideal. You have libraries for cava, bluetooth and network manager but you forgot the most basic thing which is CPU and RAM.
There's no builtin function for getting CPU usage, memory usage and disks that are mounted on the system so I'll have to build those myself reading directly from /proc which is not ideal. You have libraries for cava, bluetooth and network manager but you forgot the most basic thing which is CPU and RAM.
You could, and should use libgtop which is Glib implementation of top, the library most GTK Dashboards like the Elementary one use. I use it here for instance, but it gives almost all the information you could need.
@ARKye03 But how do I call it from javascript/GJS?
figured it out myself:
flake.nix:
{
description = "My Awesome Desktop Shell";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
ags = {
url = "github:aylur/ags";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
ags,
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
packages.${system} = {
default = ags.lib.bundle {
inherit pkgs;
src = ./.;
name = "ags-desktop";
entry = "app.ts";
# additional libraries and executables to add to gjs' runtime
extraPackages = with ags.packages.${system}; [
hyprland
battery
apps
pkgs.libgtop
];
};
};
devShells.${system} = {
default = pkgs.mkShell {
nativeBuildInputs = [
pkgs.biome
pkgs.nodePackages.nodemon
pkgs.just
(ags.packages.${system}.agsFull.override {
extraPackages = [
# you need to include libgtop here to add to the gjs runtime environment
pkgs.libgtop
];
})
];
};
};
};
}
Javascript/Typescript:
import GTop from "gi://GTop";