mountstats.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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 procfs
  14. // While implementing parsing of /proc/[pid]/mountstats, this blog was used
  15. // heavily as a reference:
  16. // https://utcc.utoronto.ca/~cks/space/blog/linux/NFSMountstatsIndex
  17. //
  18. // Special thanks to Chris Siebenmann for all of his posts explaining the
  19. // various statistics available for NFS.
  20. import (
  21. "bufio"
  22. "fmt"
  23. "io"
  24. "strconv"
  25. "strings"
  26. "time"
  27. )
  28. // Constants shared between multiple functions.
  29. const (
  30. deviceEntryLen = 8
  31. fieldBytesLen = 8
  32. fieldEventsLen = 27
  33. statVersion10 = "1.0"
  34. statVersion11 = "1.1"
  35. fieldTransport10TCPLen = 10
  36. fieldTransport10UDPLen = 7
  37. fieldTransport11TCPLen = 13
  38. fieldTransport11UDPLen = 10
  39. // kernel version >= 4.14 MaxLen
  40. // See: https://elixir.bootlin.com/linux/v6.4.8/source/net/sunrpc/xprtrdma/xprt_rdma.h#L393
  41. fieldTransport11RDMAMaxLen = 28
  42. // kernel version <= 4.2 MinLen
  43. // See: https://elixir.bootlin.com/linux/v4.2.8/source/net/sunrpc/xprtrdma/xprt_rdma.h#L331
  44. fieldTransport11RDMAMinLen = 20
  45. )
  46. // A Mount is a device mount parsed from /proc/[pid]/mountstats.
  47. type Mount struct {
  48. // Name of the device.
  49. Device string
  50. // The mount point of the device.
  51. Mount string
  52. // The filesystem type used by the device.
  53. Type string
  54. // If available additional statistics related to this Mount.
  55. // Use a type assertion to determine if additional statistics are available.
  56. Stats MountStats
  57. }
  58. // A MountStats is a type which contains detailed statistics for a specific
  59. // type of Mount.
  60. type MountStats interface {
  61. mountStats()
  62. }
  63. // A MountStatsNFS is a MountStats implementation for NFSv3 and v4 mounts.
  64. type MountStatsNFS struct {
  65. // The version of statistics provided.
  66. StatVersion string
  67. // The mount options of the NFS mount.
  68. Opts map[string]string
  69. // The age of the NFS mount.
  70. Age time.Duration
  71. // Statistics related to byte counters for various operations.
  72. Bytes NFSBytesStats
  73. // Statistics related to various NFS event occurrences.
  74. Events NFSEventsStats
  75. // Statistics broken down by filesystem operation.
  76. Operations []NFSOperationStats
  77. // Statistics about the NFS RPC transport.
  78. Transport []NFSTransportStats
  79. }
  80. // mountStats implements MountStats.
  81. func (m MountStatsNFS) mountStats() {}
  82. // A NFSBytesStats contains statistics about the number of bytes read and written
  83. // by an NFS client to and from an NFS server.
  84. type NFSBytesStats struct {
  85. // Number of bytes read using the read() syscall.
  86. Read uint64
  87. // Number of bytes written using the write() syscall.
  88. Write uint64
  89. // Number of bytes read using the read() syscall in O_DIRECT mode.
  90. DirectRead uint64
  91. // Number of bytes written using the write() syscall in O_DIRECT mode.
  92. DirectWrite uint64
  93. // Number of bytes read from the NFS server, in total.
  94. ReadTotal uint64
  95. // Number of bytes written to the NFS server, in total.
  96. WriteTotal uint64
  97. // Number of pages read directly via mmap()'d files.
  98. ReadPages uint64
  99. // Number of pages written directly via mmap()'d files.
  100. WritePages uint64
  101. }
  102. // A NFSEventsStats contains statistics about NFS event occurrences.
  103. type NFSEventsStats struct {
  104. // Number of times cached inode attributes are re-validated from the server.
  105. InodeRevalidate uint64
  106. // Number of times cached dentry nodes are re-validated from the server.
  107. DnodeRevalidate uint64
  108. // Number of times an inode cache is cleared.
  109. DataInvalidate uint64
  110. // Number of times cached inode attributes are invalidated.
  111. AttributeInvalidate uint64
  112. // Number of times files or directories have been open()'d.
  113. VFSOpen uint64
  114. // Number of times a directory lookup has occurred.
  115. VFSLookup uint64
  116. // Number of times permissions have been checked.
  117. VFSAccess uint64
  118. // Number of updates (and potential writes) to pages.
  119. VFSUpdatePage uint64
  120. // Number of pages read directly via mmap()'d files.
  121. VFSReadPage uint64
  122. // Number of times a group of pages have been read.
  123. VFSReadPages uint64
  124. // Number of pages written directly via mmap()'d files.
  125. VFSWritePage uint64
  126. // Number of times a group of pages have been written.
  127. VFSWritePages uint64
  128. // Number of times directory entries have been read with getdents().
  129. VFSGetdents uint64
  130. // Number of times attributes have been set on inodes.
  131. VFSSetattr uint64
  132. // Number of pending writes that have been forcefully flushed to the server.
  133. VFSFlush uint64
  134. // Number of times fsync() has been called on directories and files.
  135. VFSFsync uint64
  136. // Number of times locking has been attempted on a file.
  137. VFSLock uint64
  138. // Number of times files have been closed and released.
  139. VFSFileRelease uint64
  140. // Unknown. Possibly unused.
  141. CongestionWait uint64
  142. // Number of times files have been truncated.
  143. Truncation uint64
  144. // Number of times a file has been grown due to writes beyond its existing end.
  145. WriteExtension uint64
  146. // Number of times a file was removed while still open by another process.
  147. SillyRename uint64
  148. // Number of times the NFS server gave less data than expected while reading.
  149. ShortRead uint64
  150. // Number of times the NFS server wrote less data than expected while writing.
  151. ShortWrite uint64
  152. // Number of times the NFS server indicated EJUKEBOX; retrieving data from
  153. // offline storage.
  154. JukeboxDelay uint64
  155. // Number of NFS v4.1+ pNFS reads.
  156. PNFSRead uint64
  157. // Number of NFS v4.1+ pNFS writes.
  158. PNFSWrite uint64
  159. }
  160. // A NFSOperationStats contains statistics for a single operation.
  161. type NFSOperationStats struct {
  162. // The name of the operation.
  163. Operation string
  164. // Number of requests performed for this operation.
  165. Requests uint64
  166. // Number of times an actual RPC request has been transmitted for this operation.
  167. Transmissions uint64
  168. // Number of times a request has had a major timeout.
  169. MajorTimeouts uint64
  170. // Number of bytes sent for this operation, including RPC headers and payload.
  171. BytesSent uint64
  172. // Number of bytes received for this operation, including RPC headers and payload.
  173. BytesReceived uint64
  174. // Duration all requests spent queued for transmission before they were sent.
  175. CumulativeQueueMilliseconds uint64
  176. // Duration it took to get a reply back after the request was transmitted.
  177. CumulativeTotalResponseMilliseconds uint64
  178. // Duration from when a request was enqueued to when it was completely handled.
  179. CumulativeTotalRequestMilliseconds uint64
  180. // The count of operations that complete with tk_status < 0. These statuses usually indicate error conditions.
  181. Errors uint64
  182. }
  183. // A NFSTransportStats contains statistics for the NFS mount RPC requests and
  184. // responses.
  185. type NFSTransportStats struct {
  186. // The transport protocol used for the NFS mount.
  187. Protocol string
  188. // The local port used for the NFS mount.
  189. Port uint64
  190. // Number of times the client has had to establish a connection from scratch
  191. // to the NFS server.
  192. Bind uint64
  193. // Number of times the client has made a TCP connection to the NFS server.
  194. Connect uint64
  195. // Duration (in jiffies, a kernel internal unit of time) the NFS mount has
  196. // spent waiting for connections to the server to be established.
  197. ConnectIdleTime uint64
  198. // Duration since the NFS mount last saw any RPC traffic.
  199. IdleTimeSeconds uint64
  200. // Number of RPC requests for this mount sent to the NFS server.
  201. Sends uint64
  202. // Number of RPC responses for this mount received from the NFS server.
  203. Receives uint64
  204. // Number of times the NFS server sent a response with a transaction ID
  205. // unknown to this client.
  206. BadTransactionIDs uint64
  207. // A running counter, incremented on each request as the current difference
  208. // ebetween sends and receives.
  209. CumulativeActiveRequests uint64
  210. // A running counter, incremented on each request by the current backlog
  211. // queue size.
  212. CumulativeBacklog uint64
  213. // Stats below only available with stat version 1.1.
  214. // Maximum number of simultaneously active RPC requests ever used.
  215. MaximumRPCSlotsUsed uint64
  216. // A running counter, incremented on each request as the current size of the
  217. // sending queue.
  218. CumulativeSendingQueue uint64
  219. // A running counter, incremented on each request as the current size of the
  220. // pending queue.
  221. CumulativePendingQueue uint64
  222. // Stats below only available with stat version 1.1.
  223. // Transport over RDMA
  224. // accessed when sending a call
  225. ReadChunkCount uint64
  226. WriteChunkCount uint64
  227. ReplyChunkCount uint64
  228. TotalRdmaRequest uint64
  229. // rarely accessed error counters
  230. PullupCopyCount uint64
  231. HardwayRegisterCount uint64
  232. FailedMarshalCount uint64
  233. BadReplyCount uint64
  234. MrsRecovered uint64
  235. MrsOrphaned uint64
  236. MrsAllocated uint64
  237. EmptySendctxQ uint64
  238. // accessed when receiving a reply
  239. TotalRdmaReply uint64
  240. FixupCopyCount uint64
  241. ReplyWaitsForSend uint64
  242. LocalInvNeeded uint64
  243. NomsgCallCount uint64
  244. BcallCount uint64
  245. }
  246. // parseMountStats parses a /proc/[pid]/mountstats file and returns a slice
  247. // of Mount structures containing detailed information about each mount.
  248. // If available, statistics for each mount are parsed as well.
  249. func parseMountStats(r io.Reader) ([]*Mount, error) {
  250. const (
  251. device = "device"
  252. statVersionPrefix = "statvers="
  253. nfs3Type = "nfs"
  254. nfs4Type = "nfs4"
  255. )
  256. var mounts []*Mount
  257. s := bufio.NewScanner(r)
  258. for s.Scan() {
  259. // Only look for device entries in this function
  260. ss := strings.Fields(string(s.Bytes()))
  261. if len(ss) == 0 || ss[0] != device {
  262. continue
  263. }
  264. m, err := parseMount(ss)
  265. if err != nil {
  266. return nil, err
  267. }
  268. // Does this mount also possess statistics information?
  269. if len(ss) > deviceEntryLen {
  270. // Only NFSv3 and v4 are supported for parsing statistics
  271. if m.Type != nfs3Type && m.Type != nfs4Type {
  272. return nil, fmt.Errorf("%w: Cannot parse MountStats for %q", ErrFileParse, m.Type)
  273. }
  274. statVersion := strings.TrimPrefix(ss[8], statVersionPrefix)
  275. stats, err := parseMountStatsNFS(s, statVersion)
  276. if err != nil {
  277. return nil, err
  278. }
  279. m.Stats = stats
  280. }
  281. mounts = append(mounts, m)
  282. }
  283. return mounts, s.Err()
  284. }
  285. // parseMount parses an entry in /proc/[pid]/mountstats in the format:
  286. //
  287. // device [device] mounted on [mount] with fstype [type]
  288. func parseMount(ss []string) (*Mount, error) {
  289. if len(ss) < deviceEntryLen {
  290. return nil, fmt.Errorf("%w: Invalid device %q", ErrFileParse, ss)
  291. }
  292. // Check for specific words appearing at specific indices to ensure
  293. // the format is consistent with what we expect
  294. format := []struct {
  295. i int
  296. s string
  297. }{
  298. {i: 0, s: "device"},
  299. {i: 2, s: "mounted"},
  300. {i: 3, s: "on"},
  301. {i: 5, s: "with"},
  302. {i: 6, s: "fstype"},
  303. }
  304. for _, f := range format {
  305. if ss[f.i] != f.s {
  306. return nil, fmt.Errorf("%w: Invalid device %q", ErrFileParse, ss)
  307. }
  308. }
  309. return &Mount{
  310. Device: ss[1],
  311. Mount: ss[4],
  312. Type: ss[7],
  313. }, nil
  314. }
  315. // parseMountStatsNFS parses a MountStatsNFS by scanning additional information
  316. // related to NFS statistics.
  317. func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, error) {
  318. // Field indicators for parsing specific types of data
  319. const (
  320. fieldOpts = "opts:"
  321. fieldAge = "age:"
  322. fieldBytes = "bytes:"
  323. fieldEvents = "events:"
  324. fieldPerOpStats = "per-op"
  325. fieldTransport = "xprt:"
  326. )
  327. stats := &MountStatsNFS{
  328. StatVersion: statVersion,
  329. }
  330. for s.Scan() {
  331. ss := strings.Fields(string(s.Bytes()))
  332. if len(ss) == 0 {
  333. break
  334. }
  335. switch ss[0] {
  336. case fieldOpts:
  337. if len(ss) < 2 {
  338. return nil, fmt.Errorf("%w: Incomplete information for NFS stats: %v", ErrFileParse, ss)
  339. }
  340. if stats.Opts == nil {
  341. stats.Opts = map[string]string{}
  342. }
  343. for _, opt := range strings.Split(ss[1], ",") {
  344. split := strings.Split(opt, "=")
  345. if len(split) == 2 {
  346. stats.Opts[split[0]] = split[1]
  347. } else {
  348. stats.Opts[opt] = ""
  349. }
  350. }
  351. case fieldAge:
  352. if len(ss) < 2 {
  353. return nil, fmt.Errorf("%w: Incomplete information for NFS stats: %v", ErrFileParse, ss)
  354. }
  355. // Age integer is in seconds
  356. d, err := time.ParseDuration(ss[1] + "s")
  357. if err != nil {
  358. return nil, err
  359. }
  360. stats.Age = d
  361. case fieldBytes:
  362. if len(ss) < 2 {
  363. return nil, fmt.Errorf("%w: Incomplete information for NFS stats: %v", ErrFileParse, ss)
  364. }
  365. bstats, err := parseNFSBytesStats(ss[1:])
  366. if err != nil {
  367. return nil, err
  368. }
  369. stats.Bytes = *bstats
  370. case fieldEvents:
  371. if len(ss) < 2 {
  372. return nil, fmt.Errorf("%w: Incomplete information for NFS events: %v", ErrFileParse, ss)
  373. }
  374. estats, err := parseNFSEventsStats(ss[1:])
  375. if err != nil {
  376. return nil, err
  377. }
  378. stats.Events = *estats
  379. case fieldTransport:
  380. if len(ss) < 3 {
  381. return nil, fmt.Errorf("%w: Incomplete information for NFS transport stats: %v", ErrFileParse, ss)
  382. }
  383. tstats, err := parseNFSTransportStats(ss[1:], statVersion)
  384. if err != nil {
  385. return nil, err
  386. }
  387. stats.Transport = append(stats.Transport, *tstats)
  388. }
  389. // When encountering "per-operation statistics", we must break this
  390. // loop and parse them separately to ensure we can terminate parsing
  391. // before reaching another device entry; hence why this 'if' statement
  392. // is not just another switch case
  393. if ss[0] == fieldPerOpStats {
  394. break
  395. }
  396. }
  397. if err := s.Err(); err != nil {
  398. return nil, err
  399. }
  400. // NFS per-operation stats appear last before the next device entry
  401. perOpStats, err := parseNFSOperationStats(s)
  402. if err != nil {
  403. return nil, err
  404. }
  405. stats.Operations = perOpStats
  406. return stats, nil
  407. }
  408. // parseNFSBytesStats parses a NFSBytesStats line using an input set of
  409. // integer fields.
  410. func parseNFSBytesStats(ss []string) (*NFSBytesStats, error) {
  411. if len(ss) != fieldBytesLen {
  412. return nil, fmt.Errorf("%w: Invalid NFS bytes stats: %v", ErrFileParse, ss)
  413. }
  414. ns := make([]uint64, 0, fieldBytesLen)
  415. for _, s := range ss {
  416. n, err := strconv.ParseUint(s, 10, 64)
  417. if err != nil {
  418. return nil, err
  419. }
  420. ns = append(ns, n)
  421. }
  422. return &NFSBytesStats{
  423. Read: ns[0],
  424. Write: ns[1],
  425. DirectRead: ns[2],
  426. DirectWrite: ns[3],
  427. ReadTotal: ns[4],
  428. WriteTotal: ns[5],
  429. ReadPages: ns[6],
  430. WritePages: ns[7],
  431. }, nil
  432. }
  433. // parseNFSEventsStats parses a NFSEventsStats line using an input set of
  434. // integer fields.
  435. func parseNFSEventsStats(ss []string) (*NFSEventsStats, error) {
  436. if len(ss) != fieldEventsLen {
  437. return nil, fmt.Errorf("%w: invalid NFS events stats: %v", ErrFileParse, ss)
  438. }
  439. ns := make([]uint64, 0, fieldEventsLen)
  440. for _, s := range ss {
  441. n, err := strconv.ParseUint(s, 10, 64)
  442. if err != nil {
  443. return nil, err
  444. }
  445. ns = append(ns, n)
  446. }
  447. return &NFSEventsStats{
  448. InodeRevalidate: ns[0],
  449. DnodeRevalidate: ns[1],
  450. DataInvalidate: ns[2],
  451. AttributeInvalidate: ns[3],
  452. VFSOpen: ns[4],
  453. VFSLookup: ns[5],
  454. VFSAccess: ns[6],
  455. VFSUpdatePage: ns[7],
  456. VFSReadPage: ns[8],
  457. VFSReadPages: ns[9],
  458. VFSWritePage: ns[10],
  459. VFSWritePages: ns[11],
  460. VFSGetdents: ns[12],
  461. VFSSetattr: ns[13],
  462. VFSFlush: ns[14],
  463. VFSFsync: ns[15],
  464. VFSLock: ns[16],
  465. VFSFileRelease: ns[17],
  466. CongestionWait: ns[18],
  467. Truncation: ns[19],
  468. WriteExtension: ns[20],
  469. SillyRename: ns[21],
  470. ShortRead: ns[22],
  471. ShortWrite: ns[23],
  472. JukeboxDelay: ns[24],
  473. PNFSRead: ns[25],
  474. PNFSWrite: ns[26],
  475. }, nil
  476. }
  477. // parseNFSOperationStats parses a slice of NFSOperationStats by scanning
  478. // additional information about per-operation statistics until an empty
  479. // line is reached.
  480. func parseNFSOperationStats(s *bufio.Scanner) ([]NFSOperationStats, error) {
  481. const (
  482. // Minimum number of expected fields in each per-operation statistics set
  483. minFields = 9
  484. )
  485. var ops []NFSOperationStats
  486. for s.Scan() {
  487. ss := strings.Fields(string(s.Bytes()))
  488. if len(ss) == 0 {
  489. // Must break when reading a blank line after per-operation stats to
  490. // enable top-level function to parse the next device entry
  491. break
  492. }
  493. if len(ss) < minFields {
  494. return nil, fmt.Errorf("%w: invalid NFS per-operations stats: %v", ErrFileParse, ss)
  495. }
  496. // Skip string operation name for integers
  497. ns := make([]uint64, 0, minFields-1)
  498. for _, st := range ss[1:] {
  499. n, err := strconv.ParseUint(st, 10, 64)
  500. if err != nil {
  501. return nil, err
  502. }
  503. ns = append(ns, n)
  504. }
  505. opStats := NFSOperationStats{
  506. Operation: strings.TrimSuffix(ss[0], ":"),
  507. Requests: ns[0],
  508. Transmissions: ns[1],
  509. MajorTimeouts: ns[2],
  510. BytesSent: ns[3],
  511. BytesReceived: ns[4],
  512. CumulativeQueueMilliseconds: ns[5],
  513. CumulativeTotalResponseMilliseconds: ns[6],
  514. CumulativeTotalRequestMilliseconds: ns[7],
  515. }
  516. if len(ns) > 8 {
  517. opStats.Errors = ns[8]
  518. }
  519. ops = append(ops, opStats)
  520. }
  521. return ops, s.Err()
  522. }
  523. // parseNFSTransportStats parses a NFSTransportStats line using an input set of
  524. // integer fields matched to a specific stats version.
  525. func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats, error) {
  526. // Extract the protocol field. It is the only string value in the line
  527. protocol := ss[0]
  528. ss = ss[1:]
  529. switch statVersion {
  530. case statVersion10:
  531. var expectedLength int
  532. if protocol == "tcp" {
  533. expectedLength = fieldTransport10TCPLen
  534. } else if protocol == "udp" {
  535. expectedLength = fieldTransport10UDPLen
  536. } else {
  537. return nil, fmt.Errorf("%w: Invalid NFS protocol \"%s\" in stats 1.0 statement: %v", ErrFileParse, protocol, ss)
  538. }
  539. if len(ss) != expectedLength {
  540. return nil, fmt.Errorf("%w: Invalid NFS transport stats 1.0 statement: %v", ErrFileParse, ss)
  541. }
  542. case statVersion11:
  543. var expectedLength int
  544. if protocol == "tcp" {
  545. expectedLength = fieldTransport11TCPLen
  546. } else if protocol == "udp" {
  547. expectedLength = fieldTransport11UDPLen
  548. } else if protocol == "rdma" {
  549. expectedLength = fieldTransport11RDMAMinLen
  550. } else {
  551. return nil, fmt.Errorf("%w: invalid NFS protocol \"%s\" in stats 1.1 statement: %v", ErrFileParse, protocol, ss)
  552. }
  553. if (len(ss) != expectedLength && (protocol == "tcp" || protocol == "udp")) ||
  554. (protocol == "rdma" && len(ss) < expectedLength) {
  555. return nil, fmt.Errorf("%w: invalid NFS transport stats 1.1 statement: %v, protocol: %v", ErrFileParse, ss, protocol)
  556. }
  557. default:
  558. return nil, fmt.Errorf("%w: Unrecognized NFS transport stats version: %q, protocol: %v", ErrFileParse, statVersion, protocol)
  559. }
  560. // Allocate enough for v1.1 stats since zero value for v1.1 stats will be okay
  561. // in a v1.0 response. Since the stat length is bigger for TCP stats, we use
  562. // the TCP length here.
  563. //
  564. // Note: slice length must be set to length of v1.1 stats to avoid a panic when
  565. // only v1.0 stats are present.
  566. // See: https://github.com/prometheus/node_exporter/issues/571.
  567. //
  568. // Note: NFS Over RDMA slice length is fieldTransport11RDMAMaxLen
  569. ns := make([]uint64, fieldTransport11RDMAMaxLen+3)
  570. for i, s := range ss {
  571. n, err := strconv.ParseUint(s, 10, 64)
  572. if err != nil {
  573. return nil, err
  574. }
  575. ns[i] = n
  576. }
  577. // The fields differ depending on the transport protocol (TCP or UDP)
  578. // From https://utcc.utoronto.ca/%7Ecks/space/blog/linux/NFSMountstatsXprt
  579. //
  580. // For the udp RPC transport there is no connection count, connect idle time,
  581. // or idle time (fields #3, #4, and #5); all other fields are the same. So
  582. // we set them to 0 here.
  583. if protocol == "udp" {
  584. ns = append(ns[:2], append(make([]uint64, 3), ns[2:]...)...)
  585. } else if protocol == "tcp" {
  586. ns = append(ns[:fieldTransport11TCPLen], make([]uint64, fieldTransport11RDMAMaxLen-fieldTransport11TCPLen+3)...)
  587. } else if protocol == "rdma" {
  588. ns = append(ns[:fieldTransport10TCPLen], append(make([]uint64, 3), ns[fieldTransport10TCPLen:]...)...)
  589. }
  590. return &NFSTransportStats{
  591. // NFS xprt over tcp or udp
  592. Protocol: protocol,
  593. Port: ns[0],
  594. Bind: ns[1],
  595. Connect: ns[2],
  596. ConnectIdleTime: ns[3],
  597. IdleTimeSeconds: ns[4],
  598. Sends: ns[5],
  599. Receives: ns[6],
  600. BadTransactionIDs: ns[7],
  601. CumulativeActiveRequests: ns[8],
  602. CumulativeBacklog: ns[9],
  603. // NFS xprt over tcp or udp
  604. // And statVersion 1.1
  605. MaximumRPCSlotsUsed: ns[10],
  606. CumulativeSendingQueue: ns[11],
  607. CumulativePendingQueue: ns[12],
  608. // NFS xprt over rdma
  609. // And stat Version 1.1
  610. ReadChunkCount: ns[13],
  611. WriteChunkCount: ns[14],
  612. ReplyChunkCount: ns[15],
  613. TotalRdmaRequest: ns[16],
  614. PullupCopyCount: ns[17],
  615. HardwayRegisterCount: ns[18],
  616. FailedMarshalCount: ns[19],
  617. BadReplyCount: ns[20],
  618. MrsRecovered: ns[21],
  619. MrsOrphaned: ns[22],
  620. MrsAllocated: ns[23],
  621. EmptySendctxQ: ns[24],
  622. TotalRdmaReply: ns[25],
  623. FixupCopyCount: ns[26],
  624. ReplyWaitsForSend: ns[27],
  625. LocalInvNeeded: ns[28],
  626. NomsgCallCount: ns[29],
  627. BcallCount: ns[30],
  628. }, nil
  629. }