Linux View machine configuration, and cpu/memory/hard disk usage

Source: Internet
Author: User
Tags disk usage dmesg

How to view machine configuration under Linux? cpu/Memory/HDD

Dmesg
Displays the boot information. The kernel will store the boot information in the ring buffer. If you are too late to view the information, you can use DMESG to view it. The boot information is also saved in the/var/log directory, in a file named DMESG

Dmesg|grep HD
Hard disk
Dmesg|grep CPU
Cpu
DMESG|GREP proc
Memory
Dmesg|grep Redhat
Operating system
Dmesg|more
More information
Uname-a
Operating system version


View Linux CPU and memory utilization
2008-07-17 18:04

During system maintenance, it may be necessary to review the CPU usage at any time, and to analyze the system condition according to the corresponding information. In CentOS, you can view CPU usage by using the top command. After running the top command, the CPU usage status is displayed in full-screen mode, and will be in the dialog-using top-based commands, you can control how the display is displayed, and so on. The command to exit Top is Q (the Q key is struck once in the top run).

Operation Example:

Enter "Top" on the command line

You can start the top

Top Full Screen Dialog mode can be divided into 3 parts: System Information Bar, command input field, process list bar.

The first part-the top System Information Bar:

First line (top):

"00:11:04" is the current time of the system;

"3:35" is the operating time of the system after it has been started;

"2 Users" is the user who is currently logged on to the system, more specifically the number of terminals logged on to the user-the same user at the same time to the system of multiple terminal connections will be treated as multiple users connected to the system, here the number of users will also be displayed as the number of terminals;

"Load average" is the average of the current system load, the following three values are 1 minutes ago, 5 minutes ago, 15 minutes ago The average process, the general can be thought that this value exceeds the number of CPUs, the CPU will be more strenuous load the current system contains the process;

Second line (Tasks):

"Total" is the current number of system processes;

"1 Running" is the number of processes currently in operation;

"Sleeping" is the number of processes currently in the waiting state;

"0 stoped" for the number of system processes stopped;

"0 Zombie" for the number of processes restored;

Third line (Cpus):

The current utilization rate of CPU is indicated respectively;

Line Four (MEM):

Indicates the total amount of memory, current usage, idle memory, and amount of RAM in buffer usage;

Line Five (Swap):

Represents the category with the fourth line (MEM), but here reflects the use of the Swap partition (swap). Typically, swap partitions (swap) are frequently used, and will be seen as a result of insufficient physical memory.

The second part--the inner command prompt bar of the middle part:

In the top run, you can control how processes are displayed through the internal commands of top. The internal command is the following table:

S

-Change the screen update frequency

L-Turn off or turn on the representation of the first line top information in the first section

T-turn off or turn on the second line of the first section Cpus information representation of the Tasks and the third row

M-Turn off or turn on the first part of the four-line Mem and fifth line Swap information representation

N-the list of processes in the order of the PID size (the third part is described later)

P-List of processes in the Order of CPU Utilization (third part)

M-Arrange the list of processes in the Order of Memory occupancy (Part III)

H-Show help

N-Set the number of processes displayed in the process list

Q-Exit Top

S-

Change the screen update cycle

Part Three-the bottom part of the Process list bar:

A list of processes that are separated by PID will be updated periodically based on the Set screen update time. The top internal command lets you control how it is displayed here

View memory under Linux We generally use the free command:
[[email protected] tmp]# free
Total used free shared buffers Cached
mem:3266180 3250004 16176 0 110652 2668236
-/+ buffers/cache:471116 2795064
swap:2048276 80160 1968116

