The Linux Enterprise Application-Linux server application information, a parameter running in the current system, is described below. 1. CPU
The file "/proc/stat" contains CPU information. Every CPU tick is used in this file. The following numbers indicate user, nice, sys, idle, and iowait. Some versions of kernel do not include iowait. These values indicate where each tick of the CPU is used from the boot to the present. For example:
Cpu0 256279030 0 11832528 1637168262
That is, 256279030 tick is used for user consumption since CPU 0 is started, and 11832528 is used for sys consumption. Therefore, if you want to calculate the CPU load per unit time (for example, 1 s), you only need to calculate the difference between the values before and after 1 second in addition to the number of tick per second. Gkrellm is implemented in this way: (200 * (v2-v1)/CPU_TICKS_PER_SECOND) + 1)/2
For example, if you read/proc/stat for the first time, the value of the user is 256279030; if you read it again after one second, the value is 256289030, the CPU user consumption in this second is: (200 * (256289030-256279030)/CPU_TICKS_PER_SECOND) + 1)/2 = (10000*200/1000000) + 1) /2 = 1%.
2. memory consumption
The file "/proc/meminfo" contains the memory information and swap information. For example:
$ Cat/proc/meminfo
Total: used: free: shared: buffers: cached:
Mem: 1057009664 851668992 205340672 0 67616768 367820800
Swap: 2146787328 164429824 1982357504
MemTotal: 1032236 kB
MemFree: 200528 kB
MemShared: 0 kB
......
However, from the source code of gkrellm, some versions do not have the statistics of the previous two rows, but can only collect data based on the following types of Key: Value.
3. Disk Space
From the source code of gkrellm, this is a very complex data. Disk partition data may be distributed in:/proc/mounts,/proc/diskstats,/proc/partitions, and so on. In addition, if you want to check a specific path, you also need the help of commands such as mount and df. To reduce the trouble, I can directly use the statfs function to obtain this data.
Int statfs (const char * path, struct statfs * buf );
This function only needs to enter the path name to be checked to return the space usage of the partition where the path is located:
Total Space: buf. f_bsize * buf. f_blocks
Free Space: buf. f_bsize * buf. f_bavail
4. Disk I/O
Disk I/O data is also complex. For some versions, see/proc/diskstats, for some versions, see/proc/partitions, and for some versions, I still don't know where to view them ...... However, we can see that the data version is also the same as the CPU, which requires a value every other time. The difference between the two values is the traffic.
5. Network Traffic
Network traffic is also varied, but it can basically be obtained in/proc/net/dev. It also requires two values to take the difference as the traffic value.
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