Disk I/O performance monitoring (Linux and Windows)

Source: Internet
Author: User

Disk I/O performance is an important indicator to measure the overall performance of computers. Linux provides the iostat command to obtain disk input/output (I/O) statistics, while Windows provides the WMI interface, you can write a simple script to obtain functions equivalent to iostat.

1. Linux iostat command

Iostat-D-K-T 2

Calculate the disk Io information every 2 seconds until you press Ctrl + C to terminate the program. The-D option indicates the disk information statistics, and the-k indicates that the disk information is displayed in KB per second, -T requires that the time information be printed. 2 indicates that the time is output every 2 seconds. The disk I/O Load Status output for the first time provides statistics about the disk I/O load since the system was started. Each subsequent output is the average Io load between each interval.

After running this command, output:

Linux 2.6.9-67.0.7.elsmp (localhost. localdomain) 11/19/2008

Time: 03:15:25
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
Sda2 0.00 0.00 0.00 538
Sda3 13.84 25.59 53.03 28913291

Time: 03:15:27
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 disk I/O status list is displayed next.

Device: displays the disk name.
TPS: the number of transfers that are output to the physical disk per second. One transmission is an I/O Request to a physical disk. Multiple logical requests can be combined as a single I/O Request to the disk. Transmission has a medium size.
Kb_read/s: the amount of data read from the disk per second, in KB.
Kb_wrtn/s: the amount of data written to the disk per second, in KB.
Kb_read: Total number of KB read.
Kb_wrtn: Total number of KB written.

2. win32_perfformatteddata_perfdisk_logicaldisk object in WMI

Win32_perfformatteddata_perfdisk_logicaldisk represents the Logical Disk performance data object, which can be used to obtain the core information of the disk. The win32_perfformatteddata_perfdisk_logicaldisk object has the following main attributes:

Name: disk name
Disktransferspersec: the number of disk transfers per second.
Diskreadbytespersec: the amount of data read from the disk per second, measured in bytes.
Diskwritebytespersec: the amount of data read from the disk per second, measured in bytes.
Percentfreespace: percentage of available disks.

3. Precautions for using win32_perfformatteddata_perfdisk_logicaldisk

Note the following before using win32_perfformatteddata_perfdisk_logicaldisk:

(1) You cannot use obw.miservice. execquery to execute the SELECT statement to obtain disk performance data.
(2) You must use wbemscripting. swbemrefresher to add win32_perfformatteddata_perfdisk_logicaldisk, and then call the refresh method to refresh data to obtain performance information.
(3) No useful data can be obtained during the first refresh. the disk performance data can be obtained from the second refresh.
(4) the above problems are related to the counter mechanism used by WMI Performance Monitoring.

4. Example

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

'Script file name: diskmonitor. vbs

Strcomputer = "."
Set ob1_miservice = GetObject ("winmgmts :"_
& "{Impersonationlevel = impersonate }! \ "& Strcomputer &" \ Root \ cimv2 ")
Set objrefresher = Createobject ("wbemscripting. swbemrefresher ")
Set coldisks = objrefresher. addenum (ob1_miservice, "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:", 15, 0) & formatstr ("TPS", 7, 1) & formatstr ("kb_read/s", 13, 1) & formatstr ("kb_wrtn/s", 13, 1) & formatstr ("free space", 13, 1)

For each objdisk in coldisks
Wscript. echo formatstr (objdisk. name, 15, 0) & formatstr (objdisk. disktransferspersec, 7, 1) & formatstr (objdisk. diskreadbytespersec, 13, 1) & formatstr (objdisk. diskwritebytespersec, 13, 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:", 15, 0) & formatstr ("TPS", 7, 1) & formatstr ("kb_read/s", 13, 1) & formatstr ("kb_wrtn/s", 13, 1) & formatstr ("free space", 13, 1)

For each objdisk in coldisks
Wscript. echo formatstr (objdisk. name, 15, 0) & formatstr (objdisk. disktransferspersec, 7, 1) & formatstr (objdisk. diskreadbytespersec, 13, 1) & formatstr (objdisk. diskwritebytespersec, 13, 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

Example:

(1) cscript diskmonitor. vbs
Only one win32_perfformatteddata_perfdisk_logicaldisk object is refreshed, and no useful data is obtained.

(2) cscript diskmonitor. vbs 2
Obtain and output the disk performance data every 2 seconds until you press Ctrl + C to terminate the program.

(3) cscript diskmonitor. vbs 2 100
Obtain the disk performance data and output the data every 2 seconds. Obtain the data for a total of 100 times and then exit.

The output information includes disktransferspersec, diskreadbytespersec, diskwritebytespersec, and percentfreespace.

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.