1
2
3
4
5
6
7
8
9
10
11
12
13
14 package nfs_test
15
16 import (
17 "reflect"
18 "strings"
19 "testing"
20
21 "github.com/prometheus/procfs/nfs"
22 )
23
24 func TestNewNFSdServerRPCStats(t *testing.T) {
25 tests := []struct {
26 name string
27 content string
28 stats *nfs.ServerRPCStats
29 invalid bool
30 }{
31 {
32 name: "invalid file",
33 content: "invalid",
34 invalid: true,
35 }, {
36 name: "good file, proc4ops 72",
37 content: `rc 0 6 18622
38 fh 0 0 0 0 0
39 io 157286400 0
40 th 8 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
41 ra 32 0 0 0 0 0 0 0 0 0 0 0
42 net 18628 0 18628 6
43 rpc 18628 0 0 0 0
44 proc2 18 2 69 0 0 4410 0 0 0 0 0 0 0 0 0 0 0 99 2
45 proc3 22 2 112 0 2719 111 0 0 0 0 0 0 0 0 0 0 0 27 216 0 2 1 0
46 proc4 2 2 10853
47 proc4ops 72 0 0 0 1098 2 0 0 0 0 8179 5896 0 0 0 0 5900 0 0 2 0 2 0 9609 0 2 150 1272 0 0 0 1236 0 0 0 0 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
48 wdeleg_getattr 16
49 `,
50 stats: &nfs.ServerRPCStats{
51 ReplyCache: nfs.ReplyCache{
52 Hits: 0,
53 Misses: 6,
54 NoCache: 18622,
55 },
56 FileHandles: nfs.FileHandles{
57 Stale: 0,
58 TotalLookups: 0,
59 AnonLookups: 0,
60 DirNoCache: 0,
61 NoDirNoCache: 0,
62 },
63 InputOutput: nfs.InputOutput{
64 Read: 157286400,
65 Write: 0,
66 },
67 Threads: nfs.Threads{
68 Threads: 8,
69 FullCnt: 0,
70 },
71 ReadAheadCache: nfs.ReadAheadCache{
72 CacheSize: 32,
73 CacheHistogram: []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
74 NotFound: 0,
75 },
76 Network: nfs.Network{
77 NetCount: 18628,
78 UDPCount: 0,
79 TCPCount: 18628,
80 TCPConnect: 6,
81 },
82 ServerRPC: nfs.ServerRPC{
83 RPCCount: 18628,
84 BadCnt: 0,
85 BadFmt: 0,
86 BadAuth: 0,
87 BadcInt: 0,
88 },
89 V2Stats: nfs.V2Stats{
90 Null: 2,
91 GetAttr: 69,
92 SetAttr: 0,
93 Root: 0,
94 Lookup: 4410,
95 ReadLink: 0,
96 Read: 0,
97 WrCache: 0,
98 Write: 0,
99 Create: 0,
100 Remove: 0,
101 Rename: 0,
102 Link: 0,
103 SymLink: 0,
104 MkDir: 0,
105 RmDir: 0,
106 ReadDir: 99,
107 FsStat: 2,
108 },
109 V3Stats: nfs.V3Stats{
110 Null: 2,
111 GetAttr: 112,
112 SetAttr: 0,
113 Lookup: 2719,
114 Access: 111,
115 ReadLink: 0,
116 Read: 0,
117 Write: 0,
118 Create: 0,
119 MkDir: 0,
120 SymLink: 0,
121 MkNod: 0,
122 Remove: 0,
123 RmDir: 0,
124 Rename: 0,
125 Link: 0,
126 ReadDir: 27,
127 ReadDirPlus: 216,
128 FsStat: 0,
129 FsInfo: 2,
130 PathConf: 1,
131 Commit: 0,
132 },
133 ServerV4Stats: nfs.ServerV4Stats{
134 Null: 2,
135 Compound: 10853,
136 },
137 V4Ops: nfs.V4Ops{
138 Op0Unused: 0,
139 Op1Unused: 0,
140 Op2Future: 0,
141 Access: 1098,
142 Close: 2,
143 Commit: 0,
144 Create: 0,
145 DelegPurge: 0,
146 DelegReturn: 0,
147 GetAttr: 8179,
148 GetFH: 5896,
149 Link: 0,
150 Lock: 0,
151 Lockt: 0,
152 Locku: 0,
153 Lookup: 5900,
154 LookupRoot: 0,
155 Nverify: 0,
156 Open: 2,
157 OpenAttr: 0,
158 OpenConfirm: 2,
159 OpenDgrd: 0,
160 PutFH: 9609,
161 PutPubFH: 0,
162 PutRootFH: 2,
163 Read: 150,
164 ReadDir: 1272,
165 ReadLink: 0,
166 Remove: 0,
167 Rename: 0,
168 Renew: 1236,
169 RestoreFH: 0,
170 SaveFH: 0,
171 SecInfo: 0,
172 SetAttr: 0,
173 SetClientID: 3,
174 SetClientIDConfirm: 3,
175 Verify: 0,
176 Write: 0,
177 RelLockOwner: 0,
178 },
179 WdelegGetattr: 16,
180 },
181 }, {
182 name: "good file, proc4ops 40",
183 content: `rc 0 25020854 19157796
184 fh 276 0 0 0 0
185 io 899844043 2470085989
186 th 1024 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
187 ra 2048 4250593 118232 55926 31504 20253 13815 9875 7028 5546 3991 171551
188 net 44179842 1 44179026 3092
189 rpc 44177753 0 0 0 0
190 proc2 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
191 proc3 22 747 7259760 1383711 1570520 3464939 8436 4688207 21668847 1173194 6457 2127 172 213538 1253 556401 14950 1101 56245 90790 742 367 1989658
192 proc4 2 0 0
193 proc4ops 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
194 wdeleg_getattr 9`,
195
196 stats: &nfs.ServerRPCStats{
197 ReplyCache: nfs.ReplyCache{
198 Hits: 0,
199 Misses: 25020854,
200 NoCache: 19157796,
201 },
202 FileHandles: nfs.FileHandles{
203 Stale: 276,
204 TotalLookups: 0,
205 AnonLookups: 0,
206 DirNoCache: 0,
207 NoDirNoCache: 0,
208 },
209 InputOutput: nfs.InputOutput{
210 Read: 899844043,
211 Write: 2470085989,
212 },
213 Threads: nfs.Threads{
214 Threads: 1024,
215 FullCnt: 0,
216 },
217 ReadAheadCache: nfs.ReadAheadCache{
218 CacheSize: 2048,
219 CacheHistogram: []uint64{4250593, 118232, 55926, 31504, 20253, 13815, 9875, 7028, 5546, 3991},
220 NotFound: 171551,
221 },
222 Network: nfs.Network{
223 NetCount: 44179842,
224 UDPCount: 1,
225 TCPCount: 44179026,
226 TCPConnect: 3092,
227 },
228 ServerRPC: nfs.ServerRPC{
229 RPCCount: 44177753,
230 BadCnt: 0,
231 BadFmt: 0,
232 BadAuth: 0,
233 BadcInt: 0,
234 },
235 V2Stats: nfs.V2Stats{
236 Null: 0,
237 GetAttr: 0,
238 SetAttr: 0,
239 Root: 0,
240 Lookup: 0,
241 ReadLink: 0,
242 Read: 0,
243 WrCache: 0,
244 Write: 0,
245 Create: 0,
246 Remove: 0,
247 Rename: 0,
248 Link: 0,
249 SymLink: 0,
250 MkDir: 0,
251 RmDir: 0,
252 ReadDir: 0,
253 FsStat: 0,
254 },
255 V3Stats: nfs.V3Stats{
256 Null: 747,
257 GetAttr: 7259760,
258 SetAttr: 1383711,
259 Lookup: 1570520,
260 Access: 3464939,
261 ReadLink: 8436,
262 Read: 4688207,
263 Write: 21668847,
264 Create: 1173194,
265 MkDir: 6457,
266 SymLink: 2127,
267 MkNod: 172,
268 Remove: 213538,
269 RmDir: 1253,
270 Rename: 556401,
271 Link: 14950,
272 ReadDir: 1101,
273 ReadDirPlus: 56245,
274 FsStat: 90790,
275 FsInfo: 742,
276 PathConf: 367,
277 Commit: 1989658,
278 },
279 ServerV4Stats: nfs.ServerV4Stats{
280 Null: 0,
281 Compound: 0,
282 },
283 V4Ops: nfs.V4Ops{
284 Op0Unused: 0,
285 Op1Unused: 0,
286 Op2Future: 0,
287 Access: 0,
288 Close: 0,
289 Commit: 0,
290 Create: 0,
291 DelegPurge: 0,
292 DelegReturn: 0,
293 GetAttr: 0,
294 GetFH: 0,
295 Link: 0,
296 Lock: 0,
297 Lockt: 0,
298 Locku: 0,
299 Lookup: 0,
300 LookupRoot: 0,
301 Nverify: 0,
302 Open: 0,
303 OpenAttr: 0,
304 OpenConfirm: 0,
305 OpenDgrd: 0,
306 PutFH: 0,
307 PutPubFH: 0,
308 PutRootFH: 0,
309 Read: 0,
310 ReadDir: 0,
311 ReadLink: 0,
312 Remove: 0,
313 Rename: 0,
314 Renew: 0,
315 RestoreFH: 0,
316 SaveFH: 0,
317 SecInfo: 0,
318 SetAttr: 0,
319 SetClientID: 0,
320 SetClientIDConfirm: 0,
321 Verify: 0,
322 Write: 0,
323 RelLockOwner: 0,
324 },
325 WdelegGetattr: 9,
326 },
327 },
328 {
329 name: "good file, proc4ops 59",
330 content: `rc 0 268 742119
331 fh 0 0 0 0 0
332 io 2476981939 0
333 th 8 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
334 ra 32 30104 0 0 0 0 0 0 0 0 0 71174
335 net 742701 314 742393 10103960
336 rpc 742406 310 310 0 0
337 proc2 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
338 proc3 22 105 71158 0 175642 184711 17103 101277 0 0 0 0 0 0 0 0 0 0 8916 102 202 0 0
339 proc4 2 101 182991
340 proc4ops 59 0 0 0 18112 8341 0 0 0 3239 71595 11834 0 0 0 0 107097 0 0 8344 0 5100 0 181968 0 235 5735 4406 0 0 0 652 8342 8344 0 0 134 134 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
341 wdeleg_getattr 10`,
342 stats: &nfs.ServerRPCStats{
343 ReplyCache: nfs.ReplyCache{
344 Hits: 0,
345 Misses: 268,
346 NoCache: 742119,
347 },
348 FileHandles: nfs.FileHandles{
349 Stale: 0,
350 TotalLookups: 0,
351 AnonLookups: 0,
352 DirNoCache: 0,
353 NoDirNoCache: 0,
354 },
355 InputOutput: nfs.InputOutput{
356 Read: 2476981939,
357 Write: 0,
358 },
359 Threads: nfs.Threads{
360 Threads: 8,
361 FullCnt: 0,
362 },
363 ReadAheadCache: nfs.ReadAheadCache{
364 CacheSize: 32,
365 CacheHistogram: []uint64{30104, 0, 0, 0, 0, 0, 0, 0, 0, 0},
366 NotFound: 71174,
367 },
368 Network: nfs.Network{
369 NetCount: 742701,
370 UDPCount: 314,
371 TCPCount: 742393,
372 TCPConnect: 10103960,
373 },
374 ServerRPC: nfs.ServerRPC{
375 RPCCount: 742406,
376 BadCnt: 310,
377 BadFmt: 310,
378 BadAuth: 0,
379 BadcInt: 0,
380 },
381 V2Stats: nfs.V2Stats{
382 Null: 0,
383 GetAttr: 0,
384 SetAttr: 0,
385 Root: 0,
386 Lookup: 0,
387 ReadLink: 0,
388 Read: 0,
389 WrCache: 0,
390 Write: 0,
391 Create: 0,
392 Remove: 0,
393 Rename: 0,
394 Link: 0,
395 SymLink: 0,
396 MkDir: 0,
397 RmDir: 0,
398 ReadDir: 0,
399 FsStat: 0,
400 },
401 V3Stats: nfs.V3Stats{
402 Null: 105,
403 GetAttr: 71158,
404 SetAttr: 0,
405 Lookup: 175642,
406 Access: 184711,
407 ReadLink: 17103,
408 Read: 101277,
409 Write: 0,
410 Create: 0,
411 MkDir: 0,
412 SymLink: 0,
413 MkNod: 0,
414 Remove: 0,
415 RmDir: 0,
416 Rename: 0,
417 Link: 0,
418 ReadDir: 0,
419 ReadDirPlus: 8916,
420 FsStat: 102,
421 FsInfo: 202,
422 PathConf: 0,
423 Commit: 0,
424 },
425 ServerV4Stats: nfs.ServerV4Stats{
426 Null: 101,
427 Compound: 182991,
428 },
429 V4Ops: nfs.V4Ops{
430 Op0Unused: 0,
431 Op1Unused: 0,
432 Op2Future: 0,
433 Access: 18112,
434 Close: 8341,
435 Commit: 0,
436 Create: 0,
437 DelegPurge: 0,
438 DelegReturn: 3239,
439 GetAttr: 71595,
440 GetFH: 11834,
441 Link: 0,
442 Lock: 0,
443 Lockt: 0,
444 Locku: 0,
445 Lookup: 107097,
446 LookupRoot: 0,
447 Nverify: 0,
448 Open: 8344,
449 OpenAttr: 0,
450 OpenConfirm: 5100,
451 OpenDgrd: 0,
452 PutFH: 181968,
453 PutPubFH: 0,
454 PutRootFH: 235,
455 Read: 5735,
456 ReadDir: 4406,
457 ReadLink: 0,
458 Remove: 0,
459 Rename: 0,
460 Renew: 652,
461 RestoreFH: 8342,
462 SaveFH: 8344,
463 SecInfo: 0,
464 SetAttr: 0,
465 SetClientID: 134,
466 SetClientIDConfirm: 134,
467 Verify: 0,
468 Write: 0,
469 RelLockOwner: 0,
470 },
471 WdelegGetattr: 10,
472 },
473 }, {
474 name: "good file, proc4ops 39",
475 content: `rc 0 25020854 19157796
476 fh 276 0 0 0 0
477 io 899844043 2470085989
478 th 1024 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
479 ra 2048 4250593 118232 55926 31504 20253 13815 9875 7028 5546 3991 171551
480 net 44179842 1 44179026 3092
481 rpc 44177753 0 0 0 0
482 proc2 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
483 proc3 22 747 7259760 1383711 1570520 3464939 8436 4688207 21668847 1173194 6457 2127 172 213538 1253 556401 14950 1101 56245 90790 742 367 1989658
484 proc4 2 0 0
485 proc4ops 39 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 39
486 wdeleg_getattr 765432`,
487 stats: &nfs.ServerRPCStats{
488 ReplyCache: nfs.ReplyCache{
489 Hits: 0,
490 Misses: 25020854,
491 NoCache: 19157796,
492 },
493 FileHandles: nfs.FileHandles{
494 Stale: 276,
495 TotalLookups: 0,
496 AnonLookups: 0,
497 DirNoCache: 0,
498 NoDirNoCache: 0,
499 },
500 InputOutput: nfs.InputOutput{
501 Read: 899844043,
502 Write: 2470085989,
503 },
504 Threads: nfs.Threads{
505 Threads: 1024,
506 FullCnt: 0,
507 },
508 ReadAheadCache: nfs.ReadAheadCache{
509 CacheSize: 2048,
510 CacheHistogram: []uint64{4250593, 118232, 55926, 31504, 20253, 13815, 9875, 7028, 5546, 3991},
511 NotFound: 171551,
512 },
513 Network: nfs.Network{
514 NetCount: 44179842,
515 UDPCount: 1,
516 TCPCount: 44179026,
517 TCPConnect: 3092,
518 },
519 ServerRPC: nfs.ServerRPC{
520 RPCCount: 44177753,
521 BadCnt: 0,
522 BadFmt: 0,
523 BadAuth: 0,
524 BadcInt: 0,
525 },
526 V2Stats: nfs.V2Stats{
527 Null: 0,
528 GetAttr: 0,
529 SetAttr: 0,
530 Root: 0,
531 Lookup: 0,
532 ReadLink: 0,
533 Read: 0,
534 WrCache: 0,
535 Write: 0,
536 Create: 0,
537 Remove: 0,
538 Rename: 0,
539 Link: 0,
540 SymLink: 0,
541 MkDir: 0,
542 RmDir: 0,
543 ReadDir: 0,
544 FsStat: 0,
545 },
546 V3Stats: nfs.V3Stats{
547 Null: 747,
548 GetAttr: 7259760,
549 SetAttr: 1383711,
550 Lookup: 1570520,
551 Access: 3464939,
552 ReadLink: 8436,
553 Read: 4688207,
554 Write: 21668847,
555 Create: 1173194,
556 MkDir: 6457,
557 SymLink: 2127,
558 MkNod: 172,
559 Remove: 213538,
560 RmDir: 1253,
561 Rename: 556401,
562 Link: 14950,
563 ReadDir: 1101,
564 ReadDirPlus: 56245,
565 FsStat: 90790,
566 FsInfo: 742,
567 PathConf: 367,
568 Commit: 1989658,
569 },
570 ServerV4Stats: nfs.ServerV4Stats{
571 Null: 0,
572 Compound: 0,
573 },
574 V4Ops: nfs.V4Ops{
575 Op0Unused: 0,
576 Op1Unused: 0,
577 Op2Future: 0,
578 Access: 0,
579 Close: 0,
580 Commit: 0,
581 Create: 0,
582 DelegPurge: 0,
583 DelegReturn: 0,
584 GetAttr: 0,
585 GetFH: 0,
586 Link: 0,
587 Lock: 0,
588 Lockt: 0,
589 Locku: 0,
590 Lookup: 0,
591 LookupRoot: 0,
592 Nverify: 0,
593 Open: 0,
594 OpenAttr: 0,
595 OpenConfirm: 0,
596 OpenDgrd: 0,
597 PutFH: 0,
598 PutPubFH: 0,
599 PutRootFH: 0,
600 Read: 0,
601 ReadDir: 0,
602 ReadLink: 0,
603 Remove: 0,
604 Rename: 0,
605 Renew: 0,
606 RestoreFH: 0,
607 SaveFH: 0,
608 SecInfo: 0,
609 SetAttr: 0,
610 SetClientID: 0,
611 SetClientIDConfirm: 0,
612 Verify: 0,
613 Write: 39,
614 RelLockOwner: 0,
615 },
616 WdelegGetattr: 765432,
617 },
618 },
619 }
620
621 for _, tt := range tests {
622 t.Run(tt.name, func(t *testing.T) {
623 stats, err := nfs.ParseServerRPCStats(strings.NewReader(tt.content))
624
625 if tt.invalid && err == nil {
626 t.Fatal("expected an error, but none occurred")
627 }
628 if !tt.invalid && err != nil {
629 t.Fatalf("unexpected error: %v", err)
630 }
631
632 if want, have := tt.stats, stats; !reflect.DeepEqual(want, have) {
633 t.Fatalf("unexpected NFS stats:\nwant:\n%v\nhave:\n%v", want, have)
634 }
635 })
636 }
637 }
638
View as plain text