Linux programs and resource monitoring commands

Source: Internet
Author: User
Tags mrtg

 

1. Process Information

 

1 PS


[Root @ test/root] # ps-Aux

Parameter description:

A: select to list all programs.

U: list all user programs

X: list all tty programs

Example:

[Root @ test/root] # ps-Aux

User PID % CPU % mem vsz RSS tty stat Start Time Command

Root 1 0.0 0.1 1384 468? S mar31 0: 05 init [3]

Root 2 0.0 0.0 0 0? SW mar31 0: 00 [keventd]

Root 3 0.0 0.0 0 0? Swn mar31 0: 00 [ksoftirqd_cpu0]

Root 4 0.0 0.0 0 0? SW mar31 0: 11 [kswapd]

Root 5 0.0 0.0 0 0? SW mar31 0: 00 [bdflush]

Root 6 0.0 0.0 0 0? SW mar31 0: 00 [kupdated]

Root 130 0.0 0.0 0 0? SW mar31 0: 00 [kjournald]

Root 131 0.0 0.0 0 0? SW mar31 0: 01 [kjournald]

Root 132 0.0 0.0 0 0? SW mar31 0: 03 [kjournald]

Root 133 0.0 0.0 0 0? SW mar31 0: 12 [kjournald]

Root 482 0.0 0.2 1444 528? S mar31 0: 03 syslogd-M 0

........

The preceding command is used to query related programs executed in the background of the current host environment. I usually use the PS-Aux Parameter

List all information to check the program. The above procedures are described as follows:

· User: indicates which user the program belongs;

· PID: the code of the program;

· % CPU: indicates the number of CPU resources used by the program;

 

% Mem: indicates the amount of RAM used by the program;

· Vsz, RSS: occupied Ram size (in bytes );

· TTY: is the Program executed by the Login User? If it is a tty1-tty6, it is the local login, if it is pts /??, Then

Is a remote login;

· Stat: the State of the program. R is executable, S is the program in sleep, that is, it is not executed, and T is

Detecting or stopping. Z indicates the death program. Kill is required;

· Start: the start date of the program;

· Time: the running time of the program;

· Command: content of the program.

 

 

2 Top
[Root @ test/root] # top parameter description: In the program running top, you can enter the following characters for sorting A: sort by age or in the order of execution t: sort by startup time M: sort by memory size P: sort by consumed CPU resources example: [root @ test/root] # top 11: 55 pm up 8 days,, 1 user, load average: 0.22, 0.14, 0.10 71 processes: 69 sleeping, 2 running, 0 zombie, 0 stopped CPU states: 24.6% user, 3.7% system, 0.0% nice, 71.5% idle mem: 255892 k av, 222300 K used, 33592 K free, 0 K shrd, 48084 K buff swap: 28 9128 k av, 8184 K used, 280944 K free 110472 K cached PID user pri Ni size RSS share stat % CPU % mem Time Command 9898 root 9 0 5976 5976 1364 s 5.5 0: 00 MRTG 2.3 Apache 14 0 4744 5312 5052 s 2.1 1.9 httpd 9189 Apache 14 0 4520 4256 s 3752 0 01 httpd 1.9 Apache 10 0 1.6 9187 s 4544 001 httpd 4276 MySQL 9 0 3800 1.7 1.6 s 9212 7280 mysqld 9888 root 12 0 1064 1064 832 R 0.7 0.4 top 4842 MySQL 10 0 7280 4772 2716 s 0.5 0 06 mysqld 1.8 MySQL 10 0 9218 7280 4772 s 2716 00 mysqld PS is a good management tool, however, the PS is not dynamic after all. With top, you can use the dynamic (updated every five seconds) method to detect program running. In addition, P can be used to sort resources consumed by CPU, and m can be used to sort memory usage during the program running. It is a very useful management tool. 3 mpstat Install: APT-Get install sysstatUnlike top, mpstat can monitor CPU usage of multiple cores. (1) Current CPU usage mpstat (2) Current 1st CPU usage mpstat 1 (3) CPU usage, interval 1 second, display 3 mpstat 1 3

 

4 kill[Root @ test/root] # Kill-signal PID parameter description:-signal is the same as the preceding kill:-1: Let the PID re-read its configuration file-9: killing the program-15: stop the program example: [root @ test/root] # Kill-9 2380 to kill a program, you need to know the PID of the program. In addition, it should be noted that many programs are affiliated. For example, Sendmail may open many programs at the same time (if the number of emails is large, the entire program cannot be killed by the subprogram. To know the program code (PID), you must make good use of tools such as PS and top. In addition, you often find that the kill-1 PID is written in some scripts, where-l allows the PID to re-read the configuration file, which is most often found in the syslogd daemon.

 

