Linux下磁盘监控脚本

九月份偷了下懒,补上一篇

注释:shell脚本,需要fio工具,实时监控磁盘的读写性能

#!/bin/bash
DATE=$(date +%m-%d)
IOSTATLOG=/var/log/iostat${DATE}.log
FIOLOG=/var/log/fio${DATE}.log

/bin/ps -ef |grep "iostat -dk 5" | grep -v grep > /dev/null

if [ $? == 0 ]
then
echo "Disk monitor already running"
exit 1
else
/usr/bin/iostat -dk 5 >>$IOSTATLOG &
pid=$!
fi

while true
do

echo "-------------`date`--------">>$FIOLOG
echo "--------------fio test---------------------">>$FIOLOG
######随机读:
echo "-------------随机读s----------------">>$FIOLOG
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=4k -size=4096M -numjobs=10 -runtime=1000 -group_reporting -name=mytest >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=128k -size=4096M -numjobs=10 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=psync -bs=1M -size=4096M -numjobs=10 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
#####顺序读:
echo "-------------顺序读----------------">>$FIOLOG
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=4k -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=128k -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=read -ioengine=psync -bs=1M -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1

#####随机写:
echo "-------------随机写----------------">>$FIOLOG
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=4k -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=128k -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randwrite -ioengine=psync -bs=1M -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1

#####顺序写:
echo "-------------顺序写----------------">>$FIOLOG
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=4k -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=128k -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=write -ioengine=psync -bs=1M -size=4096M -numjobs=30 -runtime=1000 -group_reporting -name=mytest  >>$FIOLOG 2>&1

#####混合随机读写:
echo "-------------混合随机读写----------------">>$FIOLOG
#######4k
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=4k -size=4096M -numjobs=30 -runtime=100 -group_reporting -name=mytest -ioscheduler=noop  >>$FIOLOG 2>&1
#######128k
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=128k -size=4096M -numjobs=30 -runtime=100 -group_reporting -name=mytest -ioscheduler=noop  >>$FIOLOG 2>&1
#######1M
fio -filename=/dev/sda1 -direct=1 -iodepth 1 -thread -rw=randrw -rwmixread=70 -ioengine=psync -bs=1M -size=4096M -numjobs=30 -runtime=100 -group_reporting -name=mytest -ioscheduler=noop  >>$FIOLOG 2>&1

sleep 60
done
时间: 2024-12-05 16:18:56

Linux下磁盘监控脚本的相关文章

linux下磁盘占用达到100%了,找不到哪些大文件耗尽了磁盘。

Linux下的根分区使用率100%,但是查看/分区下的目录都不大,没有占用满,这该怎么处理? 重启是肯定有效的,目前处理情况:重新restart应用后,空间释放出来 1.lsof | grep deletd 2.reboot 重启 linux下磁盘占用达到100%了,找不到哪些大文件耗尽了磁盘. Linux下使用df -lh 查看磁盘时: /dev/sda1 130G 123G 353M 100% / 磁盘快用尽了, 但我这边就是查找不到具体是哪些大文件占用的. 1.如果是大文件占用了,那么查询

linux下磁盘管理机制--LVM

当我们用传统分区方法使用磁盘时,当出现分区大小不够用的时候,通常只能添加添加一个更大的磁盘,重新创建分区来扩展空间.但是,这样只能是将原来的磁盘下线,换上新的磁盘,在将原始数据写入,在实际的生产过程中是不允许的.此时就需要使用逻辑卷LVM这种磁盘分区管理了. 逻辑卷是将硬盘空间重新"分割"成大小相等的块(PE)组成的PV放到一个容器(VG)中,当需要可以随时向这个容器中取出这样的块,来实现动态调整磁盘空间大小.当然新添加的块不会改变原来的文件系统,而且原磁盘也不用下线. 下面说明逻辑卷

Linux下添加shell脚本使得nginx日志每天定时切割压缩

Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介 对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大 这时,无论是出现异常时查日志,还是使用"GoAccess"等工具对日志进行分析都将会变得非常麻烦.因此,每天定时对nginx日志进行切割压缩就非常有必要了 二 实现 我的实现思路是每天晚上接近12点时定时执行脚本.其脚本内容就是将当前的nginx日志先按照当天日期进行重命名接着进行压缩,最后是新建空白的ngi

Linux下磁盘分区、挂载、卸载操作记录

Linux下磁盘分区.挂载.卸载操作记录. 操作环境:CentOS release 6.5 (Final) Last login: Wed Oct 26 17:25:27 2016 from 118.230.194.76 [[email protected] ~]# [[email protected] ~]# fdisk -l Disk /dev/sda: 536.9 GB, 536870912000 bytes 255 heads, 63 sectors/track, 65270 cylin

linux下磁盘管理机制--RAID

RAID(Redundant Array Of Independent Disks):独立磁盘冗余阵列.RAID的最初出现的目的是为了解决中小型企业因经费原因使用不起SCSCI硬盘,而不得不使用像IDE较廉价的磁盘情况下,将多块IDE磁盘通过某种机制组合起来,使得IDE磁盘在一定程度上提高读写性能的一种机制.当然,现在也可以将SCSCI类的磁盘也可以做成RAID来提高磁盘的读写性能. 一.RAID的级别 RAID机制通过级别来RAID级别来定义磁盘的组合方式.常见的级别有:RAID0,RAID1

linux下定时执行脚本

cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动.关闭这个服务: 1.cron的启动 /sbin/service crond start //启动服务/sbin/service crond stop //关闭服务/sbin/service crond restart //重启服务/sbin/service crond reload //重新载入配置 你也可以将这个服务在系统启动的时候自动启动:

linux下实现监控进程网络带宽

嗯,最近都在网易游戏实习,所以貌似有段时间没有上来写点东西了...来网易游戏实习最主要的目的其实就是想知道在游戏公司里面工作都是些什么内容,毕竟自己以前也没有接触过游戏公司..还比较的好奇... 以前可能觉得游戏公司各种高大上吧,做的工作各种有意思..现在看来应该也不是这样子的,毕竟大多数时间应该还是在写游戏的逻辑代码了... 挺奇怪的...感觉虽然在游戏公司实习,但是做的事情还是自己的老本行...因为要用python开发一个服务器的监控系统,而且有提出要监控某个指定进程所占用的网络带宽的情况.

Linux下的shell脚本编程-变量-算术表达式-判断语句-if分支语句

Linux下的shell脚本编程-变量-算术表达式-判断语句-if分支语句 一:实验环境 1):虚拟机 2):linux系统 二:实验目标 1): shell 基本语法 2):变量 3):表达式 4):判断语句 5): if表达式 三:实验脚本 第一块 一个简单的shell脚本程序 [[email protected] ~]# mkdir test [[email protected] test]# vim example1.sh #!/bin/bash #This is to show wha

linux下磁盘的挂载

linux下磁盘的挂载与卸载 Linux下每个文件系统都有独立的inode,block,super block等信息,这个文件系统要挂载到目录树才可以使用,将文件系统与目录树结合的操作称为挂载,反之则为卸载. 也就是说,挂载点一定是目录,而目录是进入磁盘分区(也就是文件系统)的入口. 挂载时有三点需要注意: 1.单一文件系统不应该重复被挂载到不同的挂载点(目录)中:2.单一目录不应该重复挂载多个文件系统#这两点可以类比windows磁盘与盘符的关系,一一对应.3.作为挂载点的目录理论上应该是空目