Why create your own monitoring tools when there are so many better ones in the market? … Why not?

Maybe you want to do performance testing. Maybe you are using low spec system and want to create your own monitoring tools instead of inbuilt tools such as htop to reduce impact of analysis on data being analyzed. Maybe you just want to learn for the sake of learning. In this article I will help you write the script to monitor system. I will primarily use golang as it is fast, simple to can be compiled natively.

Of course, we will not all will be discussed all the method of monitoring all the parameters in this article. For code reference on what we are discussing here as well as some extra parameters, you can refer to my GitHub page here:  https://github.com/umangshrestha/system-monitoring

Before we start we need to learn little basics about pseudo files. We will try to keep the theory to minimum as possible.

Pseudo Files

Linux home folder structure.

In Linux, there are concepts called pseudo files. As the name suggests they are not a real files but look as such. They primarily reside in ram and store information about current system set. As such, they don’t pertain the data like other files after system restart. For system monitoring we mostly care only about /proc/ files. Learning the psudo files will take you one step closes to better understanding of linux.

/proc/cpuinfo -> nproc

nproc prints the number of CPU processing units available in the system. In normal programming this is the max number of threads that kernel allocates.

$ nproc
8

#linux #golang #go #shell

Create Your Own System Monitoring tool in Linux
4.05 GEEK