iotop

硬盘不休眠意味着有进程不断地在读写硬盘,用这个工具排查
官网:http://guichaz.free.fr/iotop/
需要Python 2.5(及以上版本)和 Linux kernel 2.6.20(及以上版本),TASK_DELAY_ACCT,CONFIG_TASKSTATS,TASK_IO_ACCOUNTING,CONFIG_VM_EVENT_COUNTERS这些内核选项开启。
用法:iotop [OPTIONS]

参数: —version 显示版本号然后退出 -h, —help 显示帮助然后退出 -o, —only 只显示正在产生I/O的进程或线程。除了传参,可以在运行过程中按o生效。 -b, —batch 非交互模式,一般用来记录日志 -n NUM, —iter=NUM 设置监测的次数,默认无限。在非交互模式下很有用 -d SEC, —delay=SEC 设置每次监测的间隔,默认1秒,接受非整形数据例如1.1 -p PID, —pid=PID 指定监测的进程/线程 -u USER, —user=USER 指定监测某个用户产生的I/O -P, —processes 仅显示进程,默认iotop显示所有线程 -a, —accumulated 显示累积的I/O,而不是带宽 -k, —kilobytes 使用kB单位,而不是对人友好的单位。在非交互模式下,脚本编程有用。 -t, —time 加上时间戳,非交互非模式。 -q 只在第一次监测时显示列名 -qq 永远不显示列名。 -qqq 永远不显示I/O汇总。

快捷键:
快捷键:
左右箭头来改变排序
r:反向排序,
o:切换至选项—only,
p:切换至—processes选项,
a:切换至—accumulated选项
q:退出
i:改变线程的优先级

可惜没有指定监测磁盘的选项,
iotop -o -P -b > iolog.log 获取IO读写日志就可以分析出来

hdparm

硬盘进行休眠状态的工具
用法:hdparm [-CfghiIqtTvyYZ][-a <快取分区>][-A <0或1>][-c ][-d <0或1>][-k <0或1>][-K <0或1>][-m <分区数>][-n <0或1>][-p ][-P <分区数>][-r <0或1>][-S <时间>][-u <0或1>][-W <0或1>][-X <传输模式>][设备]

参数: -a<快取分区> 设定读取文件时,预先存入块区的分区数,若不加上<快取分区>选项,则显示目前的设定。 -A<0或1> 启动或关闭读取文件时的快取功能。 -B 高级电源管理 1 - 待机状态时最低功耗(磁头停转) 64 - 待机状态时中等功耗 127 - 待机状态时中等功耗 128 - 非待机状态时最低功耗(磁头不停转) 192 - 非待机状态时中等功耗 254 - 最高性能,最大功耗 255 - 已禁用 -C 检测IDE硬盘的电源管理模式。 -d<0或1> 设定磁盘的DMA模式。 -d<0或1> 设定磁盘的DMA模式。

-f 将内存缓冲区的数据写入硬盘,并清楚缓冲区。

-g 显示硬盘的磁轨,磁头,磁区等参数。

-h 显示帮助。

-i 显示硬盘的硬件规格信息,这些信息是在开机时由硬盘本身所提供。

-I 直接读取硬盘所提供的硬件规格信息。

-k<0或1> 重设硬盘时,保留-dmu参数的设定。

-K<0或1> 重设硬盘时,保留-APSWXZ参数的设定。

-m<磁区数> 设定硬盘多重分区存取的分区数。

-n<0或1> 忽略硬盘写入时所发生的错误。

-p 设定硬盘的PIO模式。

-P<磁区数> 设定硬盘内部快取的分区数。

-q 在执行后续的参数时,不在屏幕上显示任何信息。

-r<0或1> 设定硬盘的读写模式。

-S<时间> 进入省电模式前的等待时间等待时间。 120 = 10 minutes =10分钟×60秒/5

180 = 15 minutes

242 = 1 hour

243 = 1.5 hours

244 = 2 hours

-t 评估硬盘的读取效率。

-T 平谷硬盘快取的读取效率。

-u<0或1> 在硬盘存取时,允许其他中断要求同时执行。

-v 显示硬盘的相关设定。

-W<0或1> 设定硬盘的写入快取。

-X<传输模式> 设定硬盘的传输模式。

-y 使IDE硬盘进入省电模式。

-Y 使IDE硬盘进入睡眠模式。

-Z 关闭某些Seagate硬盘的自动省电功能。

常用的几个命令
使所有硬盘立马进入省电状态 hdparm -Y /dev/sd* 检查所有硬盘当前省电状态 sudo hdparm -C /dev/sd*

