The proc file system is a special file system, which only exists in the memory and does not occupy the external storage space. It provides interfaces for accessing system kernel data in the form of a file system. Users and applications can obtain system information through proc and change certain kernel parameters. "
1. Obtain relevant performance parameters from the/proc file system
CPU usage:/proc/STAT
Memory usage:/proc/meminfo
Network load information:/proc/NET/dev
Calculation method: (from: proc file system, see references)
(1) processor usage
(2) memory usage
(3) inbound and outbound data packets
(4) overall network load
These data must be extracted from the/proc/STAT,/proc/NET/dev, And/proc/meminfo files respectively. If you have any problems or are not clear about the data to be extracted, you can use man proc to view the online manual of the proc file system.
(1) processor usage
Here, we need to extract four pieces of data from/proc/STAT: user mode, nice mode, and system mode) and idle processor time (idle ). They are located in the first line of the/proc/STAT file. The CPU usage is calculated using the following formula.
CPU usage = 100 * (User + nice + System)/(User + nice + system + idle)
(2) memory usage
Here we need to extract two data from the/proc/meminfo file, the current memory usage (cmem) and the total memory (amem ).
Memory usage percentage = 100 * (cmem/umem)
(3) Network Utilization
To obtain data about network utilization, You need to obtain two pieces of data from the/proc/NET/dev file: the number of data packets output from the local machine and the number of data packets flowing into the local machine. Both are located in the fourth row of the file.
The performance collection program starts to record the initial values of the two data values. After each value is obtained, the initial value is subtracted from the data packets passed through the current node starting from the cluster.
Calculate the average network load by using the above data:
Average network load = (output packet + incoming packet)/2
CAT/proc/loadavg command
# Cat/proc/loadavg
1.54 1.03 0.94 1/285 28156
The returned data is as follows:
Lavg_1:Average load per minute
Lavg_5:5-minute average load
Lavg_15: average load within 15 minutes
Nr_running:The number of tasks running the queue at the sampling time, which is the same as the procs_running of/proc/STAT.
Nr_threads:Number of active tasks in the system at the sampling time (excluding completed tasks)
Last_pid:The maximum PID value, including lightweight processes, that is, threads.
CAT/proc/STAT command
# Cat/proc/loadavg
CPU 119560393 366 75934979 491196419 22949796 273570 0
Cpu0 24181069 1 18320054 132965211 2407486 3 18623 0
Cpu1 27984558 11 21594016 126044599 2248274 0 20895 0
Cpu2 27843845 349 21307705 116391192 12214581 35726 98960 0
Cpu3 39550920 3 14713203 115795416 6079453 237839 1515332 0
Intr 2741402899 1779118189 2 0 0 2 0 3 0 1 1 0 0
Ctxt 1, 7985896352
(Btime 1217386758)
Processes 1161591
Procs_running 1
Procs_blocked 0
The returned data has the following meanings:
The first five rows are CPU time = user + system + nice + idle + iowait + IRQ + softirq (For details, refer to the remarks provided later)
The "intr" line shows the number of interruptions. The first line is the number of all interruptions that have occurred since the system was started; then each number corresponds to the number of times a specific interruption has occurred since the system was started.
"Ctxt" indicates the number of times the CPU context has been exchanged since the system was started.
"Btime" indicates the time (in seconds) that has elapsed since the system was started.
The number of tasks created since the system started "processes (total_forks.
"Procs_running": number of tasks in the current queue.
"Procs_blocked": Number of blocked tasks.
Remarks
User + system + nice + idle + iowait + IRQ + softirq:
The CPU time of the user State (unit: jiffies) is accumulated from the start of the system to the current time. The nice value is not included in the process. 1 jiffies = 0.01 seconds
The CPU time (unit: jiffies) occupied by a nice process whose nice value is negative from the time the system starts to the current time)
System accumulates from system startup to current time, core time (unit: jiffies)
Idle accumulates from system startup to current time, except hard disk Io wait time (unit: jiffies)
Iowait accumulates from system startup to current time, hard disk Io wait time (unit: jiffies)
IRQ accumulates from the system startup to the current time, and the hard interruption time (unit: jiffies)
Softirq accumulates from the system startup to the current time. Soft Interrupt time (unit: jiffies)