mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-29 21:41:00 +08:00
1ee2fc7cbe
renamed: 10 Useful Chaining Operators in Linux with Practical Examples.md -> 201401/10 Useful Chaining Operators in Linux with Practical Examples.md renamed: 10 basic examples of linux netstat command.md -> 201401/10 basic examples of linux netstat command.md renamed: 12 Advanced Commands For Linux Server Admins!.md -> 201401/12 Advanced Commands For Linux Server Admins!.md renamed: 14 New Linux Distros That Were Introduced In 2013.md -> 201401/14 New Linux Distros That Were Introduced In 2013.md renamed: 15 Basic MySQL Interview Questions for Database Administrators.md -> 201401/15 Basic MySQL Interview Questions for Database Administrators.md renamed: "2013\357\274\232The Golden Year for Linux \342\200\223 10 Biggest Linux Achievements.md" -> "201401/2013\357\274\232The Golden Year for Linux \342\200\223 10 Biggest Linux Achievements.md" renamed: 2014--The year of the Linux car.md -> 201401/2014--The year of the Linux car.md renamed: 5 Things To Love And Hate About Ubuntu 13.10.md -> 201401/5 Things To Love And Hate About Ubuntu 13.10.md renamed: 8 Interesting Linux Tips And Tricks!.md -> 201401/8 Interesting Linux Tips And Tricks!.md renamed: CentOS 6.5 desktop installation guide with screenshots.md -> 201401/CentOS 6.5 desktop installation guide with screenshots.md renamed: "Command Line Basics \342\200\223 watch.md" -> "201401/Command Line Basics \342\200\223 watch.md" renamed: Configure Your Browser To Use Tor On Ubuntu or Debian or Linux Mint.md -> 201401/Configure Your Browser To Use Tor On Ubuntu or Debian or Linux Mint.md renamed: Daily Ubuntu Tips - Mount Partitions In Ubuntu From Your Desktop GUI.md -> 201401/Daily Ubuntu Tips - Mount Partitions In Ubuntu From Your Desktop GUI.md renamed: "Daily Ubuntu Tips \342\200\223 Do Nothing When Laptop Lid Is Closed.md" -> "201401/Daily Ubuntu Tips \342\200\223 Do Nothing When Laptop Lid Is Closed.md" renamed: "Daily Ubuntu Tips \342\200\224 Install VMware Workstation In Ubuntu.md" -> "201401/Daily Ubuntu Tips \342\200\224 Install VMware Workstation In Ubuntu.md" renamed: "Daily Ubuntu Tips \342\200\224 Windows Disk Management Equivalent In Ubuntu.md" -> "201401/Daily Ubuntu Tips \342\200\224 Windows Disk Management Equivalent In Ubuntu.md" renamed: "Gnu--toward the post-scarcity world \342\200\223 the Free Software Column.md" -> "201401/Gnu--toward the post-scarcity world \342\200\223 the Free Software Column.md" renamed: How to Dual Boot Ubuntu and Windows Properly.md -> 201401/How to Dual Boot Ubuntu and Windows Properly.md renamed: "How to Install and Configure UFW \342\200\223 An Un-complicated FireWall in Debian or Ubuntu.md" -> "201401/How to Install and Configure UFW \342\200\223 An Un-complicated FireWall in Debian or Ubuntu.md" renamed: How to Upgrade to GNOME 3.10 in Ubuntu 13.10.md -> 201401/How to Upgrade to GNOME 3.10 in Ubuntu 13.10.md renamed: How to install and configure Nagios on Linux.md -> 201401/How to install and configure Nagios on Linux.md renamed: How to set password policy on Linux.md -> 201401/How to set password policy on Linux.md renamed: How to stitch photos together on Linux.md -> 201401/How to stitch photos together on Linux.md renamed: How to upgrade MySQL server on Debian or Ubuntu.md -> 201401/How to upgrade MySQL server on Debian or Ubuntu.md renamed: Juju ice-cream icon design.md -> 201401/Juju ice-cream icon design.md renamed: Linus Torvalds Releases Last Linux Kernel 3.13 RC for 2013.md -> 201401/Linus Torvalds Releases Last Linux Kernel 3.13 RC for 2013.md renamed: Linus Torvalds Says All Contributor License Agreements Are Broken.md -> 201401/Linus Torvalds Says All Contributor License Agreements Are Broken.md renamed: Linux free Command - Display Free and used Memory in the System.md -> 201401/Linux free Command - Display Free and used Memory in the System.md renamed: Linux id Command - Print user ID and group ID information.md -> 201401/Linux id Command - Print user ID and group ID information.md renamed: Linux is Everywhere. We show you exactly where.md -> 201401/Linux is Everywhere. We show you exactly where.md renamed: Linux lsusb Command to Print information about USB on System.md -> 201401/Linux lsusb Command to Print information about USB on System.md renamed: Linux vmstat Command - Tool to Report Virtual Memory Statistics.md -> 201401/Linux vmstat Command - Tool to Report Virtual Memory Statistics.md renamed: "Linux who command \342\200\223 Displays who is on the system.md" -> "201401/Linux who command \342\200\223 Displays who is on the system.md" renamed: "Move Dropbox\342\200\231s Folder To An External Drive In Ubuntu.md" -> "201401/Move Dropbox\342\200\231s Folder To An External Drive In Ubuntu.md" renamed: New Ubuntu 14.04 Icons Are Drop-Dead Gorgeous, Might Not Arrive in Desktop Version.md -> 201401/New Ubuntu 14.04 Icons Are Drop-Dead Gorgeous, Might Not Arrive in Desktop Version.md renamed: Our Top 10 Linux Applications of 2013.md -> 201401/Our Top 10 Linux Applications of 2013.md renamed: Setup your personal Cloud server in minutes using ownCloud On RHEL, CentOS, Scientific Linux 6.5.md -> 201401/Setup your personal Cloud server in minutes using ownCloud On RHEL, CentOS, Scientific Linux 6.5.md renamed: Software May Be Eating The World, But Open Source Software Is Eating Itself.md -> 201401/Software May Be Eating The World, But Open Source Software Is Eating Itself.md renamed: The Debian Administrator's Handbook updated for Debian 7 Wheezy published and freely available for download.md -> 201401/The Debian Administrator's Handbook updated for Debian 7 Wheezy published and freely available for download.md renamed: The Fedora Project Will No Longer Name Its Linux Distributions.md -> 201401/The Fedora Project Will No Longer Name Its Linux Distributions.md renamed: The Genius Of Linux Is Community, Not Technology.md -> 201401/The Genius Of Linux Is Community, Not Technology.md renamed: Top 10 Linux Distros For Hackers!.md -> 201401/Top 10 Linux Distros For Hackers!.md renamed: Tunnel SSH Connections Over SSL Using 'Stunnel' On Debian 7 Ubuntu 13.10.md -> 201401/Tunnel SSH Connections Over SSL Using 'Stunnel' On Debian 7 Ubuntu 13.10.md renamed: Ubuntu Stores Your Wi-Fi Passwords By Default!.md -> 201401/Ubuntu Stores Your Wi-Fi Passwords By Default!.md renamed: Ubuntu Will Reach True Convergence Before Microsoft, Says Shuttleworth.md -> 201401/Ubuntu Will Reach True Convergence Before Microsoft, Says Shuttleworth.md renamed: Understanding Linux cd Command with Examples.md -> 201401/Understanding Linux cd Command with Examples.md renamed: look--Linux Command To Verify Spellings And Display Lines Beginning With A String.md -> 201401/look--Linux Command To Verify Spellings And Display Lines Beginning With A String.md
105 lines
5.5 KiB
Markdown
105 lines
5.5 KiB
Markdown
Linux vmstat 命令 - 报告虚拟内存统计的工具
|
||
================================================================================
|
||
众所周知,计算机必须有称之为RAM(随机访问内存)的存储器使得计算机工作。RAM指的是插在计算机主板上的物理存储。这里的RAM被用于加载像浏览器、文字处理器这类的程序,实际上,你使用的程序都运行在内存上。
|
||
|
||
让我们假设你有2GB的内存。当你在运行操作系统时,你的可用内存可能只有1.5GB。接着你使用了大量的程序。当内存使用满之后,你可能再也无法加载更多的程序。浅显地说,计算机可能会说:"抱歉,你不能在运行更多的程序了,如果你还要运行其他的程序请先关闭一些程序。"
|
||
|
||
为了解决这个问题,包括Linux在内的各种操作系统使用了一个称之为虚拟内存的方法。这个方法会搜索最近不在使用的程序的内存区域,接着将它们拷贝到计算机硬盘上。这会腾出一些剩余内存空间给你有机会运行更多的程序。
|
||
|
||
为了监视虚拟内存的活动,我们使用**vmstat**工具。
|
||
|
||
### 什么是 vmstat ###
|
||
|
||
vmstat是一个提供报告虚拟内存统计的工具。它包括了系统内存、交换和实时处理器利用率。
|
||
|
||
### 如何运行 vmstat ###
|
||
|
||
和[mpstat][1]一样,vmstat包含在sysstat包中。如果你还没有,请安装sysstat包。
|
||
|
||
为了运行vmstat,只需在控制台输入vmstat。不带参数运行vmstat会显示vmstat的默认结果。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_default.png)
|
||
|
||
让我们看下如何了解vmstat提供的信息:
|
||
|
||
#### Procs ####
|
||
|
||
procs有 **r**列和**b**列。**r**列代表等待访问CPU进程的数量。而b列意味着睡眠进程的数量。在这些列的下面,是它们的值。从上面的截图中,我门有2个进程正在等待访问CPU,0个睡眠进程。
|
||
|
||
#### Memory ####
|
||
|
||
memory有**swpd、 free、 buff** 和 **cache** 这些列。这些信息和命令**free -m**相同。**swpd列**显示了有多少内存已经被交换到了交换文件或者磁盘。**free列**显示了未分配的可用内存。**buff列**显示了使用中的内存。**cache列**显示了有多少内存可以被交换到交换文件或者磁盘上如果一些应用需要他们。
|
||
|
||
#### Swap ####
|
||
|
||
swap显示了从交换系统上发送或取回了多少内存。**si**列告诉我们每秒有多少内存被**从swap移到真实内存**中(In)。**so**列告诉我们每秒有多少内存被**从真实内存移到swap**中(Out)。
|
||
|
||
#### I/O ####
|
||
|
||
**io**依据块的读写显示了每秒输入输出的活动。**bi**列告诉我们收到的块数量,**bo**列告诉我们发送的块数量。
|
||
|
||
#### System ####
|
||
|
||
system显示了每秒的系统操作数量。**in**列显示了系统每秒被中断的数量。**cs**列显示了系统为了处理所以任务而上下文切换的数量。
|
||
|
||
#### CPU ####
|
||
|
||
CPU告诉了我们CPU资源的使用情况。**us列**显示了处理器在非内核程序消耗的时间。**sy列**显示了处理器在内核相关任务上消耗的时间。**id列**显示了处理器的空闲时间。**wa列**显示了处理器在等待IO操作完成以继续处理任务上的时间。
|
||
|
||
### 按间隔时间运行vmstat ###
|
||
|
||
作为一个统计工具,使用vmstat最好的方法是使用**间隔时间**。你可以间断地捕捉系统状态。让我假设以5秒的间隔运行vmstat。只需要在你的控制台中输入**vmstat 5**就行。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_delay_5.png)
|
||
|
||
命令将会每5秒运行一次,**直到**你按下Ctrl-C来终止它。你也可以使用第二个参数来控制vmstat运行的次数。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_count_7.png)
|
||
|
||
上面的命令会**以5秒的间隔运行7次vmstat**。
|
||
|
||
### 显示活跃和非活跃内存 ###
|
||
|
||
要这么做,你可以在vmstat后加入**-a**选项。这是个示例。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_a.png)
|
||
|
||
### 显示磁盘统计数据总结 ###
|
||
|
||
如果你想,vmstat也可以打印系统磁盘活动统计。使用**-D**选项就行。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_disk_sum.png)
|
||
|
||
### 显示单位 ###
|
||
|
||
你可以选择你想打印的显示单位字符。在**-S后跟上k (小写,1000)、 K (大写,1024)、 m (小写,1000000)、 M (大写,1048576)** 字节. 如果你不想选择单位,默认使用的是K (1024)。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_define_unit.png)
|
||
|
||
### 显示某个磁盘分区的详细统计数据 ###
|
||
|
||
要这么做,你可以使用**-p选项跟上设备名**。这里有个例子。
|
||
|
||
![](http://linoxide.com/wp-content/uploads/2013/12/vmstat_partition.png)
|
||
|
||
### 文件 ###
|
||
|
||
vmstat实际上是使用这些文件获取的数据。
|
||
|
||
/proc/meminfo
|
||
/proc/stat
|
||
/proc/*/stat
|
||
|
||
### 总结 ###
|
||
|
||
如果你感觉系统运行超出内存了,在你增加物理内存前,这个工具可以帮助你确定问题的根本原因。通常上,你可以在控制台中输入**man vmstat**获取更多的关于vmstat的详细信息,这会为你显示vmstat的手册页。
|
||
|
||
--------------------------------------------------------------------------------
|
||
|
||
via: http://linoxide.com/linux-command/linux-vmstat-command-tool-report-virtual-memory-statistics/
|
||
|
||
译者:[geekpi](https://github.com/geekpi) 校对:[wxy](https://github.com/wxy)
|
||
|
||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||
|
||
[1]:http://linoxide.com/linux-command/linux-mpstat-command/ |