-
Notifications
You must be signed in to change notification settings - Fork 9
/
nfs3-mon.d
executable file
·248 lines (221 loc) · 7.1 KB
/
nfs3-mon.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/sbin/dtrace -Cs
#pragma D option quiet
#pragma D option defaultargs
#pragma D option dynvarsize=64m
/*
* Give a traffic overview for an NFS fileserver every ten seconds.
* Specialized to CSLab's environment.
*
* usage: nfs3-mon.d [verbosity]
*
* verbosity 1 adds some extra activity breakdowns.
*
* Information on what gets reported:
* - writes are broken down into different categories depending on the
* NFS v3 'stable' setting. These are plain writes (no stability
* required), 'write (data sync)' aka DATA_SYNC, and 'write (file
* sync)' aka FILE_SYNC.
*
* The 'currently outstanding' information is an instantaneous snapshot.
* All other information is aggregated over ten seconds. Note that size
* are *not* MB/second, they are total MBs; divide by ten to get a per-second
* figure.
*
* Written by Chris Siebenmann
* https://github.com/siebenmann/cks-dtrace/
*/
/* SOLARIS VERSION DEPENDENCY:
* Go from a znode to the name of the pool it is in.
* If you get an error 'os is not a member of struct objset',
* try using the commented-out version instead (it drops the
* '->os' bit).
*/
/* #define ZNODE_TO_POOLNAME(ZN) ((string) ZN->z_zfsvfs->z_os->os->os_spa->spa_name) */
#define ZNODE_TO_POOLNAME(ZN) ((string) ZN->z_zfsvfs->z_os->os_spa->spa_name)
BEGIN
{
/* BRUTE FORCE TRIUMPHS */
names["128.100.3.90"] = "aviary";
names["128.100.3.96"] = "dcsimap";
names["128.100.3.40"] = "apps0";
names["128.100.3.41"] = "apps1";
names["128.100.3.42"] = "apps2";
names["128.100.3.43"] = "apps3";
names["128.100.3.37"] = "oldapps";
names["128.100.3.83"] = "dcssmb-3";
names["128.100.3.117"] = "dcsosmb-3";
names["128.100.3.84"] = "smb-3";
names["128.100.3.30"] = "colony";
names["128.100.1.10"] = "settlement";
names["128.100.3.218"] = "arsenal";
names["128.100.3.35"] = "armoury";
names["128.100.3.124"] = "mailswitch";
names["128.100.3.180"] = "pwmaster";
names["128.100.3.150"] = "comps0";
names["128.100.3.151"] = "comps1";
names["128.100.3.152"] = "comps2";
names["128.100.3.153"] = "comps3";
names["128.100.3.154"] = "comps4";
names["128.100.3.100"] = "compsbk0";
names["128.100.3.102"] = "compsbk1";
names["128.100.3.103"] = "compsbk2";
names["128.100.3.104"] = "compsbk3";
names["128.100.3.105"] = "compsbk4";
names["128.100.3.106"] = "compsbk5";
/* this is the stable_how enum */
wtypes[0] = "writes"; /* UNSTABLE */
wtypes[1] = "writes (data sync)"; /* DATA_SYNC */
wtypes[2] = "writes (file sync)"; /* FILE_SYNC */
verbose = $1;
topn = verbose > 0 ? 5: 3;
vnl = verbose ? "\n" : "";
ztype = `zfsfstype;
}
fbt::rfs3_read:entry
{
self->dir = "reads";
}
fbt::rfs3_write:entry
{
self->dir = wtypes[args[0]->stable];
}
fbt::rfs3_commit:entry
{
self->dir = "commits";
}
fbt::rfs3_read:entry, fbt::rfs3_write:entry, fbt::rfs3_commit:entry
{
self->in_rfs3 = 1;
self->count = args[0]->count;
self->req = args[3];
self->uid = args[4]->cr_uid;
self->fs = (string)args[2]->exi_export.ex_path;
self->ts = timestamp;
this->socket =
(struct sockaddr_in *)self->req->rq_xprt->xp_xpc.xpc_rtaddr.buf;
/* Generate a printable IPv4 address from a sockaddr_in structure.
This magic is taken from nfsv3fbtrws.d in the DTrace book.
More modern versions of DTrace have convenience functions that
do this for us. - cks */
this->a = (uint8_t *)&this->socket->sin_addr.S_un.S_addr;
this->addr1 = strjoin(lltostr(this->a[0] + 0ULL), strjoin(".",
strjoin(lltostr(this->a[1] + 0ULL), ".")));
this->addr2 = strjoin(lltostr(this->a[2] + 0ULL), strjoin(".",
lltostr(this->a[3] + 0ULL)));
self->address = strjoin(this->addr1, this->addr2);
self->address = names[self->address] != 0 ? names[self->address] : self->address;
@curops = sum(1);
@opsc[self->dir] = sum(1);
@opsz[self->dir] = sum(self->count);
}
/*
* nfs3_fhtovp can fail, eg on a stale filehandle, and in
* that case we can't go digging for the pool et al.
*/
fbt::nfs3_fhtovp:return
/self->in_rfs3 && args[1]/
{
self->vp = args[1];
/* Ugly simplification */
this->fst = self->vp->v_vfsp->vfs_fstype;
this->znode = (znode_t *)self->vp->v_data;
self->pool = this->fst == ztype ?
stringof(ZNODE_TO_POOLNAME(this->znode)) :
strjoin("non-ZFS fstype ", stringof(`vfssw[this->fst].vsw_name));
/* guard against repeated calls to nfs3_fhtovp() just in case. */
self->in_rfs3 = 0;
}
/*
* We can only trace requests where nfs3_fhtovp() succeeded.
* Such requests have a timestamp but had in_rfs3 turned off
* above.
*/
fbt::rfs3_read:return, fbt::rfs3_write:return, fbt::rfs3_commit:return
/ self->ts > 0 && !self->in_rfs3 /
{
@fsuser[self->fs, self->uid] = sum(self->count);
@fsclient[self->fs, self->address] = sum(self->count);
@fs[self->fs] = sum(self->count);
@user[self->uid] = sum(self->count);
@client[self->address] = sum(self->count);
@matrix[self->fs, self->uid, self->address] = sum(self->count);
@dir[self->dir] = sum(self->count);
@counts[self->dir] = count();
@pools[self->pool] = sum(self->count);
}
/*
* We must count and clear out *all* ops, even the ones where invalid
* filehandles happened.
*/
fbt::rfs3_read:return, fbt::rfs3_write:return, fbt::rfs3_commit:return
/ self->ts > 0 /
{
@curops = sum(-1);
@opsc[self->dir] = sum(-1);
@opsz[self->dir] = sum(-self->count);
self->in_rfs3 = 0;
self->count = 0;
self->req = 0;
self->uid = 0;
self->dir = 0;
self->ts = 0;
self->pool = 0;
self->address = 0;
}
/* quick hack. this really belongs in a ZFS stats DTrace script */
fbt::zil_lwb_write_start:entry
{
this->syncpool = (string) args[0]->zl_dmu_pool->dp_spa->spa_name;
/* @zilsync[this->syncpool] = count(); */
}
tick-10sec
/ verbose == 0 /
{
trunc(@fsuser, 0);
trunc(@fsclient, 0);
trunc(@user, 0);
trunc(@fs, 0);
}
tick-10sec
{
printf("\n%Y (10 second totals):\n", walltimestamp);
trunc(@fsuser, topn); normalize(@fsuser, (1024*1024));
trunc(@fsclient, topn); normalize(@fsclient, (1024*1024));
trunc(@fs, topn); normalize(@fs, (1024*1024));
trunc(@user, topn); normalize(@user, (1024*1024));
trunc(@client, topn); normalize(@client, (1024*1024));
trunc(@matrix, 5); normalize(@matrix, (1024*1024));
trunc(@pools, topn); normalize(@pools, (1024*1024));
normalize(@dir, (1024*1024));
normalize(@opsz, (1024*1024));
printa("currently outstanding: %@d NFS request(s)\n ", @curops);
printa(" %@d / %@d MB %s", @opsc, @opsz); printf("\n\n");
denormalize(@opsz);
printa(" %@5d MB in %@4d %s\n", @dir, @counts); printf("\n");
printa("%@6d MB %-8s uid %5d on %-s\n", @matrix); printf("\n");
printa("%@6d MB %s\n", @pools); printf("\n");
printa("%@6d MB %-8s uid %5d\n", @fsuser); printf("%s", vnl);
printa("%@6d MB %-8s from %-15s\n", @fsclient); printf("%s", vnl);
printa("%@6d MB %s\n", @fs); printf("%s", vnl);
printa("%@6d MB %s\n", @client); printf("\n");
printa("%@6d MB uid %5d\n", @user); printf("%s", vnl);
/* trunc(@zilsync, topn);
printa("%@6d ZIL writes in %s\n", @zilsync); printf("\n"); */
}
/*
* We truncate everything at END so that it isn't printed out one last
* time (badly).
*/
tick-10sec, END
{
/* trunc(@zilsync); */
trunc(@fsuser);
trunc(@fsclient);
trunc(@fs);
trunc(@user);
trunc(@client);
trunc(@matrix);
trunc(@dir);
trunc(@counts);
trunc(@pools);
}