linux性能监控工具

Linux系统出现问题时,我们不仅需要查看系统日志信息,而且还要使用大量的性能监测工具来判断究竟是哪一部分(内存、CPU、硬盘……)出了问题。在Linux系统中,所有的运行参数保存在虚拟目录/proc中,换句话说,我们使用的性能监控工具取到的数据值实际上就是源自于这个目录,当涉及到系统高估时,我们就可以修改/proc目录中的相关参数了,当然有些是不能乱改的。下面就让我们了解一下这些常用的性能监控工具。




工具




功能描述




uptime ---- 系统平均负载率 dmesg ---- 硬件/系统信息 top ----- 进程进行状态

iostat -------- CPU和磁盘平均使用率 vmstat --------- 系统运行状态 sar --------- 实时收集系统使用状态 KDE System Guard --- 图形监控工具 free ---------------内存使用率

traffic-vis ------------网络监控(只有SUSE有) pmap ------------- 进程内存占用率 strace --------- 追踪程序运行状态 ulimit ---------系统资源使用限制 mpstat -------------多处理器使用率




1、uptime




  uptime命令用于查看服务器运行了多长时间以及有多少个用户登录,快速获知服务器的负荷情况。




  uptime的输出包含一项内容是load average,显示了最近1,5,15分钟的负荷情况。它的值代表等待CPU处理的进程数,如果CPU没有时间处理这些进程,load average值会升高;反之则会降低。 load average的最佳值是1,说明每个进程都可以马上处理并且没有CPU cycles被丢失。对于单CPU的机器,1或者2是可以接受的值;对于多路CPU的机器,load average值可能在8到10之间。




  也可以使用uptime命令来判断网络性能。例如,某个网络应用性能很低,通过运行uptime查看服务器的负荷是否很高,如果不是,那么问题应该是网络方面造成的。 以下是uptime的运行实例:




  9:24am up 19:06, 1 user, load average: 0.00, 0.00, 0.00




  也可以查看/proc/loadavg和/proc/uptime两个文件,注意不能编辑/proc中的文件,要用cat等命令来查看,如:




  liyawei:~ # cat /proc/loadavg 0.00 0.00 0.00 1/55 5505




  2、dmesg




  dmesg命令主要用来显示内核信息。使用dmesg可以有效诊断机器硬件故障或者添加硬件出现的问题。




  另外,使用dmesg可以确定您的服务器安装了那些硬件。每次系统重启,系统都会检查所有硬件并将信息记录下来。执行/bin/dmesg命令可以查看该记录。 dmesg输入实例:




ReiserFS: hda6: checking transaction log (hda6) ReiserFS: hda6: Using r5 hash to sort names

Adding 1044184k swap on /dev/hda5. Priority:-1 extents:1 across:1044184k parport_pc: VIA 686A/8231 detected

parport_pc: probing current configuration parport_pc: Current parallel port base: 0x378

parport0: PC-style at 0x378 (0x778), irq 7, using FIFO [PCSPP,TRISTATE,COMPAT,ECP] parport_pc: VIA parallel port: io=0x378, irq=7 lp0: using parport0 (interrupt-driven).

e100: Intel(R) PRO/100 Network Driver, 3.5.10-k2-NAPI e100: Copyright(c) 1999-2005 Intel Corporation

ACPI: PCI Interrupt 0000:00:0d.0[A] -> GSI 17 (level, low) -> IRQ 169

e100: eth0: e100_probe: addr 0xd8042000, irq 169, MAC addr 00:02:55:1E:35:91 usbcore: registered new driver usbfs usbcore: registered new driver hub

hdc: ATAPI 48X CD-ROM drive, 128kB Cache, UDMA(33) Uniform CD-ROM driver Revision: 3.20

USB Universal Host Controller Interface driver v2.3 3、top


  top命令显示处理器的活动状况。缺省情况下,显示占用CPU最多的任务,并且每隔5秒钟做一次刷新。




  Process priority的数值决定了CPU处理进程的顺序。LIUNX内核会根据需要调整该数值的大小。nice value局限于priority。priority的值不能低于nice value(nice value值越低,优先级越高)。您不可以直接修改Process priority的值,但是可以通过调整nice level值来间接地改变Process priority值,然而这一方法并不是所有时候都可用。如果某个进程运行异常的慢,可以通过降低nice level为该进程分配更多的CPU。




  Linux 支持的 nice levels 由19 (优先级低)到-20 (优先级高),缺省值为0。 执行/bin/ps命令可以查看到当前进程的情况。



 4、iostat


  iostat由Red Hat Enterprise Linux AS发布。同时iostat也是Sysstat的一部分,可以下载到,网址是http://perso.wanadoo.fr/sebastien.godard/




  执行iostat命令可以从系统启动之后的CPU平均时间,类似于uptime。除此之外,iostat还对创建一个服务器磁盘子系统的活动报告。该报告包含两部分:CPU使用情况和磁盘使用情况。




  iostat显示实例:




