...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package nfs
17
18 import (
19 "os"
20 "strings"
21
22 "github.com/prometheus/procfs/internal/fs"
23 )
24
25
26 type ReplyCache struct {
27 Hits uint64
28 Misses uint64
29 NoCache uint64
30 }
31
32
33 type FileHandles struct {
34 Stale uint64
35 TotalLookups uint64
36 AnonLookups uint64
37 DirNoCache uint64
38 NoDirNoCache uint64
39 }
40
41
42 type InputOutput struct {
43 Read uint64
44 Write uint64
45 }
46
47
48 type Threads struct {
49 Threads uint64
50 FullCnt uint64
51 }
52
53
54 type ReadAheadCache struct {
55 CacheSize uint64
56 CacheHistogram []uint64
57 NotFound uint64
58 }
59
60
61 type Network struct {
62 NetCount uint64
63 UDPCount uint64
64 TCPCount uint64
65 TCPConnect uint64
66 }
67
68
69 type ClientRPC struct {
70 RPCCount uint64
71 Retransmissions uint64
72 AuthRefreshes uint64
73 }
74
75
76 type ServerRPC struct {
77 RPCCount uint64
78 BadCnt uint64
79 BadFmt uint64
80 BadAuth uint64
81 BadcInt uint64
82 }
83
84
85 type V2Stats struct {
86 Null uint64
87 GetAttr uint64
88 SetAttr uint64
89 Root uint64
90 Lookup uint64
91 ReadLink uint64
92 Read uint64
93 WrCache uint64
94 Write uint64
95 Create uint64
96 Remove uint64
97 Rename uint64
98 Link uint64
99 SymLink uint64
100 MkDir uint64
101 RmDir uint64
102 ReadDir uint64
103 FsStat uint64
104 }
105
106
107 type V3Stats struct {
108 Null uint64
109 GetAttr uint64
110 SetAttr uint64
111 Lookup uint64
112 Access uint64
113 ReadLink uint64
114 Read uint64
115 Write uint64
116 Create uint64
117 MkDir uint64
118 SymLink uint64
119 MkNod uint64
120 Remove uint64
121 RmDir uint64
122 Rename uint64
123 Link uint64
124 ReadDir uint64
125 ReadDirPlus uint64
126 FsStat uint64
127 FsInfo uint64
128 PathConf uint64
129 Commit uint64
130 }
131
132
133 type ClientV4Stats struct {
134 Null uint64
135 Read uint64
136 Write uint64
137 Commit uint64
138 Open uint64
139 OpenConfirm uint64
140 OpenNoattr uint64
141 OpenDowngrade uint64
142 Close uint64
143 Setattr uint64
144 FsInfo uint64
145 Renew uint64
146 SetClientID uint64
147 SetClientIDConfirm uint64
148 Lock uint64
149 Lockt uint64
150 Locku uint64
151 Access uint64
152 Getattr uint64
153 Lookup uint64
154 LookupRoot uint64
155 Remove uint64
156 Rename uint64
157 Link uint64
158 Symlink uint64
159 Create uint64
160 Pathconf uint64
161 StatFs uint64
162 ReadLink uint64
163 ReadDir uint64
164 ServerCaps uint64
165 DelegReturn uint64
166 GetACL uint64
167 SetACL uint64
168 FsLocations uint64
169 ReleaseLockowner uint64
170 Secinfo uint64
171 FsidPresent uint64
172 ExchangeID uint64
173 CreateSession uint64
174 DestroySession uint64
175 Sequence uint64
176 GetLeaseTime uint64
177 ReclaimComplete uint64
178 LayoutGet uint64
179 GetDeviceInfo uint64
180 LayoutCommit uint64
181 LayoutReturn uint64
182 SecinfoNoName uint64
183 TestStateID uint64
184 FreeStateID uint64
185 GetDeviceList uint64
186 BindConnToSession uint64
187 DestroyClientID uint64
188 Seek uint64
189 Allocate uint64
190 DeAllocate uint64
191 LayoutStats uint64
192 Clone uint64
193 }
194
195
196 type ServerV4Stats struct {
197 Null uint64
198 Compound uint64
199 }
200
201
202
203
204
205
206
207
208
209
210
211
212 type V4Ops struct {
213
214 Op0Unused uint64
215 Op1Unused uint64
216 Op2Future uint64
217 Access uint64
218 Close uint64
219 Commit uint64
220 Create uint64
221 DelegPurge uint64
222 DelegReturn uint64
223 GetAttr uint64
224 GetFH uint64
225 Link uint64
226 Lock uint64
227 Lockt uint64
228 Locku uint64
229 Lookup uint64
230 LookupRoot uint64
231 Nverify uint64
232 Open uint64
233 OpenAttr uint64
234 OpenConfirm uint64
235 OpenDgrd uint64
236 PutFH uint64
237 PutPubFH uint64
238 PutRootFH uint64
239 Read uint64
240 ReadDir uint64
241 ReadLink uint64
242 Remove uint64
243 Rename uint64
244 Renew uint64
245 RestoreFH uint64
246 SaveFH uint64
247 SecInfo uint64
248 SetAttr uint64
249 SetClientID uint64
250 SetClientIDConfirm uint64
251 Verify uint64
252 Write uint64
253 RelLockOwner uint64
254 }
255
256
257 type ClientRPCStats struct {
258 Network Network
259 ClientRPC ClientRPC
260 V2Stats V2Stats
261 V3Stats V3Stats
262 ClientV4Stats ClientV4Stats
263 }
264
265
266 type ServerRPCStats struct {
267 ReplyCache ReplyCache
268 FileHandles FileHandles
269 InputOutput InputOutput
270 Threads Threads
271 ReadAheadCache ReadAheadCache
272 Network Network
273 ServerRPC ServerRPC
274 V2Stats V2Stats
275 V3Stats V3Stats
276 ServerV4Stats ServerV4Stats
277 V4Ops V4Ops
278 WdelegGetattr uint64
279 }
280
281
282
283 type FS struct {
284 proc *fs.FS
285 }
286
287
288
289 func NewDefaultFS() (FS, error) {
290 return NewFS(fs.DefaultProcMountPoint)
291 }
292
293
294
295 func NewFS(mountPoint string) (FS, error) {
296 if strings.TrimSpace(mountPoint) == "" {
297 mountPoint = fs.DefaultProcMountPoint
298 }
299 fs, err := fs.NewFS(mountPoint)
300 if err != nil {
301 return FS{}, err
302 }
303 return FS{&fs}, nil
304 }
305
306
307
308 func (fs FS) ClientRPCStats() (*ClientRPCStats, error) {
309 f, err := os.Open(fs.proc.Path("net/rpc/nfs"))
310 if err != nil {
311 return nil, err
312 }
313 defer f.Close()
314
315 return ParseClientRPCStats(f)
316 }
317
318
319
320 func (fs FS) ServerRPCStats() (*ServerRPCStats, error) {
321 f, err := os.Open(fs.proc.Path("net/rpc/nfsd"))
322 if err != nil {
323 return nil, err
324 }
325 defer f.Close()
326
327 return ParseServerRPCStats(f)
328 }
329
View as plain text