Here is an explanation of these values:
Total: The amount of physical memory.
Used: How large is used.
Free: How much is available.
Shared: The total amount of memory shared by multiple processes.
Buffers/cached: The size of the disk cache.
Third line (-/+ buffers/cached):
Used: How large is used.
Free: How much is available.
There is not much to explain in line four.
Difference: The used/free of the second line (MEM) differs from the third row (-/+ Buffers/cache) used/free. The difference between the two is that the first line is from the OS point of view, because for the os,buffers/cached are all belong to be used, so his available memory is 16176KB, the used memory is 3250004KB, which includes, the kernel (OS) uses + Application (X, ORACLE,ETC) uses the +buffers+cached.
The third line refers to the application from the point of view, buffers/cached is equal to the availability of the application, because buffer/cached is to improve the performance of the file read, when the application needs to use memory, buffer/cached will be quickly recycled.
So from the application's point of view, available memory = System Free memory+buffers+cached.
As in the above example:
2795064=16176+110652+2668236

Next, explain when the memory will be exchanged, and by what side. When the available memory is less than the rated value, a meeting is exchanged.
How to see the rating:
Cat/proc/meminfo

[Email protected] tmp]# Cat/proc/meminfo
memtotal:3266180 KB
memfree:17456 KB
buffers:111328 KB
cached:2664024 KB
swapcached:0 KB
active:467236 KB
inactive:2644928 KB
hightotal:0 KB
highfree:0 KB
lowtotal:3266180 KB
lowfree:17456 KB
swaptotal:2048276 KB
swapfree:1968116 KB
Dirty:8 KB
writeback:0 KB
mapped:345360 KB
slab:112344 KB
committed_as:535292 KB
pagetables:2340 KB
vmalloctotal:536870911 KB
vmallocused:272696 KB
vmallocchunk:536598175 KB
hugepages_total:0
hugepages_free:0
hugepagesize:2048 KB

Results viewed with free-m:
[Email protected] tmp]# free-m
Total used free shared buffers Cached
mem:3189 3173 16 0 107 2605
-/+ buffers/cache:460 2729
swap:2000 78 1921


To view the size of the/proc/kcore file (memory image):
[Email protected] tmp]# ll-h/proc/kcore
-R--------1 root root 4.1G June 12:04/proc/kcore

Note:

Memory-intensive measurements

To measure how much memory a process consumes, Linux provides a convenient way for us to provide all the information we have in the/proc directory, and in fact the top tools are also available here to obtain the appropriate information.

Memory usage information for/proc/meminfo machines

The/proc/pid/maps PID is the process number that displays the virtual address occupied by the current process.

Memory occupied by the/PROC/PID/STATM process

[Email protected] ~]# CAT/PROC/SELF/STATM

654 57 44 0 0 334 0

Output interpretation

CPU and CPU0 ... The meaning of each parameter of each row (in the first example) is:

Parameter Interpretation/proc//status

Size (pages) task virtual address space VMSIZE/4

Resident (pages) the size of the physical memory that the application is using VMRSS/4

Shared (pages) pages 0

The size of the executable virtual memory owned by the TRS (pages) program VMEXE/4

The size of the library in which Lrs (pages) is imaged into the virtual memory space of the task VMLIB/4

Drs (pages) program data segment and user-state stack size (vmdata+ VMSTK) 4

DT (pages) 04

View Machine available memory

/proc/28248/>free

Total used free shared buffers Cached

mem:1023788 926400 97388 0 134668 503688

-/+ buffers/cache:288044 735744

swap:1959920 89608 1870312

When we look at the idle memory of the machine with the free command, we find that the value of the. This is mainly because, in Linux there is such a thought, the memory is not white, so it as far as possible cache and buffer some data to facilitate the next use. But in fact, the memory is also available for immediate use.

So free memory =free+buffers+cached=total-used




How to get CPU utilization under Linux
2009-04-07 18:20
The proc file system is a pseudo-file system that only exists in memory and does not occupy external memory space. It provides an interface for accessing system kernel data in a file system manner. Users and applications can get system information through proc, and can change certain parameters of the kernel. "

Here's how to get some of the firewall-related performance parameters from the/proc file system, and how to modify the kernel configuration with the/proc file system.

1. Get related performance parameters from/proc file system
CPU Usage:/proc/stat
Memory Usage:/proc/meminfo
Network Load Information:/proc/net/dev

