sigar_interface.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package sigar
  2. import (
  3. "time"
  4. )
  5. type Sigar interface {
  6. CollectCpuStats(collectionInterval time.Duration) (<-chan Cpu, chan<- struct{})
  7. GetLoadAverage() (LoadAverage, error)
  8. GetMem() (Mem, error)
  9. GetSwap() (Swap, error)
  10. GetFileSystemUsage(string) (FileSystemUsage, error)
  11. }
  12. type Cpu struct {
  13. User uint64
  14. Nice uint64
  15. Sys uint64
  16. Idle uint64
  17. Wait uint64
  18. Irq uint64
  19. SoftIrq uint64
  20. Stolen uint64
  21. }
  22. func (cpu *Cpu) Total() uint64 {
  23. return cpu.User + cpu.Nice + cpu.Sys + cpu.Idle +
  24. cpu.Wait + cpu.Irq + cpu.SoftIrq + cpu.Stolen
  25. }
  26. func (cpu Cpu) Delta(other Cpu) Cpu {
  27. return Cpu{
  28. User: cpu.User - other.User,
  29. Nice: cpu.Nice - other.Nice,
  30. Sys: cpu.Sys - other.Sys,
  31. Idle: cpu.Idle - other.Idle,
  32. Wait: cpu.Wait - other.Wait,
  33. Irq: cpu.Irq - other.Irq,
  34. SoftIrq: cpu.SoftIrq - other.SoftIrq,
  35. Stolen: cpu.Stolen - other.Stolen,
  36. }
  37. }
  38. type LoadAverage struct {
  39. One, Five, Fifteen float64
  40. }
  41. type Uptime struct {
  42. Length float64
  43. }
  44. type Mem struct {
  45. Total uint64
  46. Used uint64
  47. Free uint64
  48. ActualFree uint64
  49. ActualUsed uint64
  50. }
  51. type Swap struct {
  52. Total uint64
  53. Used uint64
  54. Free uint64
  55. }
  56. type CpuList struct {
  57. List []Cpu
  58. }
  59. type FileSystem struct {
  60. DirName string
  61. DevName string
  62. TypeName string
  63. SysTypeName string
  64. Options string
  65. Flags uint32
  66. }
  67. type FileSystemList struct {
  68. List []FileSystem
  69. }
  70. type FileSystemUsage struct {
  71. Total uint64
  72. Used uint64
  73. Free uint64
  74. Avail uint64
  75. Files uint64
  76. FreeFiles uint64
  77. }
  78. type ProcList struct {
  79. List []int
  80. }
  81. type RunState byte
  82. const (
  83. RunStateSleep = 'S'
  84. RunStateRun = 'R'
  85. RunStateStop = 'T'
  86. RunStateZombie = 'Z'
  87. RunStateIdle = 'D'
  88. RunStateUnknown = '?'
  89. )
  90. type ProcState struct {
  91. Name string
  92. State RunState
  93. Ppid int
  94. Tty int
  95. Priority int
  96. Nice int
  97. Processor int
  98. }
  99. type ProcMem struct {
  100. Size uint64
  101. Resident uint64
  102. Share uint64
  103. MinorFaults uint64
  104. MajorFaults uint64
  105. PageFaults uint64
  106. }
  107. type ProcTime struct {
  108. StartTime uint64
  109. User uint64
  110. Sys uint64
  111. Total uint64
  112. }
  113. type ProcArgs struct {
  114. List []string
  115. }
  116. type ProcExe struct {
  117. Name string
  118. Cwd string
  119. Root string
  120. }