TranslateProject/sources/talk/20150709 7 command line tools for monitoring your Linux system.md
2015-07-15 18:08:18 +08:00

6.3 KiB
Raw Blame History

监控你的Linux系统的7个命令行工具

这里有一些基本的命令行工具让你能更简单地探索和操作Linux。

Image courtesy Meltys-stock

深入

关于Linux最棒的一件事之一是你能深入操作系统多深来探索它是如何工作的并寻找机会来微调性能或诊断问题。这里有一些基本的命令行工具让你能更简单地探索和操作Linux。大多数的这些命令是在你的Linux系统中已经内建的但假设它们不是就用谷歌搜索命令名和你的发行版名吧你会找到哪些包需要安装(注意,一些命令是和其它命令捆绑起来打成一个包的,你所找的包可能写的是其它的名字)。如果你知道一些你所使用的其它工具,欢迎评论。

Image courtesy Mark Gibbs

How we did it

FYI: 本文中的截图取自Debian Linux 8.1 (“Jessie”),其运行在OS X 10.10.3 (“Yosemite”)操作系统下Oracle VirtualBox 4.3.28中的一台虚拟机里。想要建立你的Debian虚拟机可以看看我的这篇教程——“How to install Debian Linux in a VirtualBox VM”。

Image courtesy Mark Gibbs

Top命令

作为Linux系统监控工具中比较易用的一个top命令能带我们一览Linux中的几乎每一处。以下这张图是它的默认界面但是按“z”键可以切换不同的显示颜色。其它热键和命令则有其它的功能例如显示概要信息和内存信息(第四行第二个),根据各种不一样的条件排序、终止进程任务等等(你可以在这里找到完整的列表)。

Image courtesy Mark Gibbs

htop

相比top它的替代品Htop则更为精致。维基百科是这样描述的“Users often deploy htop in cases where Unix top does not provide enough information about the systems processes, for example when trying to find minor memory leaks in applications. Htop is also popularly used interactively as a system monitor. Compared to top, it provides a more convenient, cursor-controlled interface for sending signals to processes.” (For more detail go here.)

Image courtesy Mark Gibbs

Vmstat

Vmstat is a simpler tool for monitoring your Linux system performance statistics but that makes it highly suitable for use in shell scripts. Fire up your regex-fu and you can do some amazing things with vmstat and cron jobs. “The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case” (go here for more info.).

Image courtesy Mark Gibbs

ps

The ps command shows a list of running processes. In this case, Ive used the “-e”switch to show everything, that is, all processes running (Ive scrolled back to the top of the output otherwise the column names wouldnt be visible). This command has a lot of switches that allow you to format the output as needed. Add a little of the aforementioned regex-fu and youve got a powerful tool. Go here for the full details.

Image courtesy Mark Gibbs

Pstree

Pstree “shows running processes as a tree. The tree is rooted at either pid or init if pid is omitted. If a user name is specified, all process trees rooted at processes owned by that user are shown.”This is a really useful tool as the tree helps you sort out which process is dependent on which process (go here).

Image courtesy Mark Gibbs

pmap

Understanding just how an app uses memory is often crucial in debugging, and the pmap produces just such information when given a process ID (PID). The screenshot shows the medium weight output generated by using the “-x”switch. You can get pmap to produce even more detailed information using the “-X”switch but youll need a much wider terminal window.

Image courtesy Mark Gibbs

iostat

A crucial factor in your Linux systems performance is processor and storage usage, which are what the iostat command reports on. As with the ps command, iostat has loads of switches that allow you to select the output format you need as well as sample performance over a time period and then repeat that sampling a number of times before reporting. See here.


via: http://www.networkworld.com/article/2937219/linux/7-command-line-tools-for-monitoring-your-linux-system.html

作者:Mark Gibbs 译者:译者ID 校对:校对者ID

本文由 LCTT 原创翻译,Linux中国 荣誉推出