uptime命令
通过uptime可以了解到系统的负载情况,在命令行中输入uptime时,会输出以下信息:
root@iZ2ze6fssrhq5nqms7h4amZ:~# uptime
16:50:59 up 43 days, 20:22, 1 user, load average: 0.11, 0.04, 0.01
其中
- 16:50:59为当前时间
- up 43 days,20:22为系统运行了43天20小时22秒
- 1 user为当前共有一个用户登录
- load average为过去1分钟、5分钟、15分钟的平均负载
如何理解平均负载
Linux的正统解释(man uptime)
现在只着重看一下uptime命令中关于平均负载的解释
System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.
平均负载是三个时间间隔内处于可运行或不可中断状态进程的平均数。
- 处于可运行状态的进程正在使用CPU或等待使用CPU。
- 处于不可中断状态的进程正在等待某些I/O访问(如等待磁盘)。
负载平均值不是系统中CPU数量的标准化值。当负载平均值为1时,在单个CPU上表示系统一直处于负载状态,而在4 CPU系统上则表示75%的时间处于空闲状态。因此可以推断CPU的空闲状态可以表示为(N - M)/ N,其中N为CPU数量,M为平均负载值。
举个例子,当平均负载为2时,在不同CPU个数情况下有不同的含义:
- 在2 个 CPU 的系统上,意味着所有的 CPU 都刚好被完全占用。
- 在4 个 CPU 的系统上,意味着 CPU 有 50% 的空闲。
- 在1 个 CPU 的系统中,意味着有一半的进程竞争不到 CPU。