| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
# nfsd global counters |
| 4 |
global nfsd_lookups |
| 5 |
global nfsd_reads |
| 6 |
global nfsd_writes |
| 7 |
global nfsd_creates |
| 8 |
global nfsd_commits |
| 9 |
global nfsd_removes |
| 10 |
|
| 11 |
# nfsd client tables |
| 12 |
global nfsd_lookup_clients |
| 13 |
global nfsd_lookup_clients_last_file |
| 14 |
global nfsd_read_clients |
| 15 |
global nfsd_write_clients |
| 16 |
|
| 17 |
# Accumulate lookup stats |
| 18 |
# Keep a count of lookups globally and by client_ip |
| 19 |
# also keep track of the last file looked up by each |
| 20 |
# client_ip |
| 21 |
probe nfsd.proc.lookup { |
| 22 |
nfsd_lookups <<< 1 |
| 23 |
nfsd_lookup_clients[client_ip] <<< 1 |
| 24 |
|
| 25 |
# If no command line argument is provided, remember the last |
| 26 |
# directory name and filename ('foo/bar.c') of the lookup. If |
| 27 |
# a command line argument was provided, remember the full |
| 28 |
# pathname of the last lookup ('/home/user/foo/bar.c'). |
| 29 |
%( $# == 0 %? |
| 30 |
nfsd_lookup_clients_last_file[client_ip] |
| 31 |
= sprintf("%s/%s", d_name(fh->fh_dentry), filename) |
| 32 |
%: |
| 33 |
nfsd_lookup_clients_last_file[client_ip] |
| 34 |
= sprintf("%s/%s", |
| 35 |
task_dentry_path(task_current(), |
| 36 |
fh->fh_dentry, |
| 37 |
fh->fh_export->ex_path->mnt), |
| 38 |
filename) |
| 39 |
%) |
| 40 |
} |
| 41 |
|
| 42 |
# Accumulate read stats |
| 43 |
# Keep a count of reads globally and by client_ip |
| 44 |
# also keep track of the number of bytes read globally |
| 45 |
# and per-client_ip |
| 46 |
probe nfsd.proc.read { |
| 47 |
nfsd_reads <<< size |
| 48 |
nfsd_read_clients[client_ip] <<< size |
| 49 |
} |
| 50 |
|
| 51 |
# Accumulate write stats |
| 52 |
# Keep a count of writes globally and by client_ip |
| 53 |
# also keep track of the number of bytes writen globally |
| 54 |
# and per-client_ip |
| 55 |
probe nfsd.proc.write { |
| 56 |
nfsd_writes <<< size |
| 57 |
nfsd_write_clients[client_ip] <<< size |
| 58 |
} |
| 59 |
|
| 60 |
# Just count creates for now |
| 61 |
probe nfsd.proc.create { |
| 62 |
nfsd_creates <<< 1 |
| 63 |
} |
| 64 |
|
| 65 |
# Just count commits for now |
| 66 |
probe nfsd.proc.commit { |
| 67 |
nfsd_commits <<< 1 |
| 68 |
} |
| 69 |
|
| 70 |
# Just count removes for now |
| 71 |
probe nfsd.proc.remove { |
| 72 |
nfsd_removes <<< 1 |
| 73 |
} |
| 74 |
|
| 75 |
# This is our "main loop" executed once every $interval |
| 76 |
# We clear the terminal (top-style screen updates) and then |
| 77 |
# to write out all our stats areas as fast as possible. |
| 78 |
# Currently there are three sections: |
| 79 |
# |
| 80 |
# Global stats |
| 81 |
# Top 10 lookup clients |
| 82 |
# Top 10 reading clients |
| 83 |
# Top 10 writing clients |
| 84 |
# |
| 85 |
probe timer.ms(1000) |
| 86 |
{ |
| 87 |
ansi_clear_screen() |
| 88 |
print("\n") |
| 89 |
printf("lookups : %8d\n", @count(nfsd_lookups)) |
| 90 |
printf("reads : %8d\n", @count(nfsd_reads)) |
| 91 |
printf("r/bytes : %8d KiB\n", @sum(nfsd_reads) >> 10) |
| 92 |
printf("writes : %8d\n", @count(nfsd_writes)) |
| 93 |
printf("w/bytes : %8d KiB\n", @sum(nfsd_writes) >> 10) |
| 94 |
printf("creates : %8d\n", @count(nfsd_creates)) |
| 95 |
printf("commits : %8d\n", @count(nfsd_commits)) |
| 96 |
printf("removes : %8d\n", @count(nfsd_removes)) |
| 97 |
printf("\n") |
| 98 |
print("lookups\n") |
| 99 |
printf("client\t\t\tlast file\n") |
| 100 |
foreach (ip in nfsd_lookup_clients- limit 10) |
| 101 |
printf("%s\t%s\n", ip, nfsd_lookup_clients_last_file[ip]) |
| 102 |
print("\n") |
| 103 |
print("reads\n") |
| 104 |
printf("client\t\t\treads\tbytes\n") |
| 105 |
foreach (ip in nfsd_read_clients- limit 10) |
| 106 |
printf("%s\t%d\t%d\n", ip, @count(nfsd_read_clients[ip]), |
| 107 |
@sum(nfsd_read_clients[ip])) |
| 108 |
print("\n") |
| 109 |
printf("writes\n") |
| 110 |
printf("client\t\t\twrites\tbytes\n") |
| 111 |
foreach (ip in nfsd_write_clients- limit 10) |
| 112 |
printf("%s\t%d\t%d\n", ip, @count(nfsd_write_clients[ip]), |
| 113 |
@sum(nfsd_write_clients[ip])) |
| 114 |
|
| 115 |
delete nfsd_lookups |
| 116 |
delete nfsd_reads |
| 117 |
delete nfsd_writes |
| 118 |
delete nfsd_creates |
| 119 |
delete nfsd_commits |
| 120 |
delete nfsd_removes |
| 121 |
|
| 122 |
delete nfsd_lookup_clients |
| 123 |
delete nfsd_lookup_clients_last_file |
| 124 |
delete nfsd_read_clients |
| 125 |
delete nfsd_write_clients |
| 126 |
} |