Disk IO performance monitoring (Linux and Windows)

Source: Internet
Author: User
Tags sleep

The IO performance of a disk is an important indicator of the overall performance of the computer. Linux provides the IOSTAT command to obtain disk input/output (i.e. IO) statistics, and Windows provides a WMI interface that allows you to write a simple script to get the functionality that is 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, the-D option indicates the statistics disk information, the-K representation is in kilobytes per second,-T requires time information to print out, and 2 indicates output every 2 seconds. The first output of the disk IO load condition provides statistics about the time since the system started. Each subsequent output is the average IO load status 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

...

Each output prints the time information, followed by a list of disk IO conditions.

Device: Display disk name
TPS: Represents the number of transfers per second to the physical disk. One transmission is an I/O request to a physical disk. Multiple logical requests can be and are a single I/O request to the 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 per second from the disk, in kilobytes.
Kb_read: Total number of kilobytes read.
KB_WRTN: Total number of kilobytes written.

2. Win32_perfformatteddata_perfdisk_logicaldisk objects in WMI

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

Name: Disk names
Disktransferspersec: The 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 considerations

When using Win32_perfformatteddata_perfdisk_logicaldisk, you need to be aware of:

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

4, the use of examples

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 & "Rootcimv2")
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 spaces", 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 spaces", 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


Use examples:

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

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

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

The information that the script outputs includes disktransferspersec, Diskreadbytespersec, Diskwritebytespersec, and PercentFreeSpace.

IO output is another indicator of server performance. Now very web site open slow but broadband is OK, this situation may be disk IO performance problems, Linux this aspect do very well will use faster, page windows is more and more slow.

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.