为方便问题发生后,问题原因的分析排查,我们可以在服务器中事先部署如下脚本,方便故障发生后,问题原因的分析排查

脚本部署方法:

1.将脚本【top_monitor.sh】上传到服务器

2.登陆虚拟机,并切换到root用户

3.执行命令: chmod +x  <path>/top_monitor.sh  【<path>替换成实际脚本上传的目录】

4.执行命令:crontab -e

5.添加定时任务:* * * * * <the path of the script>/top_monitor.sh <the path of ouputs saved> <keeps>

备注:

范例:* * * * * /root/top_monitor.sh /var/tmp/ 72 &

a.这里的keeps以小时为单位,如果保留三天的话,就输入72

b.该脚本每五秒钟收集一次top/vmstat/iostat命令的输出,每分钟会生成一个性能数据文件

c.不要把用户数据放到该目录下,否则会被清理掉

6.搜集到的性能日志格式如下:

-- ::
top - :: up day, min, users, load average: 0.00, 0.00, 0.00
Tasks: total, running, sleeping, stopped, zombie
Cpu(s): 1.0%us, 0.5%sy, 0.0%ni, 98.2%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3530640k total, 778368k used, 2752272k free, 127976k buffers
Swap: 0k total, 0k used, 0k free, 352288k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
root S 1.9 0.0 :07.04 events/
root S 0.0 0.0 :07.80 init
root S 0.0 0.0 :00.01 kthreadd
root RT S 0.0 0.0 :02.09 migration/
root S 0.0 0.0 :00.79 ksoftirqd/
root RT S 0.0 0.0 :00.00 stopper/
root RT S 0.0 0.0 :00.13 watchdog/
root RT S 0.0 0.0 :02.19 migration/
root RT S 0.0 0.0 :00.00 stopper/
root S 0.0 0.0 :00.80 ksoftirqd/
root RT S 0.0 0.0 :00.13 watchdog/
root S 0.0 0.0 :04.85 events/
root S 0.0 0.0 :00.00 events/
root S 0.0 0.0 :00.00 events/
root S 0.0 0.0 :00.00 events_long/
root S 0.0 0.0 :00.00 events_long/
root S 0.0 0.0 :00.00 events_power_ef
root S 0.0 0.0 :00.00 events_power_ef
root S 0.0 0.0 :00.00 cgroup
root S 0.0 0.0 :00.00 khelper
root S 0.0 0.0 :00.00 netns
root S 0.0 0.0 :00.00 async/mgr
root S 0.0 0.0 :00.00 pm
root S 0.0 0.0 :00.39 sync_supers
root S 0.0 0.0 :00.06 bdi-default
root S 0.0 0.0 :00.00 kintegrityd/
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st Linux 2.6.-696.3..el6.x86_64 (hlmcent69nma) // _x86_64_ ( CPU) avg-cpu: %user %nice %system %iowait %steal %idle
1.00 0.00 0.52 0.27 0.00 98.20 Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sdc 0.00 0.00 0.00 0.00 0.03 0.00 8.02 0.00 1.88 1.88 0.00 1.88 0.00
sdb 0.00 6.55 0.01 0.08 0.09 3249.50 37296.35 0.00 13.02 0.60 14.82 0.50 0.00
sda 0.04 15.12 0.12 2.52 6.35 141.07 55.83 0.01 4.93 6.92 4.83 3.29 0.87

脚本详情如下:

#! /bin/bash

if [ $# != 2 ]; then
echo "Invalid option, try top_monitor.sh <path> <hours>"
exit
fi export dir=$1
export keeps=$2 ## Create topMon folder
if [ ! -d "$dir" ]; then
mkdir $dir
fi mkdir $dir/topMon file=$dir/topMon/"topMon_"`date +%Y%m%d`
file=$dir/topMon/"topMon_"`date +%Y%m%d%H%M%S` ## Cleanup expired outputs
for i in `find $dir/topMon/ -type f -atime +$keeps -print`
#for i in `find $dir/topMon/ -type f -amin +$keeps -print`
do
rm -rf $i
done ## Record top ouputs
for i in {0..10}
do
date +"%Y-%m-%d %H:%M:%S" >> $file
top -b -n 1 | head -33 >> $file
vmstat >> $file
iostat -x 1 1 >> $file
sleep 5
done

最新文章

  1. MongoDB常用操作--集合2
  2. JAVA基础知识之Annotation
  3. jQuery库中的变量$和其它类库的变量$冲突解决方案
  4. JAX-RS(基于Jersey) + Spring 4.x + MyBatis构建REST服务架构
  5. 校内OJ 1128 词链(link)(Trie+DFS)
  6. [转载]Sublime Text 3 搭建 React.js 开发环境
  7. 《数据通信与网络》笔记--SCTP
  8. 【通信】Netty JBOSS提供的一个java开源框架
  9. Reflector+Reflexil 相结合实现对DLL文件修改
  10. 解决从VIM复制出来的代码格式错乱或对齐的问题
  11. lua中打印所以类型功能实现table嵌套table
  12. Petit FatFs
  13. element ui 1.4 升级到 2.0.11
  14. Luogu 3375 【模板】KMP字符串匹配(KMP算法)
  15. javascript语法之Date对象与小案例
  16. SQL Server 常用的系统函数
  17. PHP遍历二叉树
  18. STL之set和map
  19. 海思编解码芯片添加64M nor flash
  20. Java_Mybatis_注解代理写法

热门文章

  1. 【读书笔记与思考】《python数据分析与挖掘实战》-张良均
  2. css布局--水平垂直居中
  3. IOS10.3上传照片只能拍照不能选择解决办法
  4. es7 await/async解决异步问题
  5. linux下使用 FreeRDP 连接 Windows 远程桌面(转)
  6. es5预览本地文件、es6练习代码演示案例
  7. SSIS 延迟验证(DelayValidation)
  8. 关于python使用threadpool中的函数单个参数和多个参数用法举例
  9. PHP面向对象编程基本原则
  10. CodeForces801-A.Vicious Keyboard-暴力