Chinaunix首页 | 论坛 | 博客
  • 博客访问: 563470
  • 博文数量: 199
  • 博客积分: 5087
  • 博客等级: 大校
  • 技术积分: 2165
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-26 21:53
文章存档

2010年(199)

我的朋友

分类: LINUX

2010-06-28 12:50:47



系统管理员(SA)有一项非常棘手的工作:处理用户账户,安全,修补,更新,升级,磁盘空间,性能以及其他被交代的各种杂项任务。对一些SA来说,简直是永无宁日。为了帮助那些SA更好的征服Linux系统,我在这里列举了12款原生的Linux系统监控工具,这些都是我最常用的。
任何用户都可以使用这些命令,如果它们存在且没有被SA限制保护的话。它们都是无害的只读命令。唯一的问题是,普通用户会向SA提交性能问题,并且还是在SA发现之前,这令那些本就超负荷工作的系统管理员们倍受刺激。
1. top
它是一款诊断工具,同时也是一款实时监控工具。执行这条命令可以查看系统中的系统资源消耗情况。可以自己试着在命令提示符处输入top并回车。点击q键退出。
top - 14:55:04 up 3 days, 20:49, 2 users, load average: 0.07, 0.05, 0.06
Tasks: 124 total, 1 running, 123 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.8%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 2832420k total, 2578360k used, 254060k free, 277288k buffers
Swap: 1540088k total, 0k used, 1540088k free, 1914544k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
17686 root 5 -10 690m 549m 535m S 2 19.9 16:31.18 vmware-vmx
21487 khess 15 0 12584 1060 788 R 0 0.0 0:00.07 top
1 root 18 0 10316 684 568 S 0 0.0 0:01.54 init
2 root RT 0 0 0 0 S 0 0.0 0:00.18 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.01 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/0
5 root RT 0 0 0 0 S 0 0.0 0:00.18 migration/1
6 root 34 19 0 0 0 S 0 0.0 0:30.78 ksoftirqd/1
7 root RT 0 0 0 0 S 0 0.0 0:00.00 watchdog/1
8 root 10 -5 0 0 0 S 0 0.0 0:00.00 events/0
9 root 10 -5 0 0 0 S 0 0.0 0:00.07 events/1
10 root 10 -5 0 0 0 S 0 0.0 0:00.00 khelper
33 root 10 -5 0 0 0 S 0 0.0 0:00.00 kthread
38 root 10 -5 0 0 0 S 0 0.0 0:00.00 kblockd/0
2. uptime
uptime命令非常简单。它会为您展示一个系统性能快照以及自上次重启以来的系统运行时间。在提示符处输入uptime即可查看您的uptime状态。下面是一个uptime的例子:
14:57:56 up 3 days, 20:52, 2 users, load average: 0.04, 0.04, 0.05
3. vmstat(Virtual Memory Statistics)
vmstat(虚拟内存统计)命令对虚拟化没什么用,但是它却从swap空间角度对您的系统健康起作用。通常,用户执行vmstat命令后会显示:
$ vmstat 5 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 253564 277376 1914556 0 0 3 12 23 11 0 0 99 0 0
0 0 0 253564 277380 1914556 0 0 0 23 1064 832 0 0 100 0 0
0 0 0 253564 277380 1914556 0 0 0 205 1114 884 0 0 99 0 0
1 0 0 253440 277380 1914556 0 0 0 7 1060 811 0 0 100 0 0
0 0 0 253812 277380 1914560 0 0 0 16 1089 903 38 3 59 0 0
来自vmstat的man页面:
vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.
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.
4. free
Free显示系统中的空闲物理内存(RAM)大小,已使用物理内存,空闲和已使用的swap内存以及内核占用的缓冲区。
$ free
total used free shared buffers cached
Mem: 2832420 2578732 253688 0 277416 1914556
-/+ buffers/cache: 386760 2445660
Swap: 1540088 0 1540088
5. ps
ps命令可以为您展示当前正在运行的进程的快照。 另外还有很多其他的可用选项参数,最常用的是ps -ef(以全格式查看所有进程)。任何用户都可以使用ps命令。
以下是一个局部的ps列表:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Apr24 ? 00:00:01 init [3]
root 2 1 0 Apr24 ? 00:00:00 [migration/0]
root 3 1 0 Apr24 ? 00:00:00 [ksoftirqd/0]
root 4 1 0 Apr24 ? 00:00:00 [watchdog/0]
root 5 1 0 Apr24 ? 00:00:00 [migration/1]
root 6 1 0 Apr24 ? 00:00:30 [ksoftirqd/1]
root 7 1 0 Apr24 ? 00:00:00 [watchdog/1]
root 8 1 0 Apr24 ? 00:00:00 [events/0]
root 9 1 0 Apr24 ? 00:00:00 [events/1]
root 10 1 0 Apr24 ? 00:00:00 [khelper]
root 33 1 0 Apr24 ? 00:00:00 [kthread]
root 38 33 0 Apr24 ? 00:00:00 [kblockd/0]
root 39 33 0 Apr24 ? 00:00:00 [kblockd/1]
root 40 33 0 Apr24 ? 00:00:00 [kacpid]
root 180 33 0 Apr24 ? 00:00:00 [cqueue/0]
root 181 33 0 Apr24 ? 00:00:00 [cqueue/1]
root 184 33 0 Apr24 ? 00:00:00 [khubd]
6. iostat
iostat用于报告CPU,磁盘和分区(I/O)统计。iostat有多种参数可用于具体输出。它是sysstat软件包的一部分。
以下是CPU iostat的一个例子:
$ iostat -c
Linux 2.6.18-53.el5 (system.domain.com) 04/28/2010
avg-cpu: %user %nice %system %iowait %steal %idle
0.18 0.00 0.43 0.11 0.00 99.28
7. w(what)
w命令比who命令更好,用于查看何人已登陆以及他们在做什么。
$ w
15:28:59 up 3 days, 21:23, 2 users, load average: 0.00, 0.03, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
khess pts/0 megamachine 12:26 1:38m 0.04s 0.04s -bash
khess pts/1 megamachine 12:30 0.00s 0.09s 0.01s w
8. sar(System Activity Reporter)
sar(System Activity Reporter)命令是sysstat软件包的一部分。 所有希望进行全面系统性能衡量的系统管理员都应该安装它。默认设置时每10分钟记录一个系统快照,为系统管理员提供24小时的性能视图。对于尝试在一天内找出瓶颈和故障,这款工具非常有价值。
sar命令具有超过36个配置参数。可通过man sar查看所有的功能列表。
$ sar
Linux 2.6.18-53.el5 (system.domain.com) 04/28/2010
12:00:01 AM CPU %user %nice %system %iowait %steal %idle
12:10:01 AM all 0.49 0.00 0.52 0.05 0.00 98.94
12:20:01 AM all 0.13 0.00 0.51 0.08 0.00 99.28
12:30:01 AM all 0.12 0.00 0.53 0.05 0.00 99.29
12:40:01 AM all 0.12 0.00 0.52 0.05 0.00 99.31
12:50:01 AM all 0.13 0.00 0.55 0.07 0.00 99.25
01:00:01 AM all 0.13 0.00 0.65 0.06 0.00 99.16
01:10:01 AM all 0.54 0.00 0.50 0.08 0.00 98.88
01:20:01 AM all 0.13 0.00 0.51 0.08 0.00 99.28
01:30:01 AM all 0.12 0.00 0.52 0.08 0.00 99.28
01:40:01 AM all 0.13 0.00 0.50 0.07 0.00 99.30
9. mpstat
mpstat命令为您提供多核处理器,CPU相关统计。它是sysstat软件包的一部分。
$ mpstat 5 5
Linux 2.6.18-53.el5 (system.domain.com) 04/28/2010
03:44:58 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
03:45:03 PM all 0.30 0.00 8.81 0.00 0.00 0.00 0.00 90.89 1072.80
03:45:08 PM all 0.10 0.00 0.40 1.10 0.00 0.10 0.00 98.30 1109.42
03:45:13 PM all 0.10 0.00 0.40 0.00 0.00 0.00 0.00 99.50 1063.15
03:45:18 PM all 0.20 0.00 3.70 0.00 0.00 0.00 0.00 96.10 1084.57
03:45:23 PM all 0.10 0.00 0.30 0.00 0.00 0.10 0.00 99.50 1067.07
Average: all 0.16 0.00 2.72 0.22 0.00 0.04 0.00 96.86 1079.37
或者
mpstat -P ALL
Linux 2.6.18-53.el5 (system.domain.com) 04/28/2010
03:50:59 PM CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
03:50:59 PM all 0.18 0.00 0.41 0.11 0.01 0.02 0.00 99.28 1071.77
03:50:59 PM 0 0.24 0.00 0.13 0.02 0.00 0.00 0.00 99.61 1000.70
03:50:59 PM 1 0.12 0.00 0.68 0.19 0.03 0.03 0.00 98.95 71.07
10. netstat
带有多种配置参数的netstat命令为您提供网络诊断信息统计,其中包括接口统计,路由表,网络连接等,聪明的系统管理员使用netstat诊断网络问题,攻击,以及查看服务和连接列表。
下面是一个例子:
$ netstat -a |grep LISTEN
tcp 0 0 localhost.localdomain:2208 *:* LISTEN
tcp 0 0 *:vmware-authd *:* LISTEN
tcp 0 0 *:mysql *:* LISTEN
tcp 0 0 *:netbios-ssn *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:ndmp *:* LISTEN
tcp 0 0 localhost.localdo:findviatv *:* LISTEN
tcp 0 0 localhost.localdomain:ipp *:* LISTEN
tcp 0 0 *:con *:* LISTEN
tcp 0 0 localhost.localdomain:smtp *:* LISTEN
tcp 0 0 localhost.lo:x11-ssh-offset *:* LISTEN
tcp 0 0 localhost.localdomain:6011 *:* LISTEN
tcp 0 0 *:microsoft-ds *:* LISTEN
tcp 0 0 *:ms-wbt-server *:* LISTEN
tcp 0 0 localhost.localdomain:2207 *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost6.l:x11-ssh-offset *:* LISTEN
tcp 0 0 localhost6.localdomain:6011 *:* LISTEN
11. du
du命令用于报告磁盘使用情况。您可以用它查看所有的文件系统或单独的某一个。如果您要使用du命令,要做好准备面对一大串的文件,目录以及它们的大小情况。最好是对信息进行过滤,这样就只查看某个特定文件夹或文件系统所占用空间的快照了。执行su命令,要求以人类可读方式(MB,GB)显示/opt文件夹的摘要报告。
$ du -sh /opt
929M /opt
12. df
df命令用于报告您的文件系统中的已用及可用空间。通过下面的例子,可以看出它的输出结果与du命令有什么不同。下面的例子采用的是很多系统管理员所系统的-h参数或者说是以人类可读格式。
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
360G 274G 68G 81% /
/dev/sda1 99M 30M 65M 32% /boot
tmpfs 1.4G 0 1.4G 0% /dev/shm
/dev/hdb1 230G 164G 55G 75% /backups
现在您已经掌握了这最棒的12款原生Linux监控工具。这些命令的真正魅力在于,它们不依赖于任何web服务或第三方产品即可正常工作。唯一的缺陷是既没有预测也不与历史数据相关联。这些工具仅仅是通过快照告诉您,当前您的系统正在做什么。
-------------------------
查看原文:The Top 12 Native Linux System Monitoring Tools
本文来源于DistroList:[], 原文地址:[/the-top-12-native-linux-system-monitoring-tools/]
阅读(690) | 评论(0) | 转发(0) |
0

上一篇:Linux看门狗-watchdog 5.8 发布

下一篇:嘟嘟】

给主人留下些什么吧!~~