在Debian系统中已设置了开机自启动hdparm命令的Script,该Script位于/etc/rcS.d/目录下。当Debian系统启动时会自动运行该Script,并从/etc/hdparm.conf配置文件中读出配置参数来运行hdparm命令,从而达到自动设置驱动器运行参数的目的。

  1. ## This is the default configuration for hdparm for Debian. It is a
  2. ## rather simple script, so please follow the following guidelines :)
  3. ## Any line that begins with a comment is ignored - add as many as you
  4. ## like. Note that an in-line comment is not supported. If a line
  5. ## consists of whitespace only (tabs, spaces, carriage return), it will be
  6. ## ignored, so you can space control fields as you like. ANYTHING ELSE
  7. ## IS PARSED!! This means that lines with stray characters or lines that
  8. ## use non # comment characters will be interpreted by the initscript.
  9. ## This has probably minor, but potentially serious, side effects for your
  10. ## hard drives, so please follow the guidelines. Patches to improve
  11. ## flexibilty welcome. Please read /usr/share/doc/hdparm/README.Debian for
  12. ## notes about known issues, especially if you have an MD array.
  13. ##
  14. ## Note that if the init script causes boot problems, you can pass 'nohdparm'
  15. ## on the kernel command line, and the script will not be run.
  16. ##
  17. ## Uncommenting the options below will cause them to be added to the DEFAULT
  18. ## string which is prepended to options listed in the blocks below.
  19. ##
  20. ## If an option is listed twice, the second instance replaces the first.
  21. ##
  22. ## /sbin/hdparm is not run unless a block of the form:
  23. ## DEV {
  24. ## option
  25. ## option
  26. ## ...
  27. ## }
  28. ## exists. This blocks will cause /sbin/hdparm OPTIONS DEV to be run.
  29. ## Where OPTIONS is the concatenation of all options previously defined
  30. ## outside of a block and all options defined with in the block.
  31. # -q be quiet
  32. quiet
  33. # -a sector count for filesystem read-ahead
  34. #read_ahead_sect = 12
  35. # -A disable/enable the IDE drive's read-lookahead feature
  36. #lookahead = on
  37. # -b bus state
  38. #bus = on
  39. # -B apm setting
  40. #apm = 255
  41. # -c enable (E)IDE 32-bit I/O support - can be any of 0,1,3
  42. #io32_support = 1
  43. # -d disable/enable the "using_dma" flag for this drive
  44. #dma = off
  45. # -D enable/disable the on-drive defect management
  46. #defect_mana = off
  47. # -E cdrom speed
  48. #cd_speed = 16
  49. # -k disable/enable the "keep_settings_over_reset" flag for this drive
  50. #keep_settings_over_reset = off
  51. # -K disable/enable the drive's "keep_features_over_reset" flag
  52. #keep_features_over_reset = on
  53. # -m sector count for multiple sector I/O
  54. #mult_sect_io = 32
  55. # -P maximum sector count for the drive's internal prefetch mechanism
  56. #prefetch_sect = 12
  57. # -r read-only flag for device
  58. #read_only = off
  59. # -s Turn on/off power on in standby mode
  60. #poweron_standby = off
  61. # -S standby (spindown) timeout for the drive
  62. #spindown_time = 24
  63. # -u interrupt-unmask flag for the drive
  64. #interrupt_unmask = on
  65. # -W Disable/enable the IDE drive's write-caching feature
  66. #write_cache = off
  67. # -X IDE transfer mode for newer (E)IDE/ATA2 drives
  68. #transfer_mode = 34
  69. # -y force to immediately enter the standby mode
  70. #standby
  71. # -Y force to immediately enter the sleep mode
  72. #sleep
  73. # -Z Disable the power-saving function of certain Seagate drives
  74. #disable_seagate
  75. # -M Set the acoustic management properties of a drive
  76. #acoustic_management
  77. # -p Set the chipset PIO mode
  78. # chipset_pio_mode
  79. # --security-freeze Freeze the drive's security status
  80. # security_freeze
  81. # --security-unlock Unlock the drive's security
  82. # security_unlock = PWD
  83. # --security-set-pass Set security password
  84. # security_pass = password
  85. # --security-disable Disable drive locking
  86. # security_disable
  87. # --user-master Select password to use
  88. # user-master = u
  89. # --security-mode Set the security mode
  90. # security_mode = h
  91. # Root file systems. Please see README.Debian for details
  92. # ROOTFS = /dev/hda
  93. ## New note - you can use straight hdparm commands in this config file
  94. ## as well - the set up is ugly, but it keeps backwards compatibility
  95. ## Additionally, it should be noted that any blocks that begin with
  96. ## the keyword 'command_line' are not run until after the root filesystem
  97. ## is mounted. This is done to avoid running blocks twice. If you need
  98. ## to run hdparm to set parameters for your root disk, please use the
  99. ## standard format.
  100. #Samples follow:
  101. #First three are good for devfs systems, fourth one for systems that do
  102. #not use devfs. The fifth example uses straight hdparm command line
  103. #syntax. Any of the blocks that use command line syntax must begin with
  104. #the keyword 'command_line', and no attempt is made to validate syntax.
  105. #It is provided for those more comfortable with hdparm syntax.
  106. #/dev/discs/disc0/disc {
  107. # mult_sect_io = 16
  108. # write_cache = off
  109. # spindown_time = 240
  110. #}
  111. #/dev/discs/disc1/disc {
  112. # mult_sect_io = 32
  113. # spindown_time = 36
  114. # write_cache = off
  115. #}
  116. #/dev/cdroms/cdrom0 {
  117. # dma = on
  118. # interrupt_unmask = on
  119. # io32_support = 0
  120. #}
  121. #/dev/hda {
  122. # mult_sect_io = 16
  123. # write_cache = off
  124. # dma = on
  125. #}
  126. #command_line {
  127. # hdparm -q -m16 -q -W0 -q -d1 /dev/hda
  128. #}