parseMountStatsNFS parses a MountStatsNFS by scanning additional information related to NFS statistics.
(s *bufio.Scanner, statVersion string)
| 355 | // parseMountStatsNFS parses a MountStatsNFS by scanning additional information |
| 356 | // related to NFS statistics. |
| 357 | func parseMountStatsNFS(s *bufio.Scanner, statVersion string) (*MountStatsNFS, error) { |
| 358 | // Field indicators for parsing specific types of data |
| 359 | const ( |
| 360 | fieldOpts = "opts:" |
| 361 | fieldAge = "age:" |
| 362 | fieldBytes = "bytes:" |
| 363 | fieldEvents = "events:" |
| 364 | fieldPerOpStats = "per-op" |
| 365 | fieldTransport = "xprt:" |
| 366 | ) |
| 367 | |
| 368 | stats := &MountStatsNFS{ |
| 369 | StatVersion: statVersion, |
| 370 | } |
| 371 | |
| 372 | for s.Scan() { |
| 373 | ss := strings.Fields(string(s.Bytes())) |
| 374 | if len(ss) == 0 { |
| 375 | break |
| 376 | } |
| 377 | |
| 378 | switch ss[0] { |
| 379 | case fieldOpts: |
| 380 | if len(ss) < 2 { |
| 381 | return nil, fmt.Errorf("%w: Incomplete information for NFS stats: %v", ErrFileParse, ss) |
| 382 | } |
| 383 | if stats.Opts == nil { |
| 384 | stats.Opts = map[string]string{} |
| 385 | } |
| 386 | for opt := range strings.SplitSeq(ss[1], ",") { |
| 387 | split := strings.Split(opt, "=") |
| 388 | if len(split) == 2 { |
| 389 | stats.Opts[split[0]] = split[1] |
| 390 | } else { |
| 391 | stats.Opts[opt] = "" |
| 392 | } |
| 393 | } |
| 394 | case fieldAge: |
| 395 | if len(ss) < 2 { |
| 396 | return nil, fmt.Errorf("%w: Incomplete information for NFS stats: %v", ErrFileParse, ss) |
| 397 | } |
| 398 | // Age integer is in seconds |
| 399 | d, err := time.ParseDuration(ss[1] + "s") |
| 400 | if err != nil { |
| 401 | return nil, err |
| 402 | } |
| 403 | |
| 404 | stats.Age = d |
| 405 | case fieldBytes: |
| 406 | if len(ss) < 2 { |
| 407 | return nil, fmt.Errorf("%w: Incomplete information for NFS stats: %v", ErrFileParse, ss) |
| 408 | } |
| 409 | bstats, err := parseNFSBytesStats(ss[1:]) |
| 410 | if err != nil { |
| 411 | return nil, err |
| 412 | } |
| 413 | |
| 414 | stats.Bytes = *bstats |
no test coverage detected