2. Memory Information 1 free[Root @ test/root] # free parameter description:-K: Display memory in Kbytes-M: Display memory in Mbytes example: [root @ test/root] # free total used free shared buffers cached mem: 255892 222076 33816 0 49072 112272-/+ buffers/cache: 60732 195160 swap: 289128 7572 another way to view system resources is to use free to check the current memory usage. The above example shows that I have MB of memory and about MB of swap (virtual memory ). 2 SAR View CPU or memory information. Powerful functions.
[Root @ test/root] # SAR [-u] [-R] number of seconds parameter description:-u: View CPU usage-R: view memory usage in seconds: how many seconds? Times: Several observed examples: [root @ test/root] # Sar-u 1 3 12:10:28 am CPU % USER % nice % System % idle 12:10:29 am all 0.00 0.00 0.00 12:10:30 am all 100.00 0.00 0.00 0.00 100.00 12:10:31 AM all 12.00 0.00 1.00 87.00 average: all 4.00 0.00 0.33 95.67 24416 [root @ test/root] # Sar-R 1 3 12:11:11 am kbmemfree kbmemused % memused kbmemshrd kbbuffers kbcached kbswpfree kbswpused % swpused 12:11:12 am 231476 90.46 0 510 68 112536 281556 7572 2.62 12:11:13 am 24420 231472 90.46 0 51068 112536 281556 7572 2.62 12:11:14 am 24392 231500 90.47 0 51068 112540 281556 7572 average: 24409 231483 90.46 51068 112537 281556 7572 2.62 laruence is very fond of using SAR to view system resources. It is often used to view CPU and ram. Of course, you can also observe hard disk I/O changes. In the preceding example, we can find that the CPU idle takes a long time to observe the CPU. In addition, % memused (percentage used) and % swpused (percentage used in virtual memory) are commonly used to view Ram. This is very convenient and clear! As a matter of fact, laruence has used SAR as a tool for MRTG to plot charts, which is very convenient. However, this suite is not installed in Ubuntu by default,

Next we will compare the accuracy of top, SAR, and mpstat. CPU usage is displayed once per second. #! /Bin/sh <br/> # endless loop. Note the space after while <br/> while: <br/> DO <br/> sleep 1 </P> <p> # top <br/> cpu_top = $ (top-N 1 | grep "CPU" | awk' {print $5} '| awk-F' % ''{print $1 }') <br/> # SAR <br/> cpu_sar = $ (SAR-u 1 1 | awk 'nr = 4 {print $8 }') <br/> # mpstat <br/> cpu_mpstat = $ (mpstat | awk 'nr = 4 {print $11} ') <br/> echo "cpu_top: $ cpu_top "<br/> echo" cpu_sar: $ cpu_sar "<br/> echo" cpu_mpstat: $ cpu_mpstat "<br/> done <br/> 

The disadvantage of top and mpstat is that when top or mpstat is used for real-time refresh, the first display is not very accurate and I don't know why. SAR does not.Comprehensive information of three hosts1. Check the CPU information under/proc:
[Root @ test root] #More/proc/cpuinfoProcessor: 0vendor_id: Invalid family: 5 model: 4 model name: Pentium mmxstepping: 4 CPU MHz: 167.047fdiv _ BUG: Issue: nof00f_bug: yescoma_bug: nofpu: yesfpu_exception: yescpuid level: 1wp: yesflags: fpu vme de pse tsc msr mce cx8 mmxbogomips: 333.41More/proc/meminfo
2Uname
[Root @ test/root] # uname [-apnr] parameter description:-A: List all system information-P: List CPU information-N: List host name-R: example of listing core version information: [root @ test/root] # uname-a Linux test.linux.org 2.4.18 #2 mon Mar 25 21:51:51 CST 2002 i586 unknown want to know your system information, including core version, host name, CPU information, etc. You can use uname. In addition, if you are interested in your CPU, go to/proc to see: [root @ test root] # More/proc/cpuinfo processor: 0 vendor_id: genuineintel CPU family: 5 model: 4 model name: Pentium MMX stepping: 4 CPU MHz: 167.047 fdiv_bug: No hlt_bug: No f00f_bug: Yes coma_bug: No FPU: Yes fpu_exception: Yes cpuid level: 1 WP: yes flags: fpu vme de pse tsc msr mce cx8 MMX bogomips: 333.41

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.