The corresponding calculation method: (Excerpt from: What is the proc file system, see Resources)
(1) Processor utilization
(2) Memory usage
(3) Incoming and outgoing packets
(4) Overall Network load
These data are extracted from/proc/stat,/proc/net/dev,/proc/meminfo three files, respectively. If you have problems or are not sure about the data you want to extract, you can use the man proc to view the online manuals for the proc file system.
(1) Processor utilization
This is to extract four data from the/proc/stat: User-mode, low-priority user-mode (NICE), kernel-mode (System), and idle processor Time (idle). They are all located on the first line of the/proc/stat file. CPU utilization is calculated using the following formula.
CPU utilization = * (user + nice + system)/(user + nice + system + idle)
(2) Memory usage
Here you need to extract two data from the/proc/meminfo file, the current memory usage (CMEM), and the total amount of memory (AMEM).
Memory Usage percentage = * (CMEM/UMEM)
(3) Network utilization
In order to get the data of network utilization, we need to get two data from the/proc/net/dev file: The number of packets that are output from the native computer and the number of packets flowing into this machine. They are all located on line Fourth of this file.
The performance collector starts recording the initial values for both data, and subtracting the initial value after each subsequent acquisition is the packet that is passed from this node starting at the start of the cluster.
Using the above data to calculate the average load of the network, the method is as follows:
Average Network Load = (output packet + incoming packet)/2

2. Adjust the relevant kernel configuration via the/proc file system
Allow IP Forwarding/proc/sys/net/ipv4/ip_forward
Prohibit Ping/proc/sys/net/ipv4/icmp_echo_ignore_all

You can write "1" to the above two "files" directly under the command line to implement the relevant configuration, if writing "0" will cancel the related configuration. However, after the system restarts, these configurations will revert to the default settings, so if you want these changes to take effect, you can write the following configuration directly to the/etc/profile file, or to other program files that are executed with the system boot.

Echo 1 >/proc/sys/net/ipv4/ip_forward
Echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

If you need to obtain additional performance parameters, or need more configuration of the kernel, you can refer to the proc file system described in the link below, or you can view the relevant information directly through the man Proc.

References and RELATED LINKS

[1] What is the proc file system
Http://blog.chinaunix.net/u1/37836/showart_304248.html
[2] How to get CPU usage under Linux
Http://topic.csdn.net/t/20060701/23/4855045.html
[3] Exploring The/proc/net/directory
Http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html?page=1
[4]/proc/net Introduction
Http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/en-US/Reference_Guide/s2-proc-dir-net.html
[5] using Ulimit and proc to adjust system parameters
Http://www.linuxfly.org/post/73.htm

Note: The file is an increment, each time interval corresponding to the use of the CPU will be increased, to calculate the percentage, the last state value.

There is a problem calculating CPU usage here, which needs to be calculated using the value of the previous state.
Return
Elf published in 2007-11-16 09:06 #4

The correct calculation method is, wait for the previous time:

1. Record CPU usage at some point
2, wait for the last time period
3, and then record the CPU usage at the moment
4, calculate the total time slice
Sum up all CPU usage for the first time, get J1
Sum up all CPU usage for the second time, get J2
J2-j1 get all the time slices for this time period
That is, the total=j2-j1= of all columns of the second time and-all columns of the first
5. Calculate Idle Time
Idle corresponds to the fifth column of data, minus the first time with the second
idle= second fifth Column-fifth column of the first time
6. Calculate CPU Usage
Rate= (Total-idle)/total
See: http://oss.lzu.edu.cn/blog/article.php?tid_1379.html



When we are doing performance testing, monitoring the CPU utilization of the backend servers is a common tool. The high CPU utilization of the server indicates that the server is busy. If the front-office response time is increasing, the CPU utilization of the latter is always on, indicating that there is a bottleneck in some place, the system needs tuning. This is something that is easy for people to understand even if they don't know the technology.

