Linux系统维护的主要工作就是保证系统和应用的稳定。而如果想保证稳定就必须时刻了解系统的状态;cpu、内存、磁盘、网络和各种应用程序的运行于占用资源的状态等。同时掌握了系统资源的状态信息;也可以对系统进行优化,以发挥更好的性能。
对于这些信息的查看;需要一些工具能够及时的查看和分析;下面就对Linux系统资源监控常用的工具进行简单的介绍:
# sar -hUsage: sar [ options ] [ <interval> [ <count> ] ]Main options and reports: -b
I/O and transfer rate statistics -B
Paging statistics -d
Block device statistics -I { <int> | SUM | ALL | XALL } Interrupts statistics -m
Power management statistics -n { <keyword> [,...] | ALL } Network statistics Keywords are: DEV
Network interfaces EDEV
Network interfaces (errors).....详细请查看帮助信息 |
# sar -b -r -u 1 为了方便;这里一次性显示三项Linux 2.6.32-431.el6.x86_64 (node2.soul.com) 05/25/2014 _x86_64_
(1 CPU)#cpu信息09:07:24 PM CPU %user %nice %system %iowait %steal %idle09:07:25 PM all 0.00 0.00 2.02 0.00 0.00 97.98#I/O信息09:07:24 PM tps rtps wtps bread/s bwrtn/s09:07:25 PM 0.00 0.00 0.00 0.00 0.00#内存信息09:07:24 PM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit09:07:25 PM 764828 247524 24.45 11772 102232 1142588 36.75#对于这其中每项的含义就不做一一解释;基本表示的很清楚;大都是词面意思。 |
# sar -f /var/log/sa/sa25 sa25表示本月25号的信息Linux 2.6.32-431.el6.x86_64 (node2.soul.com) 05/25/2014 _x86_64_
(1 CPU)12:00:01 AM CPU %user %nice %system %iowait %steal %idle12:10:01 AM all 0.02 0.00 0.10 0.08 0.00 99.8012:20:01 AM all 0.01 0.00 0.10 0.06 0.00 99.83....03:20:01 PM CPU %user %nice %system %iowait %steal %idle03:30:01 PM all 7.38 0.00 0.53 0.31 0.00 91.7703:40:02 PM all 23.89 0.00 0.31 0.04 0.00 75.7603:50:01 PM all 21.84 0.00 2.37 0.32 0.00 75.4604:00:04 PM all 97.14 0.00 2.86 0.00 0.00 0.0004:10:01 PM all 47.26 0.00 0.41 0.17 0.00 52.1604:20:01 PM all 0.01 0.00 0.09 0.98 0.00 98.92Average: all 8.23 0.00 0.43 0.24 0.00 91.09#从上述信息可以看出下午3:20-4:10之前CPU占用率很高#每个文件最后一行都是统计的平均数据。 |
# sar -dLinux 2.6.32-431.el6.x86_64 (node2.soul.com) 05/25/2014 _x86_64_
(1 CPU)12:00:01 AM DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util12:10:01 AM dev11-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.0012:10:01 AM dev8-0 0.20 0.27 2.11 12.07 0.00 5.64 5.19 0.1012:10:01 AM dev8-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.0012:10:01 AM dev253-0 0.00 0.01 0.00 8.00 0.00 8.00 8.00 0.00 |
# sar -n NFS | moreLinux 2.6.32-431.el6.x86_64 (node2.soul.com) 05/25/2014 _x86_64_
(1 CPU)...08:50:01 PM 0.02 0.00 0.00 0.00 0.00 0.0009:00:01 PM 0.02 0.00 0.00 0.00 0.00 0.0009:10:01 PM 0.01 0.02 0.00 0.00 0.00 0.0009:20:01 PM 0.00 0.01 0.00 0.00 0.00 0.00Average: 0.02 0.00 0.00 0.00 0.00 0.00# sar -n DEV | moreLinux 2.6.32-431.el6.x86_64 (node2.soul.com) 05/25/2014 _x86_64_
(1 CPU)12:00:01 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s12:10:01 AM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00...Average: lo 0.92 0.92 1.47 1.47 0.00 0.00 0.00Average: eth0 627.52 19.67 142.99 2.63 0.00 0.00 0.00Average: virbr0 0.00 0.00 0.00 0.00 0.00 0.00 0.00Average: virbr0-nic 0.00 0.00 0.00 0.00 0.00 0.00 0.00 |
# yum -y install htop# htop |
# dstat -h 查看帮助信息Usage: dstat [-afv] [options..] [delay [count]]Versatile tool for generating system resource statisticsDstat options: -c, --cpu enable cpu stats -C 0,3,total include cpu0, cpu3 and total -d, --disk enable disk stats -D total,hda include hda and total -g, --page enable page stats -i, --int enable interrupt stats -I 5,eth2 include int5 and interrupt used by eth2 -l, --load enable load stats -m, --mem enable memory stats -n, --net enable network stats -N eth1,total include eth1 and total |
# dstat -c 1 5 显示cpu状态;每1秒刷新1次,共5次----total-cpu-usage----usr sys idl wai hiq siq 8 0 92 0 0 0 0 0 100 0 0 0 0 0 100 0 0 0 0 1 99 0 0 0 0 0 100 0 0 0 0 0 100 0 0 0 |
# dstat --listinternal: aio, cpu, cpu24, disk, disk24, disk24old, epoch, fs, int, int24, io, ipc, load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold, sys, tcp, time, udp, unix, vm/usr/share/dstat: battery, battery-remain, cpufreq, dbus, disk-util, fan, freespace, gpfs, gpfs-ops, helloworld, innodb-buffer, innodb-io, innodb-ops, lustre, memcache-hits, mysql-io, mysql-keys, mysql5-cmds, mysql5-conn, mysql5-io, mysql5-keys, net-packets, nfs3, nfs3-ops, nfsd3, nfsd3-ops, ntp, postfix, power, proc-count, rpc, rpcd, sendmail, snooze, thermal, top-bio, top-cpu, top-cputime, top-cputime-avg, top-io, top-latency, top-latency-avg, top-mem, top-oom, utmp, vm-memctl, vmk-hba, vmk-int, vmk-nic, vz-cpu, vz-io, vz-ubc, wifi |
# dstat --top-cpu-most-expensive- cpu process mysqld 0.1 mmm_agentd 4.0sshd: root@pt1.0kblockd/0 1.0events/0 1.0 |
# dstat --top-mem--most-expensive- memory process mysqld 37.0Mmysqld 37.0Mmysqld 37.0Mmysqld 37.0M |
-
CPU 信息 (用户的相关应用, 系统核心程序和空闲程序)
-
总内存信息,包括了物理内存,交换空间和空闲内存等等
-
之前的 1 分钟、5 分钟和 15 分钟平均的 CPU 负载
-
网络链接的下行和上行速度
-
处理器总数,以及其活动状态
-
硬盘 I/O 相关(读写)速度详情
-
当前挂载设备的磁盘使用情况
-
高 CPU 和内存使用的进程名,和相关应用的位置
-
在底部显示当前日期和时间
-
将消耗最高系统资源的进程用红色标出
|
1
|
# glances |
在服务器端启动# glances -s -B 192.168.0.113Define the password for the Glances serverPassword: Password (confirm): Glances server is running on 192.168.0.113:61209 |
#安装jinja# yum -y install python-jinja2# glances -o HTML -f /var/www/html/ -o:输出格式;HTML/CSS,-f:指定文件目录 |
本文介绍了Linux系统中用于监控和管理资源的常用工具,包括sar、Htop、dstat和Glances,分别从CPU、内存、网络、磁盘I/O等方面提供了实时的数据展示与分析,帮助用户了解系统状态,优化性能。








869

被折叠的 条评论
为什么被折叠?



