diff --git a/producer/os_darwin.go b/producer/os_darwin.go index db7b8af..bde909d 100644 --- a/producer/os_darwin.go +++ b/producer/os_darwin.go @@ -16,9 +16,9 @@ import ( ) type NetIOInfo struct { - Name string `json:"name"` - RxKBytes int64 `json:"rx_kbytes"` - TxKBytes int64 `json:"tx_kbytes"` + Name string `json:"name"` + RxKBytes int64 `json:"rx_kbytes"` + TxKBytes int64 `json:"tx_kbytes"` } type MemoryInfo struct { @@ -39,6 +39,7 @@ type LoadInfo struct { Avg15 float64 `json:"avg_15"` } type CPUInfo struct { + Total float64 `json:"total"` Idle float64 `json:"idle"` Nice float64 `json:"nice"` System float64 `json:"system"` @@ -187,15 +188,15 @@ func (p *osMetric) readMemoryStat(info *OSMetricInfo, errChan chan<- error, wait p.logger.Debug("memory swapUsed: ", misc.FileSizeIEC(memoryInfo.SwapUsed)) p.logger.Debug("memory used: ", misc.FileSizeIEC(memoryInfo.Used)) - info.Memory.Total = int64(memoryInfo.Total>>10) - info.Memory.Active = int64(memoryInfo.Active>>10) - info.Memory.Cached = int64(memoryInfo.Cached>>10) - info.Memory.Free = int64(memoryInfo.Free>>10) - info.Memory.Inactive = int64(memoryInfo.Inactive>>10) - info.Memory.SwapFree = int64(memoryInfo.SwapFree>>10) - info.Memory.SwapTotal = int64(memoryInfo.SwapTotal>>10) - info.Memory.SwapUsed = int64(memoryInfo.SwapUsed>>10) - info.Memory.Used = int64(memoryInfo.Used>>10) + info.Memory.Total = int64(memoryInfo.Total >> 10) + info.Memory.Active = int64(memoryInfo.Active >> 10) + info.Memory.Cached = int64(memoryInfo.Cached >> 10) + info.Memory.Free = int64(memoryInfo.Free >> 10) + info.Memory.Inactive = int64(memoryInfo.Inactive >> 10) + info.Memory.SwapFree = int64(memoryInfo.SwapFree >> 10) + info.Memory.SwapTotal = int64(memoryInfo.SwapTotal >> 10) + info.Memory.SwapUsed = int64(memoryInfo.SwapUsed >> 10) + info.Memory.Used = int64(memoryInfo.Used >> 10) return } @@ -249,9 +250,9 @@ func (p *osMetric) readNetworkStat(info *OSMetricInfo, errChan chan<- error, wai p.logger.Debug("netio rxBytes: ", misc.FileSizeIEC(netio.RxBytes)) p.logger.Debug("netio txBytes: ", misc.FileSizeIEC(netio.TxBytes)) netIoMap[netio.Name] = NetIOInfo{ - Name: netio.Name, - RxKBytes: int64(netio.RxBytes>>10), - TxKBytes: int64(netio.TxBytes>>10), + Name: netio.Name, + RxKBytes: int64(netio.RxBytes >> 10), + TxKBytes: int64(netio.TxBytes >> 10), } } info.NetIO = netIoMap @@ -303,15 +304,12 @@ func (p *osMetric) readCpuStat(info *OSMetricInfo, errChan chan<- error, waiter p.logger.Debugf("readCpuStat: system=%d", ct.System) p.logger.Debugf("readCpuStat: total=%d", ct.Total) p.logger.Debugf("readCpuStat: user=%d", ct.User) - p.logger.Debugf("readCpuStat: idle=%f%%", float64(ct.Idle*100)/float64(ct.Total)) - p.logger.Debugf("readCpuStat: nice=%f%%", float64(ct.Nice*100)/float64(ct.Total)) - p.logger.Debugf("readCpuStat: system=%f%%", float64(ct.System*100)/float64(ct.Total)) - p.logger.Debugf("readCpuStat: user=%f%%", float64(ct.User*100)/float64(ct.Total)) - info.CPU.Idle = float64(ct.Idle*100) / float64(ct.Total) - info.CPU.Nice = float64(ct.Nice*100) / float64(ct.Total) - info.CPU.System = float64(ct.System*100) / float64(ct.Total) - info.CPU.User = float64(ct.User*100) / float64(ct.Total) + info.CPU.Total = float64(ct.Total) + info.CPU.Idle = float64(ct.Idle) + info.CPU.Nice = float64(ct.Nice) + info.CPU.System = float64(ct.System) + info.CPU.User = float64(ct.User) return } diff --git a/producer/os_linux.go b/producer/os_linux.go index d3ce7e0..1e482d2 100644 --- a/producer/os_linux.go +++ b/producer/os_linux.go @@ -17,15 +17,15 @@ import ( ) type NetIOInfo struct { - Name string `json:"name"` - RxKBytes int64 `json:"rx_kbytes"` - TxKBytes int64 `json:"tx_kbytes"` + Name string `json:"name"` + RxKBytes int64 `json:"rx_kbytes"` + TxKBytes int64 `json:"tx_kbytes"` } type DiskIOInfo struct { - Name string `json:"name"` - ReadsCompletedKBytes int64 `json:"reads_completed_kbytes"` - WritesCompletedKBytes int64 `json:"writes_completed_kbytes"` + Name string `json:"name"` + ReadsCompletedKBytes int64 `json:"reads_completed_kbytes"` + WritesCompletedKBytes int64 `json:"writes_completed_kbytes"` } type MemoryInfo struct { Total int64 `json:"total_kbytes"` @@ -48,6 +48,7 @@ type LoadInfo struct { } type CPUInfo struct { + Total float64 `json:"total"` User float64 `json:"user"` Nice float64 `json:"nice"` System float64 `json:"system"` @@ -229,18 +230,18 @@ func (p *osMetric) readMemoryStat(info *OSMetricInfo, errChan chan<- error, wait p.logger.Debug("memory swapCached: ", misc.FileSizeIEC(memoryInfo.SwapCached)) p.logger.Debug("memory swapFree: ", misc.FileSizeIEC(memoryInfo.SwapFree)) - info.Memory.Total = int64(memoryInfo.Total>>10) - info.Memory.Used = int64(memoryInfo.Used>>10) - info.Memory.Available = int64(memoryInfo.Available>>10) - info.Memory.Buffers = int64(memoryInfo.Buffers>>10) - info.Memory.Cached = int64(memoryInfo.Cached>>10) - info.Memory.Free = int64(memoryInfo.Free>>10) - info.Memory.Active = int64(memoryInfo.Active>>10) - info.Memory.Inactive = int64(memoryInfo.Inactive>>10) - info.Memory.SwapTotal = int64(memoryInfo.SwapTotal>>10) - info.Memory.SwapUsed = int64(memoryInfo.SwapUsed>>10) - info.Memory.SwapCached = int64(memoryInfo.SwapCached>>10) - info.Memory.SwapFree = int64(memoryInfo.SwapFree>>10) + info.Memory.Total = int64(memoryInfo.Total >> 10) + info.Memory.Used = int64(memoryInfo.Used >> 10) + info.Memory.Available = int64(memoryInfo.Available >> 10) + info.Memory.Buffers = int64(memoryInfo.Buffers >> 10) + info.Memory.Cached = int64(memoryInfo.Cached >> 10) + info.Memory.Free = int64(memoryInfo.Free >> 10) + info.Memory.Active = int64(memoryInfo.Active >> 10) + info.Memory.Inactive = int64(memoryInfo.Inactive >> 10) + info.Memory.SwapTotal = int64(memoryInfo.SwapTotal >> 10) + info.Memory.SwapUsed = int64(memoryInfo.SwapUsed >> 10) + info.Memory.SwapCached = int64(memoryInfo.SwapCached >> 10) + info.Memory.SwapFree = int64(memoryInfo.SwapFree >> 10) } func (p *osMetric) readLoadStat(info *OSMetricInfo, errChan chan<- error, waiter *sync.WaitGroup) { @@ -293,9 +294,9 @@ func (p *osMetric) readNetworkStat(info *OSMetricInfo, errChan chan<- error, wai p.logger.Debug("netio rxBytes: ", misc.FileSizeIEC(netio.RxBytes)) p.logger.Debug("netio txBytes: ", misc.FileSizeIEC(netio.TxBytes)) netIoMap[netio.Name] = NetIOInfo{ - Name: netio.Name, - RxKBytes: int64(netio.RxBytes>>10), - TxKBytes: int64(netio.TxBytes>>10), + Name: netio.Name, + RxKBytes: int64(netio.RxBytes >> 10), + TxKBytes: int64(netio.TxBytes >> 10), } } info.NetIO = netIoMap @@ -361,14 +362,15 @@ func (p *osMetric) readCpuStat(info *OSMetricInfo, errChan chan<- error, waiter p.logger.Debugf("cpu softirq: %f%%", float64(ct.Softirq*100)/float64(ct.Total)) p.logger.Debugf("cpu steal: %f%%", float64(ct.Steal*100)/float64(ct.Total)) - info.CPU.User = float64(ct.User*100) / float64(ct.Total) - info.CPU.Nice = float64(ct.Nice*100) / float64(ct.Total) - info.CPU.System = float64(ct.System*100) / float64(ct.Total) - info.CPU.Idle = float64(ct.Idle*100) / float64(ct.Total) - info.CPU.Iowait = float64(ct.Iowait*100) / float64(ct.Total) - info.CPU.Irq = float64(ct.Irq*100) / float64(ct.Total) - info.CPU.Softirq = float64(ct.Softirq*100) / float64(ct.Total) - info.CPU.Steal = float64(ct.Steal*100) / float64(ct.Total) + info.CPU.Total = float64(ct.Total) + info.CPU.User = float64(ct.User) + info.CPU.Nice = float64(ct.Nice) + info.CPU.System = float64(ct.System) + info.CPU.Idle = float64(ct.Idle) + info.CPU.Iowait = float64(ct.Iowait) + info.CPU.Irq = float64(ct.Irq) + info.CPU.Softirq = float64(ct.Softirq) + info.CPU.Steal = float64(ct.Steal) return } @@ -395,9 +397,9 @@ func (p *osMetric) readDiskStat(info *OSMetricInfo, errChan chan<- error, waiter p.logger.Debug("disk read: ", misc.FileSizeIEC(dsk.ReadsCompleted)) p.logger.Debug("disk written: ", misc.FileSizeIEC(dsk.WritesCompleted)) diskIoMap[dsk.Name] = DiskIOInfo{ - Name: dsk.Name, - ReadsCompletedKBytes: int64(dsk.ReadsCompleted>>10), - WritesCompletedKBytes: int64(dsk.WritesCompleted>>10), + Name: dsk.Name, + ReadsCompletedKBytes: int64(dsk.ReadsCompleted >> 10), + WritesCompletedKBytes: int64(dsk.WritesCompleted >> 10), } } info.DiskIO = diskIoMap