It's understood, right? Personally, I don't think it's very accurate. This depends on what type of process you are testing in the background. If it is a computationally intensive process and the current pressure is getting larger, it is easy to get CPU utilization up. But if it is an I/o network intensive process, even if the client requests more and more, but the server CPU does not have to go up, this is the natural attribute of the process you are testing.

What is CPU utilization? Under Linux/unix, CPU utilization is divided into user state, System State and idle state, which indicate the time the CPU is in user state execution, the time of system kernel execution, and the time of idle system process execution. From the computer power on, the CPU has been busy all the time, so the CPU utilization is always 100%. When no user process needs to be executed, the CPU executes the system default idle process. The CPU utilization we refer to is the total time/CPU execution time of the CPU executing the non-system idle process.

In the kernel of Linux, there is a global variable: Jiffies. Jiffies represents time. Its units vary depending on the hardware platform. A constant Hz is defined in the system, representing the number of minimum time intervals per second. So the jiffies unit is 1/hz. The Intel platform Jiffies Unit is 1/100 seconds, which is the minimum time interval the system can distinguish. Each CPU time slice, jiffies must add 1. The CPU utilization is expressed by dividing the jiffies of the execution user state + the system state by the total jifffies.

In the Linux system, the CPU utilization is calculated from the/proc/stat file, the first few lines of this file record the user state of each CPU, System state, idle state of the different jiffies, common monitoring software is the use of/proc/ This data in stat calculates the CPU utilization.
Contains information about all CPU activity, and all values in the file are accumulated from the start of the system to the current moment.
/proc/stat/
[Email protected] ~]$ Cat/proc/stat
CPU 432661 13295 86656 422145968 171474 233 5346
Cpu0 123075 2462 23494 105543694 16586 0 4615
CPU1 111917 4124 23858 105503820 69697 123 371
CPU2 103164 3554 21530 105521167 64032 106 334
Cpu3 94504 3153 17772 105577285 21158 4 24
Intr 1065711094 1057275779 92 0 6 6 0 4 0 3527 0 0 0 70 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7376958 0 0 0 0 0 0 0 0 0 0 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Ctxt 19067887
Btime 1139187531
Processes 270014
Procs_running 1
procs_blocked 0


Output interpretation
Each parameter of the CPU and CPU0, CPU1, CPU2, CPU3 per line (in the first example) is:
Parameter interpretation
User (432661) accumulates from the start of the system to the current time, the CPU time (in jiffies), which does not include the nice value as a negative process. 1jiffies=0.01 sec
Nice (13295) accumulate from the start of the system to the current moment, the CPU time occupied by a process with a negative Nice value (unit: jiffies)
System (86656) accumulates at the current moment from the start of the boot, Core time (unit: jiffies)
Idle (422145968) accumulate from the start of the system to the current time, in addition to the hard disk IO wait time other than the Wait time (unit: jiffies)
Iowait (171474) accumulated from the start of the system to the current time, hard disk IO wait time (in jiffies),
IRQ (233) accumulates from the start of the system to the current moment, hard Interrupt time (unit: jiffies)
SOFTIRQ (5346) accumulated from the start of the system to the current moment, soft interrupt time (unit: jiffies)

CPU Time =USER+SYSTEM+NICE+IDLE+IOWAIT+IRQ+SOFTIRQ

The "Intr" line gives the interrupt information, the first is the number of interrupts that have occurred since the system started, and then each number corresponds to the number of times that a particular interrupt has occurred since the system started.
"Ctxt" gives the number of context exchanges that have occurred since the system started.
"Btime" gives the time, in seconds, from the start of the system to the present.
Processes (Total_forks) The number of tasks created since the system started.
"Procs_running": the number of tasks currently running the queue.
"Procs_blocked": the number of tasks that are currently blocked.
Then the CPU utilization calculation method: can use to take two sampling points, calculate its difference value.
(Idle2-idle1)/cpu2-cpu1

Linux View machine configuration, and cpu/memory/hard disk usage

Related Article

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.