25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
1.6 KiB

  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. import (
  15. "fmt"
  16. "github.com/prometheus/procfs/internal/util"
  17. )
  18. // ProcIO models the content of /proc/<pid>/io.
  19. type ProcIO struct {
  20. // Chars read.
  21. RChar uint64
  22. // Chars written.
  23. WChar uint64
  24. // Read syscalls.
  25. SyscR uint64
  26. // Write syscalls.
  27. SyscW uint64
  28. // Bytes read.
  29. ReadBytes uint64
  30. // Bytes written.
  31. WriteBytes uint64
  32. // Bytes written, but taking into account truncation. See
  33. // Documentation/filesystems/proc.txt in the kernel sources for
  34. // detailed explanation.
  35. CancelledWriteBytes int64
  36. }
  37. // IO creates a new ProcIO instance from a given Proc instance.
  38. func (p Proc) IO() (ProcIO, error) {
  39. pio := ProcIO{}
  40. data, err := util.ReadFileNoStat(p.path("io"))
  41. if err != nil {
  42. return pio, err
  43. }
  44. ioFormat := "rchar: %d\nwchar: %d\nsyscr: %d\nsyscw: %d\n" +
  45. "read_bytes: %d\nwrite_bytes: %d\n" +
  46. "cancelled_write_bytes: %d\n"
  47. _, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR,
  48. &pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes)
  49. return pio, err
  50. }