szaydel
1/8/2014 - 4:15 PM

Get a quick sense for IO sizes and amount of IO done. This is not per device, rather aggregate numbers for all devices. Output looks like t

Get a quick sense for IO sizes and amount of IO done. This is not per device, rather aggregate numbers for all devices. Output looks like this:

1389197943,0,156,0,0,527,0,3459 1389197944,0,0,0,0,0,0,0 1389197945,0,0,0,0,0,0,0 1389197946,0,0,0,0,0,0,0 1389197947,0,0,0,0,0,0,0 1389197948,0,153,0,0,518,0,3466

#!/usr/sbin/dtrace -s
#pragma D option quiet

/*
The MIT License (MIT)

Copyright (c) 2014 RackTop Systems

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

The purpose of the script is to return CSV formatted data summary about IO
happening on the system. We are using fairly generic io:: probes and so there is
not any awareness of filesystems, specific filesystem operations, etc.

We are not interested in directory paths, file information or anything else
filesystem-related.

All that we care about with this script are these datapoints in that order:
timestamp, read IO, write IO, Async IO, Read KBytes, Write Kbytes, Average Read Size,
Average Write Size.
*/

BEGIN 
{
    rio = 0; 
    wio = 0; 
    aio = 0;
    rbytes = 0;
    wbytes = 0;
}

io:::start 
{
    args[0]->b_flags & B_READ ? rio++ : 0; 
    args[0]->b_flags & B_WRITE ? wio++ : 0; 
    args[0]->b_flags & B_ASYNC ? aio++ : 0;

    args[0]->b_flags & B_READ ? rbytes += args[0]->b_bcount : 0; 
    args[0]->b_flags & B_WRITE ? wbytes += args[0]->b_bcount : 0; 
}

tick-1s 
{
    /* Read Bytes and Write Bytes are printed in KB, i.e. XX bytes / 1024. */
    printf("%d,%d,%d,%d,%d,%d,%d,%d\n", walltimestamp / 1000000000, 
        rio, wio, aio, rbytes / 1024, wbytes / 1024, rbytes > 0 ? rbytes / rio : 0, 
        wbytes > 0 ? wbytes / wio : 0); /* This gives a clean CSV output. */
    
    /* Use next commented-out line if you require user-friendly output. */
    /* printf("%Y: reads :%8d, writes :%8d, async-ios :%8d, rbytes :%8d, wbytes :%8d, avg_rbytes :%8d, avg_wbytes :%8d\n", 
        walltimestamp, rio, wio, aio, rbytes / 1024, wbytes / 1024, 
        rbytes > 0 ? rbytes / rio : 0, 
        wbytes > 0 ? wbytes / wio : 0); */

    rio = 0; 
    wio = 0; 
    aio = 0;
    rbytes = 0;
    wbytes = 0;
}