Beaver763987450
New Member
I use Linux for quite some time, but I am somewhat new to the Linux internals, the Linux philosophy of things, and the command line tools in Linux.
I am also a developer and I was interested in creating my own tools for Linux.
The first thing that I wanted to try, was to find a way to programmatically retrieve CPU/RAM/Disk utilization and also retrieving APT package information for using it to build a server monitoring and management tool.
The Windows way for all these things is calling Windows API functions.
E.g. for CPU utilization: https://stackoverflow.com/a/43357695
Trying to find the way to do this in Linux caused a massive headache for me because:
Perhaps this goes along the same dividing topic, revolving around whether to have central and essential tools, like systemd, to perform actions or let each application do everything from scratch. But wouldn't it be nice if there was one of the below things? :
Perhaps I am missing a lot of things, since I am pretty new to interacting with Linux in an application-level, but I have seen how firewalls like PfSense interact with the FreeBSD OS, and I am looking at how HTOP retrieves system information ( https://github.com/htop-dev/htop/bl...26e73b03b00005a6096/linux/LinuxMachine.c#L402 ) and I am wondering if this is the best way possible.
Maybe I am too unaccustomed to passing strings of text around, from process to process.
I am also a developer and I was interested in creating my own tools for Linux.
The first thing that I wanted to try, was to find a way to programmatically retrieve CPU/RAM/Disk utilization and also retrieving APT package information for using it to build a server monitoring and management tool.
The Windows way for all these things is calling Windows API functions.
E.g. for CPU utilization: https://stackoverflow.com/a/43357695
Trying to find the way to do this in Linux caused a massive headache for me because:
- There are no OS APIs, as far as I know.
- The tools that exists in Linux (e.g. APT) often don't provide ways to have input/output served in a machine-readable format. Not to mention that they might not be installed at all...
- Using virtual files like
/proc/stat
to retrieve information seems complex/hacky/unreliable/inefficient because, there is a lot of parsing going on (reference this and this).
Perhaps this goes along the same dividing topic, revolving around whether to have central and essential tools, like systemd, to perform actions or let each application do everything from scratch. But wouldn't it be nice if there was one of the below things? :
- An API to retrieve OS information. I am guessing people in Linux are not so fond of this idea for some reason.
- Tools (like APT, systemd, etc) that also provide machine-readable input/output options in a consiste.
- Virtual files (like
/proc/stat
) where you can at least read data in a binary format, and don't have to parse strings, or remember what each text-column is (since you could read an entire struct with names that are prettier).
Perhaps I am missing a lot of things, since I am pretty new to interacting with Linux in an application-level, but I have seen how firewalls like PfSense interact with the FreeBSD OS, and I am looking at how HTOP retrieves system information ( https://github.com/htop-dev/htop/bl...26e73b03b00005a6096/linux/LinuxMachine.c#L402 ) and I am wondering if this is the best way possible.
Maybe I am too unaccustomed to passing strings of text around, from process to process.