|
| 1 | +package types |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "math" |
| 6 | + "time" |
| 7 | +) |
| 8 | + |
| 9 | +type SysCPUStat struct { |
| 10 | + User float64 `json:"user"` |
| 11 | + Nice float64 `json:"nice"` |
| 12 | + System float64 `json:"system"` |
| 13 | + Idle float64 `json:"idle"` |
| 14 | + Iowait float64 `json:"iowait"` |
| 15 | + IRQ float64 `json:"irq"` |
| 16 | + SoftIRQ float64 `json:"softirq"` |
| 17 | + Steal float64 `json:"steal"` |
| 18 | + Guest float64 `json:"guest"` |
| 19 | + GuestNice float64 `json:"guestNice"` |
| 20 | +} |
| 21 | + |
| 22 | +type sysCPUStatAlias SysCPUStat // avoid recursion of MarshalJSON |
| 23 | + |
| 24 | +func (s SysCPUStat) MarshalJSON() ([]byte, error) { |
| 25 | + return json.Marshal(sysCPUStatAlias{ |
| 26 | + User: math.Round(s.User*1000) / 1000, |
| 27 | + Nice: math.Round(s.Nice*1000) / 1000, |
| 28 | + System: math.Round(s.System*1000) / 1000, |
| 29 | + Idle: math.Round(s.Idle*1000) / 1000, |
| 30 | + Iowait: math.Round(s.Iowait*1000) / 1000, |
| 31 | + IRQ: math.Round(s.IRQ*1000) / 1000, |
| 32 | + SoftIRQ: math.Round(s.SoftIRQ*1000) / 1000, |
| 33 | + Steal: math.Round(s.Steal*1000) / 1000, |
| 34 | + Guest: math.Round(s.Guest*1000) / 1000, |
| 35 | + GuestNice: math.Round(s.GuestNice*1000) / 1000, |
| 36 | + }) |
| 37 | +} |
| 38 | + |
| 39 | +type ProcStat struct { |
| 40 | + ContextSwitches uint64 `json:"contextSwitches"` |
| 41 | + ProcessCreated uint64 `json:"processCreated"` |
| 42 | + ProcessesRunning uint64 `json:"processesRunning"` |
| 43 | +} |
| 44 | + |
| 45 | +type SysMemoryStat struct { |
| 46 | + Total *uint64 `json:"total"` |
| 47 | + Free *uint64 `json:"free"` |
| 48 | + Available *uint64 `json:"available"` |
| 49 | + Buffers *uint64 `json:"buffers"` |
| 50 | + Cached *uint64 `json:"cached"` |
| 51 | + Active *uint64 `json:"active"` |
| 52 | + Inactive *uint64 `json:"inactive"` |
| 53 | + Swap *uint64 `json:"swap"` |
| 54 | + Dirty *uint64 `json:"dirty"` |
| 55 | + Writeback *uint64 `json:"writeback"` |
| 56 | + Slab *uint64 `json:"slab"` |
| 57 | +} |
| 58 | + |
| 59 | +type SysSample struct { |
| 60 | + //nolint |
| 61 | + Timestamp_ time.Time `json:"timestamp"` |
| 62 | + CPUStat *SysCPUStat `json:"cpuStat,omitempty"` |
| 63 | + ProcStat *ProcStat `json:"procStat,omitempty"` |
| 64 | + MemoryStat *SysMemoryStat `json:"memoryStat,omitempty"` |
| 65 | + CPUPressure *Pressure `json:"cpuPressure,omitempty"` |
| 66 | + MemoryPressure *Pressure `json:"memoryPressure,omitempty"` |
| 67 | + IOPressure *Pressure `json:"ioPressure,omitempty"` |
| 68 | +} |
| 69 | + |
| 70 | +func (s *SysSample) Timestamp() time.Time { |
| 71 | + return s.Timestamp_ |
| 72 | +} |
0 commit comments