avg-cpu: %user %nice %system %iowait %steal %idle 0.16 0.01 0.03 0.10 0.00 99.71

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn hda 0.31 4.65 4.12 327796 290832 avg-cpu: %user %nice %system %iowait %steal %idle 1.00 0.00 0.00 0.00 0.00 100.00

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn hda 0.00 0.00 0.00 0 0 avg-cpu: %user %nice %system %iowait %steal %idle 0.00 0.00 0.00 0.00 0.00 99.01

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn hda 0.00 0.00 0.00 0 0



CPU占用情况包括四块内容


  %user:显示user level (applications)时,CPU的占用情况。 %nice:显示user level在nice priority时,CPU的占用情况。 %sys:显示system level (kernel)时,CPU的占用情况。 %idle: 显示CPU空闲时间所占比例。 磁盘使用报告分成以下几个部分: Device: 块设备的名字




  tps: 该设备每秒I/O传输的次数。多个I/O请求可以组合为一个,每个I/O请求传输的字节数不同,因此可以将多个I/O请求合并为一个。 Blk_read/s, Blk_wrtn/s: 表示从该设备每秒读写的数据块数量。块的大小可以不同,如1024, 2048 或 4048字节,这取决于partition的大小。




  例如,执行下列命令获得设备/dev/sda1 的数据块大小: dumpe2fs -h /dev/sda1 |grep -F "Block size" 输出结果如下:




  dumpe2fs 1.34 (25-Jul-2003) Block size: 1024


  Blk_read, Blk_wrtn: 指示自从系统启动之后数据块读/写的合计数。


  也可以查看这几个文件/proc/stat,/proc/partitions,/proc/diskstats的内容。




  5、vmstat


  vmstat提供了processes, memory, paging, block I/O, traps和CPU的活动状况


procs -----------memory---------- ---swap-- -----io---- -system-- -----cpu------ r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 513072 52324 162404 0 0 2 2 261 32 0 0 100 0 0 0 0 0 513072 52324 162404 0 0 0 0 271 43 0 0 100 0 0 0 0 0 513072 52324 162404 0 0 0 0 255 27 0 0 100 0 0 0 0 0 513072 52324 162404 0 0 0 28 275 51 0 0 97 3 0 0 0 0 513072 52324 162404 0 0 0 0 255 21 0 0 100 0 0 各输出列的含义: Process

– r: The number of processes waiting for runtime.

– b: The number of processes in uninterruptable sleep. Memory

– swpd: The amount of virtual memory used (KB). – free: The amount of idle memory (KB).

– buff: The amount of memory used as buffers (KB). Swap

– si: Amount of memory swapped from the disk (KBps).

– so: Amount of memory swapped to the disk (KBps). IO

– bi: Blocks sent to a block device (blocks/s).

– bo: Blocks received from a block device (blocks/s). System

– in: The number of interrupts per second, including the clock. – cs: The number of context switches per second. CPU (these are percentages of total CPU time)

- us: Time spent running non-kernel code (user time, including nice time). – sy: Time spent running kernel code (system time).

– id: Time spent idle. Prior to Linux 2.5.41, this included IO-wait time.

– wa: Time spent waiting for IO. Prior to Linux 2.5.41, this appeared as zero.


  6、sar


  sar是Red Hat Enterprise Linux AS发行的一个工具,同时也是Sysstat工具集的命令之一,可以从以下网址下载:http://perso.wanadoo.fr/sebastien.godard/


  sar用于收集、报告或者保存系统活动信息。sar由三个应用组成:sar显示数据、sar1和sar2用于收集和保存数据。




  使用sar1和sar2,系统能够配置成自动抓取信息和日志,以备分析使用。配置举例:在/etc/crontab中添加如下几行内容




  同样的,你也可以在命令行方式下使用sar运行实时报告。




  从收集的信息中,可以得到详细的CPU使用情况(%user, %nice, %system, %idle)、内存页面调度、网络I/O、进程活动、块设备活动、以及interrupts/second liyawei:~


# sar -u 3 10

Linux 2.6.16.21-0.8-default (liyawei) 05/31/07

10:17:16 CPU %user %nice %system %iowait %idle 10:17:19 all 0.00 0.00 0.00 0.00 100.00 10:17:22 all 0.00 0.00 0.00 0.33 99.67 10:17:25 all 0.00 0.00 0.00 0.00 100.00 10:17:28 all 0.00 0.00 0.00 0.00 100.00 10:17:31 all 0.00 0.00 0.00 0.00 100.00 10:17:34 all 0.00 0.00 0.00 0.00 100.00 7、KDE System Guard


  KDE System Guard (KSysguard) 是KDE图形方式的任务管理和性能监视工具。监视本地及远程客户端/服务器架构体系的中的主机。



本文出自 “ghost” 博客,请务必保留此出处http://fangwei009.blog.51cto.com/5234706/1773283

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值