本博文的主要内容有

  .系统内存管理、监控:vmstat和free -mt

  .系统CPU管理、监控:sar -u、mpstat、uptime

  linux系统内存和CPU是在系统运行的过程中不断消耗的资源,其随系统进程的不断增加而减少,并在进程关闭后会回收有些资源。通过对系统内存和CPU使用率的监控,就能给了解linx系统当前的“繁忙”程序。

1、系统内存管理、监控:vmstat和free -mt

  在linux系统中,内存分为物理内存和虚拟内存。

  物理内存是真实存在的,即存在内存条上。

  虚拟内存,称为交换分区。

  在linux系统,用vmstat,即Virtual Memory Statistics,虚拟内存统计命令。

[root@weekend110 ~]# man vmstat
VMSTAT(8) Linux Administrator’s Manual VMSTAT(8)

NAME
vmstat - Report virtual memory statistics

SYNOPSIS
vmstat [-a] [-n] [-t] [-S unit] [delay [ count]]
vmstat [-s] [-n] [-S unit]
vmstat [-m] [-n] [delay [ count]]
vmstat [-d] [-n] [delay [ count]]
vmstat [-p disk partition] [-n] [delay [ count]]
vmstat [-f]
vmstat [-V]

DESCRIPTION
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 sam-
pling period of length delay. The process and memory reports are instantaneous in either case.

Options
The -a switch displays active/inactive memory, given a 2.5.41 kernel or better.

The -f switch displays the number of forks since boot. This includes the fork, vfork, and clone system calls,
and is equivalent to the total number of tasks created. Each process is represented by one or more tasks,
depending on thread usage. This display does not repeat.

The -t switch adds timestamp to the output.

The -m switch displays slabinfo.

The -n switch causes the header to be displayed only once rather than periodically.

The -s switch displays a table of various event counters and memory statistics. This display does not repeat.

delay is the delay between updates in seconds. If no delay is specified, only one report is printed with the

[root@weekend110 ~]# vmstat
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 953576 65676 531364 0 0 101 50 113 278 4 4 90 1 0
[root@weekend110 ~]# vmstat 2 4     每隔2秒执行一次,共执行4次

procs ,是进程,只输出两列信息,r表示正在运行的进程数,b是处于等待状态的进程数。

memory,是内存,输出四列信息,swpd涉及分页读取或写入磁盘的进程所消耗的所有内存,其表示系统已使用交换分区空间的数量。

                free为空闲的物理内存空间

                buff为系统用于缓冲区的物理内存空间

                cache为用作缓存的物理内存空间

swap,只输出两列信息,si表示系统从磁盘交换到内存的交换页数量,so表示从内存交换到磁盘的交换页数量

io,bi表示从磁盘读入到内存的块数量,bo为从内存读入到磁盘的块数。

system,in表示每秒系统的中断数,cs表示 每秒系统进程上下文切换的次数。

cpu,us表示执行用户进程时所使用的cpu时间,sy为执行系统进程时所使用的cpu时间,id表示cpu的空间时间,wa是等待I/O时所使用的cpu时间。

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 953584 65676 531376 0 0 101 50 113 277 4 4 90 1 0
0 0 0 953576 65676 531376 0 0 0 12 38 51 1 0 99 0 0
1 0 0 953576 65676 531376 0 0 0 0 31 46 0 1 99 0 0
0 0 0 953576 65676 531376 0 0 0 0 38 170 1 1 99 0 0
[root@weekend110 ~]#

[root@weekend110 ~]# free -mt      m表示以兆字节为单位输出,t表示提供一个合计行
total used free shared buffers cached
Mem: 1861 931 930 0 64 518
-/+ buffers/cache: 348 1513
Swap: 3055 0 3055
Total: 4917 931 3985
[root@weekend110 ~]#

2、系统CPU管理、监控:sar -u、mpstat、uptime

[root@weekend110 ~]# sar -u     -u是sar的默认选项,其表示以百分比的形式输出
Linux 2.6.32-431.el6.x86_64 (weekend110) 10/21/2016 _x86_64_ (1 CPU)

