nfsv3io.d Reports Host I/O

This is a simple DTrace script to provide basic I/O details by host every 5 seconds:

#!/usr/sbin/dtrace -s

#pragma D option quiet

dtrace:::BEGIN
{
        interval = 5;
        printf("Tracing... Interval %d secs.\n", interval);
        tick = interval;
}

nfsv3:::op-*
{
        @ops[args[0]->ci_remote] = count();
}

nfsv3:::op-read-done
{
        @reads[args[0]->ci_remote] = count();
        @readbytes[args[0]->ci_remote] = sum(args[2]->res_u.ok.data.data_len);
}


nfsv3:::op-write-done
{
        @writes[args[0]->ci_remote] = count();
        @writebytes[args[0]->ci_remote] = sum(args[2]->res_u.ok.count);
}

profile:::tick-1sec
/tick-- == 0/
{
        normalize(@ops, interval);
        normalize(@reads, interval);
        normalize(@writes, interval);
        normalize(@writebytes, 1024 * interval);
        normalize(@readbytes, 1024 * interval);
        printf("\n   %-32s %6s %6s %6s %6s %8s\n", "Client", "r/s", "w/s",
            "kr/s", "kw/s", "ops/s");
        printa("   %-32s %@6d %@6d %@6d %@6d %@8d\n", @reads, @writes,
            @readbytes, @writebytes, @ops);
        trunc(@ops);
        trunc(@reads);
        trunc(@writes);
        trunc(@readbytes);
        trunc(@writebytes);
        tick = interval;
}

This output shows 192.0.2.75 calling NFS version 3 reads and writes:

# ./nfsv3io.d
Tracing... Interval 5 secs.

   Client                            r/s    w/s   kr/s   kw/s    ops/s
   192.0.2.75                        27      1    686     40      100

   Client                            r/s    w/s   kr/s   kw/s    ops/s
   192.0.2.75                         0      0      0      0        8

   Client                            r/s    w/s   kr/s   kw/s    ops/s
   0.0.0.0                            0      0      0      0        0
   192.0.2.75                         2      0     28      0       18
^C

Other details can be calculated from the output, such as average read and write size, for example, 686(kr/s) / 27(r/s) = 25.4 average kr. These could also be added to the script to be printed as columns.

The fields printed are:

Field Description

Client

Remote client IP address

r/s

reads per second

w/s

writes per second

kr/s

kilobytes read per second

kw/s

kilobytes written per second

ops/s

Total NFSv3 operations per second (including the reads and writes)