How to control the process in Linux CPU, memory and time

How can I check the process on Linux? Do I need something like "top" and "time" compiled for a specific process name (is it a multiprocessor program in which so many PIDs will be set)?

In addition, I would like to have a graph over time of memory and processor usage for these processes, and not just finite numbers.

Any ideas?

+8
linux memory process cpu monitoring
source share
2 answers

The following are tools for monitoring a Linux system

  • System commands like top , free -m , vmstat , iostat , iotop , sar , netstat , etc. Nothing comes close to this linux utility when debugging a problem. This command gives you a clear image that is inside your server.
  • SeaLion : The agent executes all the commands specified in # 1 (also defined by the user), and the outputs of these commands can be accessed in a beautiful web interface. This tool is handy for debugging on hundreds of servers, because installation is easy. And for FREE
  • Nagios : he is the mother of all monitoring / alerting tools. This is a lot of settings, but very difficult to configure for beginners. There are toolkits called nagios plugins that cover almost all of the important Linux features.
  • Munin
  • Server Density : A cloud-based paid service that collects important metrics on Linux and enables users to create their own plugins.
  • New Relic: Another well-known monitoring service.
  • Zabbix
+7
source share

I usually dump a simple script for this type of work.

Take a look at the kernel documentation for the proc file system ("linux proc.txt").

The first line of /proc/stat (section 1.8 in proc.txt) will give you aggregate statistics on processor usage (i.e. user, good, system, simple, ...). For each process, the /proc/$PID/stat file (table 1-4 in the proc.txt file) will provide you with both processor usage statistics and memory usage statistics (see Rss).

If you share a little Google, you will find a lot of detailed information about these files and pointers to libraries / applications / code snippets to help you get / get the values ​​you need. With that in mind, I will focus on high-level strategies.

For processor statistics, use your favorite scripting language to create an executable file that accepts a set of process identifiers for monitoring. With a fixed interval (for example: 1 second), a poll / calculation of the total results for each process and the system as a whole. During each polling interval, write all the results in one line to the standard output.

For memory statistics, write a similar script, but just write down the memory usage for each process. Memory is a bit simpler as we directly get instantaneous values.

Run these scripts throughout the test, passing in a set of process IDs that you want to track and redirect your output to the log file.

 ./logcpu $(pidof foo) $(pidof bar) > cpustats ./logmem $(pidof foo) $(pidof bar) > memstats 

Import the contents of these files into a spreadsheet (for some applications it is as simple as copying / pasting). For the CPU, you are behind instantaneous values, but have cumulative values, so you need to do a little work with spreadsheets to get these values ​​(it's just the delta 't (x + 1) - t (x)'). Of course, you could write your cpu logger, but you will spend a little more time on the script.

Finally, use the table to create a nice plot.

+13
source share

All Articles