parse.go 7.1 KB

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