blob: 95a83cc5bc5f992aab355757d19a501e32a5ebcf [file] [log] [blame]
khenaidooffe076b2019-01-15 16:08:08 -05001// Copyright 2018 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package nfs
15
16import (
17 "fmt"
18)
19
20func parseReplyCache(v []uint64) (ReplyCache, error) {
21 if len(v) != 3 {
22 return ReplyCache{}, fmt.Errorf("invalid ReplyCache line %q", v)
23 }
24
25 return ReplyCache{
26 Hits: v[0],
27 Misses: v[1],
28 NoCache: v[2],
29 }, nil
30}
31
32func parseFileHandles(v []uint64) (FileHandles, error) {
33 if len(v) != 5 {
34 return FileHandles{}, fmt.Errorf("invalid FileHandles, line %q", v)
35 }
36
37 return FileHandles{
38 Stale: v[0],
39 TotalLookups: v[1],
40 AnonLookups: v[2],
41 DirNoCache: v[3],
42 NoDirNoCache: v[4],
43 }, nil
44}
45
46func parseInputOutput(v []uint64) (InputOutput, error) {
47 if len(v) != 2 {
48 return InputOutput{}, fmt.Errorf("invalid InputOutput line %q", v)
49 }
50
51 return InputOutput{
52 Read: v[0],
53 Write: v[1],
54 }, nil
55}
56
57func parseThreads(v []uint64) (Threads, error) {
58 if len(v) != 2 {
59 return Threads{}, fmt.Errorf("invalid Threads line %q", v)
60 }
61
62 return Threads{
63 Threads: v[0],
64 FullCnt: v[1],
65 }, nil
66}
67
68func parseReadAheadCache(v []uint64) (ReadAheadCache, error) {
69 if len(v) != 12 {
70 return ReadAheadCache{}, fmt.Errorf("invalid ReadAheadCache line %q", v)
71 }
72
73 return ReadAheadCache{
74 CacheSize: v[0],
75 CacheHistogram: v[1:11],
76 NotFound: v[11],
77 }, nil
78}
79
80func parseNetwork(v []uint64) (Network, error) {
81 if len(v) != 4 {
82 return Network{}, fmt.Errorf("invalid Network line %q", v)
83 }
84
85 return Network{
86 NetCount: v[0],
87 UDPCount: v[1],
88 TCPCount: v[2],
89 TCPConnect: v[3],
90 }, nil
91}
92
93func parseServerRPC(v []uint64) (ServerRPC, error) {
94 if len(v) != 5 {
95 return ServerRPC{}, fmt.Errorf("invalid RPC line %q", v)
96 }
97
98 return ServerRPC{
99 RPCCount: v[0],
100 BadCnt: v[1],
101 BadFmt: v[2],
102 BadAuth: v[3],
103 BadcInt: v[4],
104 }, nil
105}
106
107func parseClientRPC(v []uint64) (ClientRPC, error) {
108 if len(v) != 3 {
109 return ClientRPC{}, fmt.Errorf("invalid RPC line %q", v)
110 }
111
112 return ClientRPC{
113 RPCCount: v[0],
114 Retransmissions: v[1],
115 AuthRefreshes: v[2],
116 }, nil
117}
118
119func parseV2Stats(v []uint64) (V2Stats, error) {
120 values := int(v[0])
121 if len(v[1:]) != values || values != 18 {
122 return V2Stats{}, fmt.Errorf("invalid V2Stats line %q", v)
123 }
124
125 return V2Stats{
126 Null: v[1],
127 GetAttr: v[2],
128 SetAttr: v[3],
129 Root: v[4],
130 Lookup: v[5],
131 ReadLink: v[6],
132 Read: v[7],
133 WrCache: v[8],
134 Write: v[9],
135 Create: v[10],
136 Remove: v[11],
137 Rename: v[12],
138 Link: v[13],
139 SymLink: v[14],
140 MkDir: v[15],
141 RmDir: v[16],
142 ReadDir: v[17],
143 FsStat: v[18],
144 }, nil
145}
146
147func parseV3Stats(v []uint64) (V3Stats, error) {
148 values := int(v[0])
149 if len(v[1:]) != values || values != 22 {
150 return V3Stats{}, fmt.Errorf("invalid V3Stats line %q", v)
151 }
152
153 return V3Stats{
154 Null: v[1],
155 GetAttr: v[2],
156 SetAttr: v[3],
157 Lookup: v[4],
158 Access: v[5],
159 ReadLink: v[6],
160 Read: v[7],
161 Write: v[8],
162 Create: v[9],
163 MkDir: v[10],
164 SymLink: v[11],
165 MkNod: v[12],
166 Remove: v[13],
167 RmDir: v[14],
168 Rename: v[15],
169 Link: v[16],
170 ReadDir: v[17],
171 ReadDirPlus: v[18],
172 FsStat: v[19],
173 FsInfo: v[20],
174 PathConf: v[21],
175 Commit: v[22],
176 }, nil
177}
178
179func parseClientV4Stats(v []uint64) (ClientV4Stats, error) {
180 values := int(v[0])
181 if len(v[1:]) != values {
182 return ClientV4Stats{}, fmt.Errorf("invalid ClientV4Stats line %q", v)
183 }
184
185 // This function currently supports mapping 59 NFS v4 client stats. Older
186 // kernels may emit fewer stats, so we must detect this and pad out the
187 // values to match the expected slice size.
188 if values < 59 {
189 newValues := make([]uint64, 60)
190 copy(newValues, v)
191 v = newValues
192 }
193
194 return ClientV4Stats{
195 Null: v[1],
196 Read: v[2],
197 Write: v[3],
198 Commit: v[4],
199 Open: v[5],
200 OpenConfirm: v[6],
201 OpenNoattr: v[7],
202 OpenDowngrade: v[8],
203 Close: v[9],
204 Setattr: v[10],
205 FsInfo: v[11],
206 Renew: v[12],
207 SetClientID: v[13],
208 SetClientIDConfirm: v[14],
209 Lock: v[15],
210 Lockt: v[16],
211 Locku: v[17],
212 Access: v[18],
213 Getattr: v[19],
214 Lookup: v[20],
215 LookupRoot: v[21],
216 Remove: v[22],
217 Rename: v[23],
218 Link: v[24],
219 Symlink: v[25],
220 Create: v[26],
221 Pathconf: v[27],
222 StatFs: v[28],
223 ReadLink: v[29],
224 ReadDir: v[30],
225 ServerCaps: v[31],
226 DelegReturn: v[32],
227 GetACL: v[33],
228 SetACL: v[34],
229 FsLocations: v[35],
230 ReleaseLockowner: v[36],
231 Secinfo: v[37],
232 FsidPresent: v[38],
233 ExchangeID: v[39],
234 CreateSession: v[40],
235 DestroySession: v[41],
236 Sequence: v[42],
237 GetLeaseTime: v[43],
238 ReclaimComplete: v[44],
239 LayoutGet: v[45],
240 GetDeviceInfo: v[46],
241 LayoutCommit: v[47],
242 LayoutReturn: v[48],
243 SecinfoNoName: v[49],
244 TestStateID: v[50],
245 FreeStateID: v[51],
246 GetDeviceList: v[52],
247 BindConnToSession: v[53],
248 DestroyClientID: v[54],
249 Seek: v[55],
250 Allocate: v[56],
251 DeAllocate: v[57],
252 LayoutStats: v[58],
253 Clone: v[59],
254 }, nil
255}
256
257func parseServerV4Stats(v []uint64) (ServerV4Stats, error) {
258 values := int(v[0])
259 if len(v[1:]) != values || values != 2 {
260 return ServerV4Stats{}, fmt.Errorf("invalid V4Stats line %q", v)
261 }
262
263 return ServerV4Stats{
264 Null: v[1],
265 Compound: v[2],
266 }, nil
267}
268
269func parseV4Ops(v []uint64) (V4Ops, error) {
270 values := int(v[0])
271 if len(v[1:]) != values || values < 39 {
272 return V4Ops{}, fmt.Errorf("invalid V4Ops line %q", v)
273 }
274
275 stats := V4Ops{
276 Op0Unused: v[1],
277 Op1Unused: v[2],
278 Op2Future: v[3],
279 Access: v[4],
280 Close: v[5],
281 Commit: v[6],
282 Create: v[7],
283 DelegPurge: v[8],
284 DelegReturn: v[9],
285 GetAttr: v[10],
286 GetFH: v[11],
287 Link: v[12],
288 Lock: v[13],
289 Lockt: v[14],
290 Locku: v[15],
291 Lookup: v[16],
292 LookupRoot: v[17],
293 Nverify: v[18],
294 Open: v[19],
295 OpenAttr: v[20],
296 OpenConfirm: v[21],
297 OpenDgrd: v[22],
298 PutFH: v[23],
299 PutPubFH: v[24],
300 PutRootFH: v[25],
301 Read: v[26],
302 ReadDir: v[27],
303 ReadLink: v[28],
304 Remove: v[29],
305 Rename: v[30],
306 Renew: v[31],
307 RestoreFH: v[32],
308 SaveFH: v[33],
309 SecInfo: v[34],
310 SetAttr: v[35],
311 Verify: v[36],
312 Write: v[37],
313 RelLockOwner: v[38],
314 }
315
316 return stats, nil
317}