09:10:46 AM LINUX RESTART

09:20:02 AM CPU %user %nice %system %iowait %steal %idle
09:30:01 AM all 0.03 0.00 0.27 0.03 0.00 99.67
09:40:01 AM all 0.02 0.00 0.27 0.09 0.00 99.62
09:50:01 AM all 0.10 0.00 0.37 0.01 0.00 99.53
10:00:02 AM all 14.65 0.00 10.17 2.27 0.00 72.92
10:10:02 AM all 11.55 0.00 11.19 0.37 0.00 76.90
10:20:01 AM all 11.05 0.17 10.43 2.37 0.00 75.98
10:30:01 AM all 3.17 0.00 2.58 0.06 0.00 94.19
10:40:01 AM all 2.00 0.00 1.60 0.48 0.00 95.92
10:50:01 AM all 0.84 0.00 0.67 0.01 0.00 98.48
11:00:01 AM all 0.72 0.00 0.62 0.01 0.00 98.65
Average: all 4.33 0.02 3.76 0.56 0.00 91.34
[root@weekend110 ~]#

CPU表示系统中运行的CPU的编号(如双核)

%user表示,在用户模式下进程运行所花的CPU时间(%)

%nice表示,一个运行良好的进程运行所花的CPU时间(%)

%system表示,进程在内核模式下运行所花的CPU时间(%)

%iowait表示,在无进程运行时CPU等待I/O完成所花的时间(%)

%idle表示,CPU空闲时间(%)

[root@weekend110 ~]# mpstat
Linux 2.6.32-431.el6.x86_64 (weekend110) 10/21/2016 _x86_64_ (1 CPU)

11:08:56 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
11:08:56 AM all 3.89 0.01 3.52 1.01 0.02 0.15 0.00 0.00 91.40
[root@weekend110 ~]# mpstat 2    表示2秒收集一次,按ctrl + c组合键退出
Linux 2.6.32-431.el6.x86_64 (weekend110) 10/21/2016 _x86_64_ (1 CPU)

11:08:59 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle
11:09:01 AM all 0.52 0.00 0.52 0.00 0.00 0.00 0.00 0.00 98.97
11:09:03 AM all 0.00 0.00 0.51 0.00 0.00 0.00 0.00 0.00 99.49
11:09:05 AM all 0.50 0.00 0.50 0.00 0.00 0.50 0.00 0.00 98.51
11:09:07 AM all 0.52 0.00 0.52 0.00 0.00 0.00 0.00 0.00 98.97
11:09:09 AM all 0.00 0.00 0.51 0.00 0.00 0.00 0.00 0.00 99.49
11:09:11 AM all 0.51 0.00 0.51 0.00 0.00 0.51 0.00 0.00 98.46
^C
[root@weekend110 ~]#

  %ird表示,硬件中断和软件中断所花费的CPU时间(%)

  %intr/s表示,CPU每秒处理中断的次数

[root@weekend110 ~]# uptime
11:10:54 up 2:00, 3 users, load average: 0.01, 0.11, 0.07
[root@weekend110 ~]#

   当然,也可以使用System Monitor窗口监控CPU的使用情况。

