Disk IO performance monitoring (Linux and Windows)

Source: Internet
Author: User

Disk IO performance monitoring (Linux and Windows)


End South <[email protected]>


The IO performance of a disk is an important indicator of the overall performance of a computer. Linux provides the Iostat command to obtain the disk input/output (i.e. IO) statistics, Windows provides the WMI interface, you can write a simple script to get the function equivalent to Iostat.

1, Linux under the Iostat command

Iostat-d-k-t 2

The disk IO information is counted every 2 seconds until you press CTRL + C to terminate the program, and the-D option represents the statistics disk information,-K is displayed in kilobytes per second, and-T requires time information to be printed, and 2 indicates output every 2 seconds. The disk IO load status for the first output provides information about the statistics since the system started. Each subsequent output is the average IO load condition between each interval.

After running the command, the output:

Linux 2.6.9-67.0.7.ELSMP (Localhost.localdomain) 11/19/2008

Time:03:15:25 PM
Device:tps kb_read/s kb_wrtn/s Kb_read Kb_wrtn
SDA 3.53 26.66 54.76 30122033 61864280
SDA1 0.51 1.07 1.73 1207649 1949740
SDA2 0.00 0.00 0.00 538 256
Sda3 13.84 25.59 53.03 28913291 59914092

Time:03:15:27 PM
Device:tps kb_read/s kb_wrtn/s Kb_read Kb_wrtn
SDA 275.38 0.00 1738.69 0 3460
SDA1 14.57 0.00 58.29 0 116
SDA2 0.00 0.00 0.00 0 0
Sda3 419.60 0.00 1678.39 0 3340

...

The time information is printed each time the output is displayed, followed by a list of disk IO conditions.

Device: Displays the disk name
TPS: Indicates the number of transfers per second that are output to the physical disk. A single transfer is an I/O request to a physical disk. Multiple logical requests can be and are a single I/O request to disk. The transport has a medium size.
KB_READ/S: The amount of data read from disk per second, in kilobytes.
KB_WRTN/S: The amount of data written to disk per second, in kilobytes.
Kb_read: Total number of kilobytes read.
KB_WRTN: Total number of kilobytes written.

2. Win32_perfformatteddata_perfdisk_logicaldisk objects in WMI

Win32_perfformatteddata_perfdisk_logicaldisk represents a logical disk performance data object that can be used to obtain the heart-energy information of a disk. The Win32_perfformatteddata_perfdisk_logicaldisk object has some of the following main properties:

Name: Disk names
DISKTRANSFERSPERSEC: Number of disk transfers per second.
Diskreadbytespersec: The amount of data read from disk per second, in bytes.
Diskwritebytespersec: The amount of data read from disk per second, in bytes.
PercentFreeSpace: Percentage of available disks.

3, the use of Win32_perfformatteddata_perfdisk_logicaldisk precautions

When using Win32_perfformatteddata_perfdisk_logicaldisk, it is important to note:

(1) You cannot use objWMIService.ExecQuery to execute a Select statement to obtain disk performance data
(2) You must use Wbemscripting.swbemrefresher to join Win32_perfformatteddata_perfdisk_logicaldisk, and then call the Refresh method to refresh the data to obtain performance information
(3) The first time when the refresh, and can not obtain useful data, from the second start, to obtain the disk performance data
(4) The above problem is related to the mechanism of performance monitoring using counters in WMI

4. Use Example

To provide a good user interface for monitoring disk performance, you can use VBScript to write scripts to get disk performance data. The code for the script is as follows:

' Script File Name:DiskMonitor.vbs

StrComputer = "."
Set objWMIService = GetObject ("winmgmts:" _
& "{impersonationlevel=impersonate}!//" & strComputer & "/root/cimv2")
Set Objrefresher = CreateObject ("Wbemscripting.swbemrefresher")
Set coldisks = Objrefresher.addenum (objWMIService, "Win32_perfformatteddata_perfdisk_logicaldisk"). ObjectSet

If Wscript.Arguments.Count = 0 Then
Objrefresher.refresh
For each objdisk in Coldisks
WScript.Echo Objdisk.name & "& Objdisk.diskreadbytespersec &" "& Objdisk.diskwritebytespersec
Next
End If

If Wscript.Arguments.Count = 1 Then
Interval = CInt (wscript.arguments (0)) * 1000
Do While True
Objrefresher.refresh

WScript.Echo
WScript.Echo "Time:" & "" "& Time ()
WScript.Echo Formatstr ("Device:", 0) & Formatstr ("TPs", 7, 1) & Formatstr ("kb_read/s", 1) & Format STR ("kb_wrtn/s", 1) & Formatstr ("Free Space", 13, 1)

For each objdisk in Coldisks
WScript.Echo Formatstr (objdisk.name, 0) & Formatstr (Objdisk.disktransferspersec, 7, 1) & Formatstr ( Objdisk.diskreadbytespersec, 1) & Formatstr (Objdisk.diskwritebytespersec, 1) & Formatstr ( Objdisk.percentfreespace & "%", 13, 1)
Next
Wscript.Sleep Interval
Loop
End If

If Wscript.Arguments.Count = 2 Then
i = 0
Interval = CInt (wscript.arguments (0)) * 1000
Count = CInt (wscript.arguments (1))
Do While I < Count
Objrefresher.refresh

WScript.Echo
WScript.Echo "Time:" & "" "& Time ()
WScript.Echo Formatstr ("Device:", 0) & Formatstr ("TPs", 7, 1) & Formatstr ("kb_read/s", 1) & Format STR ("kb_wrtn/s", 1) & Formatstr ("Free Space", 13, 1)

For each objdisk in Coldisks
WScript.Echo Formatstr (objdisk.name, 0) & Formatstr (Objdisk.disktransferspersec, 7, 1) & Formatstr ( Objdisk.diskreadbytespersec, 1) & Formatstr (Objdisk.diskwritebytespersec, 1) & Formatstr ( Objdisk.percentfreespace & "%", 13, 1)
Next
Wscript.Sleep Interval
i = i + 1
Loop
End If

Function formatstr (str, tLen, direction)
Slen = Len (str)
Fstr = ""
num = Tlen-slen

j = 0
Do While J < num
Fstr = fstr & ""
j = j + 1
Loop

If Direction = 1 Then
FSTR = fstr & Str
Else
Fstr = str & FSTR
End If
Formatstr = Fstr
End Function


Examples of Use:

(1) CSCript Diskmonitor.vbs
The Win32_perfformatteddata_perfdisk_logicaldisk object is refreshed once, and no useful data is obtained.

(2) CSCript Diskmonitor.vbs 2
Get disk performance data once every 2 seconds and output until you press CTRL + C to terminate the program.

(3) CSCript diskmonitor.vbs 2 100
Get disk performance data and output every 2 seconds, fetch 100 times, and then exit.

The script outputs information including disktransferspersec, Diskreadbytespersec, Diskwritebytespersec, and PercentFreeSpace.

Reproduced:

Http://blog.csdn.net/magicbreaker/archive/2008/11/22/3351964.aspx

http://blog.csdn.net/forandever/article/details/5464902

Disk IO performance monitoring (Linux and Windows)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.