Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17293
  • 博文数量: 17
  • 博客积分: 1425
  • 博客等级: 上尉
  • 技术积分: 195
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-07 13:52
文章分类

全部博文(17)

文章存档

2010年(17)

我的朋友
最近访客

分类:

2010-11-07 14:24:36

为了持续观察服务器每天的运行状态,需要结合shell脚本程序和计划任务,定期跟踪记录不同时段服务器的cpu负载,内存,交换空间,磁盘使用量等信息。
  实现手段:利用shell脚本程序
  具体设计思路:
  1.编写脚本monitor.sh
  #!/bin/bash
  #this is the second script!
  day_time=`date+"%F %R"`
  cpu_test=`uptime`
  mem_test=`free -m | grep "mem" | awk '{print $2}'`
  swap_test=`free -m | grep "mem" | awk '{print $4}'`
  disk_test=`df -hT`
  user_test=`last -n 10`
  echo "now is $day_time"
  echo "%cpu is $cpu_test"
  echo "Numbet of Mem size(MB) is $mem_test"
  echo "Number of swap size(MB) is $swap_test"
  echo "the disk shiyong qingkuang is $disk_test"
  echo "the users login qingkuang is $user_test"
  2.设置cron任务
  */15 * * * * bash /monitor.sh
  55 23 * * * tar cxf /var/log/runrec /var/log/running.today && --remove-files
  备注:设置cron计划任务是为了时时执行此脚本,来监控系统状态,并记入日志,便于对系统更好的管理!
阅读(376) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~