系统内存和CPU管理、监控的更多相关文章

  1. 转---高并发Web服务的演变——节约系统内存和CPU

    [问底]徐汉彬:高并发Web服务的演变——节约系统内存和CPU 发表于22小时前| 4223次阅读| 来源CSDN| 22 条评论| 作者徐汉彬 问底Web服务内存CPU并发徐汉彬 摘要:现在的Web ...

  2. 高并发Web服务的演变——节约系统内存和CPU

    节约系统内存和CPU http://www.csdn.net/article/2015-02-12/2823952 Web系统大规模并发——电商秒杀与抢购 http://www.csdn.net/ar ...

  3. 查看Linux系统内存、CPU、磁盘使用率和详细信息

    一.查看内存占用 1.free # free -m 以MB为单位显示内存使用情况 [root@localhost ~]# free -m total used free shared buff/cac ...

  4. 查看linux/AIX系统内存及CPU占用百分比

    1.linux下查看CPU及内存占用情况 查看内存占用百分比: [root@rusky ~]# free -m | sed -n '2p' | awk '{print "used mem i ...

  5. 高并发Web服务的演变:节约系统内存和CPU

    一.越来越多的并发连接数 现在的Web系统面对的并发连接数在近几年呈现指数增长,高并发成为了一种常态,给Web系统带来不小的挑战.以最简单粗暴的方式解决,就是增加Web系统的机器和升级硬件配置.虽然现 ...

  6. 高并发 Web 服务的演变:节约系统内存和 CPU

    本文内容 越来越多的并发连接数 Web 前端优化,降低服务端压力 节约 Web 服务端的内存 节约 Web 服务器的 CPU 小结 一,越来越多的并发连接数 现在,Web 系统面对的并发连接数呈现指数 ...

  7. (转)高并发Web服务的演变——节约系统内存和CPU

    一.越来越多的并发连接数 现在的Web系统面对的并发连接数在近几年呈现指数增长,高并发成为了一种常态,给Web系统带来不小的挑战.以最简单粗暴的方式解决,就是增加Web系统的机器和升级硬件配置.虽然现 ...

  8. 【WEB】高并发Web服务的演变-节约系统内存和CPU

    目前主流浏览器通常可以存在2-6个并发. 连接和请求,占据了服务器的大量CPU和内存等资源.在资源数目超过100+的网站页面中,使用更多的下载连接,非常有必要. 缓解“高并发”的压力的手段. 一. W ...

  9. 31、服务器磁盘、内存、cpu使用率监控

    31.1.监控磁盘: #!/bin/sh diskspace="`df -hT`" IFS="\n" disk_value="80" ech ...

随机推荐

  1. ubuntu基本操作(2)

    查看当前使用那种 shell echo $SHELL 更换 shell 类型:首先检查是否安装了相应的类型 shell开启终端,直接输入相应的 shell 名称如果没有安装,则先安装,否则直接启动此时 ...

  2. shell编程的一些例子2

    控制语句: 1.if语句 demo_if #!/bin/bash if [ $# -ne 1 ] then echo "参数多于一个" exit 1 fi if [ -f &quo ...

  3. 我用C#调用C编译的dll中有这样一个函数,函数大概的功能就是把数据保存到buf缓冲区中:

    我用C#调用C编译的dll中有这样一个函数,函数大概的功能就是把数据保存到buf缓冲区中: C/C++ code   ? 1 int retrieve(int scanno,void* buf); 在 ...

  4. u-boot代码学习内容

    前言  u-boot代码庞大,不可能全部细读,只能有选择的读部分代码.在读代码之前,根据韦东山教材,关于代码学习内容和深度做以下预先划定. 一.Makefile.mkconfig.config.mk等 ...

  5. 黑马程序员-------.net基础知识三

    条件执行语句 if 语句 语法: [csharp] view plaincopyprint? if(条件) { 语句1;语句2:语句3: ··· } 执行过程: 先判断条件是否为true ,如果为tr ...

  6. POJ 1129 Channel Allocation 四色定理dfs

    题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...

  7. shutdown computer in ad and ou

    1. powershell Shutdown-computer –computername (gc c:\temp\serverlist.txt) –force –throttlelimit 10 h ...

  8. Visual Studio 内置快速生产代码简写集合

    工作之余,整理了一下,Visual Studio 里面的快速生产代码缩写集合,这个拿出来分享想一下,希望对您有所帮助. 文件下载地址:VS内置生产代码缩写集合文档.rar 首字母 简写 生成代码 a ...

  9. python中enumerate的使用

    在python的应用中,当我们使用一个数组或者列表的时候既要遍历索引又要遍历元素的时候通常的做法是这样的: >>> lsi = [1,2,3,4,5,6,7,8,9] >> ...

  10. HttpWebRequest提高效率之连接数,代理,自动跳转,gzip请求等设置问题

    先设置4个: [csharp] webrequest.ServicePoint.Expect100Continue = false; //是否使用 Nagle 不使用 提高效率 webrequest. ...