Monitor resources on a UNIX machine (with Perl)

To get an overview of what is running on a certain UNIX/Linux host, most users will usually run of one the following commands:

  • ps
  • top
  • htop

But most of the times, they will not give a correct view of what is really going on, and most of the times we want to see totals instead of individual processes with their resource consumption.

Since Perl is one of the default scripting languages on almost every UNIX/Linux flavour, we will use this language to create a script which will allow us to get general overview of how much an application is really using up (all childs processes, threads, …).

The script uses two functions:

  • get_proc_list()
  • print_sorted()

This function executes the ps command and will create a sum of the resource values per application and user. These values will be sorted in a descended way (highest will be first element in the list).

This function will print out the data structures returned by get_proc_list().

We call these functions in one liner statements like:

Sample output:

Comments are closed.