forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfsclient_test.go
205 lines (175 loc) · 5.9 KB
/
nfsclient_test.go
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
package nfsclient
import (
"bufio"
"os"
"strings"
"testing"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)
func getMountStatsPath() string {
path := "./testdata/mountstats"
if os.Getenv("MOUNT_PROC") != "" {
path = os.Getenv("MOUNT_PROC")
}
return path
}
func TestNFSClientParsev3(t *testing.T) {
var acc testutil.Accumulator
nfsclient := NFSClient{Fullstat: true}
nfsclient.nfs3Ops = map[string]bool{"READLINK": true, "GETATTR": false}
nfsclient.nfs4Ops = map[string]bool{"READLINK": true, "GETATTR": false}
data := strings.Fields(" READLINK: 500 501 502 503 504 505 506 507")
err := nfsclient.parseStat("1.2.3.4:/storage/NFS", "/A", "3", data, &acc)
require.NoError(t, err)
fieldsOps := map[string]interface{}{
"ops": uint64(500),
"trans": uint64(501),
"timeouts": uint64(502),
"bytes_sent": uint64(503),
"bytes_recv": uint64(504),
"queue_time": uint64(505),
"response_time": uint64(506),
"total_time": uint64(507),
}
acc.AssertContainsFields(t, "nfs_ops", fieldsOps)
}
func TestNFSClientParsev4(t *testing.T) {
var acc testutil.Accumulator
nfsclient := NFSClient{Fullstat: true}
nfsclient.nfs3Ops = map[string]bool{"DESTROY_SESSION": true, "GETATTR": false}
nfsclient.nfs4Ops = map[string]bool{"DESTROY_SESSION": true, "GETATTR": false}
data := strings.Fields(" DESTROY_SESSION: 500 501 502 503 504 505 506 507")
err := nfsclient.parseStat("2.2.2.2:/nfsdata/", "/B", "4", data, &acc)
require.NoError(t, err)
fieldsOps := map[string]interface{}{
"ops": uint64(500),
"trans": uint64(501),
"timeouts": uint64(502),
"bytes_sent": uint64(503),
"bytes_recv": uint64(504),
"queue_time": uint64(505),
"response_time": uint64(506),
"total_time": uint64(507),
}
acc.AssertContainsFields(t, "nfs_ops", fieldsOps)
}
func TestNFSClientParseLargeValue(t *testing.T) {
var acc testutil.Accumulator
nfsclient := NFSClient{Fullstat: true}
nfsclient.nfs3Ops = map[string]bool{"SETCLIENTID": true, "GETATTR": false}
nfsclient.nfs4Ops = map[string]bool{"SETCLIENTID": true, "GETATTR": false}
data := strings.Fields(" SETCLIENTID: 218 216 0 53568 12960 18446744073709531008 134 197")
err := nfsclient.parseStat("2.2.2.2:/nfsdata/", "/B", "4", data, &acc)
require.NoError(t, err)
fieldsOps := map[string]interface{}{
"ops": uint64(218),
"trans": uint64(216),
"timeouts": uint64(0),
"bytes_sent": uint64(53568),
"bytes_recv": uint64(12960),
"queue_time": uint64(18446744073709531008),
"response_time": uint64(134),
"total_time": uint64(197),
}
acc.AssertContainsFields(t, "nfs_ops", fieldsOps)
}
func TestNFSClientProcessStat(t *testing.T) {
var acc testutil.Accumulator
nfsclient := NFSClient{}
nfsclient.Fullstat = false
file, _ := os.Open(getMountStatsPath())
defer file.Close()
scanner := bufio.NewScanner(file)
err := nfsclient.processText(scanner, &acc)
require.NoError(t, err)
fieldsReadstat := map[string]interface{}{
"ops": uint64(600),
"retrans": uint64(1),
"bytes": uint64(1207),
"rtt": uint64(606),
"exe": uint64(607),
}
readTags := map[string]string{
"serverexport": "1.2.3.4:/storage/NFS",
"mountpoint": "/A",
"operation": "READ",
}
acc.AssertContainsTaggedFields(t, "nfsstat", fieldsReadstat, readTags)
fieldsWritestat := map[string]interface{}{
"ops": uint64(700),
"retrans": uint64(1),
"bytes": uint64(1407),
"rtt": uint64(706),
"exe": uint64(707),
}
writeTags := map[string]string{
"serverexport": "1.2.3.4:/storage/NFS",
"mountpoint": "/A",
"operation": "WRITE",
}
acc.AssertContainsTaggedFields(t, "nfsstat", fieldsWritestat, writeTags)
}
func TestNFSClientProcessFull(t *testing.T) {
var acc testutil.Accumulator
nfsclient := NFSClient{}
nfsclient.Fullstat = true
file, _ := os.Open(getMountStatsPath())
defer file.Close()
scanner := bufio.NewScanner(file)
err := nfsclient.processText(scanner, &acc)
require.NoError(t, err)
fieldsEvents := map[string]interface{}{
"inoderevalidates": uint64(301736),
"dentryrevalidates": uint64(22838),
"datainvalidates": uint64(410979),
"attrinvalidates": uint64(26188427),
"vfsopen": uint64(27525),
"vfslookup": uint64(9140),
"vfsaccess": uint64(114420),
"vfsupdatepage": uint64(30785253),
"vfsreadpage": uint64(5308856),
"vfsreadpages": uint64(5364858),
"vfswritepage": uint64(30784819),
"vfswritepages": uint64(79832668),
"vfsgetdents": uint64(170),
"vfssetattr": uint64(64),
"vfsflush": uint64(18194),
"vfsfsync": uint64(29294718),
"vfslock": uint64(0),
"vfsrelease": uint64(18279),
"congestionwait": uint64(0),
"setattrtrunc": uint64(2),
"extendwrite": uint64(785551),
"sillyrenames": uint64(0),
"shortreads": uint64(0),
"shortwrites": uint64(0),
"delay": uint64(0),
"pnfsreads": uint64(0),
"pnfswrites": uint64(0),
}
fieldsBytes := map[string]interface{}{
"normalreadbytes": uint64(204440464584),
"normalwritebytes": uint64(110857586443),
"directreadbytes": uint64(783170354688),
"directwritebytes": uint64(296174954496),
"serverreadbytes": uint64(1134399088816),
"serverwritebytes": uint64(407107155723),
"readpages": uint64(85749323),
"writepages": uint64(30784819),
}
fieldsXprtTCP := map[string]interface{}{
"bind_count": uint64(1),
"connect_count": uint64(1),
"connect_time": uint64(0),
"idle_time": uint64(0),
"rpcsends": uint64(96172963),
"rpcreceives": uint64(96172963),
"badxids": uint64(0),
"inflightsends": uint64(620878754),
"backlogutil": uint64(0),
}
acc.AssertContainsFields(t, "nfs_events", fieldsEvents)
acc.AssertContainsFields(t, "nfs_bytes", fieldsBytes)
acc.AssertContainsFields(t, "nfs_xprt_tcp", fieldsXprtTCP)
}