1
0
Fork 0

cputime 표기방식 바꿈

This commit is contained in:
Sangbum Kim 2018-07-14 01:57:27 +09:00
parent 505d6b8332
commit 9f8fed3b85
2 changed files with 55 additions and 55 deletions

View File

@ -16,9 +16,9 @@ import (
) )
type NetIOInfo struct { type NetIOInfo struct {
Name string `json:"name"` Name string `json:"name"`
RxKBytes int64 `json:"rx_kbytes"` RxKBytes int64 `json:"rx_kbytes"`
TxKBytes int64 `json:"tx_kbytes"` TxKBytes int64 `json:"tx_kbytes"`
} }
type MemoryInfo struct { type MemoryInfo struct {
@ -39,6 +39,7 @@ type LoadInfo struct {
Avg15 float64 `json:"avg_15"` Avg15 float64 `json:"avg_15"`
} }
type CPUInfo struct { type CPUInfo struct {
Total float64 `json:"total"`
Idle float64 `json:"idle"` Idle float64 `json:"idle"`
Nice float64 `json:"nice"` Nice float64 `json:"nice"`
System float64 `json:"system"` 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 swapUsed: ", misc.FileSizeIEC(memoryInfo.SwapUsed))
p.logger.Debug("memory used: ", misc.FileSizeIEC(memoryInfo.Used)) p.logger.Debug("memory used: ", misc.FileSizeIEC(memoryInfo.Used))
info.Memory.Total = int64(memoryInfo.Total>>10) info.Memory.Total = int64(memoryInfo.Total >> 10)
info.Memory.Active = int64(memoryInfo.Active>>10) info.Memory.Active = int64(memoryInfo.Active >> 10)
info.Memory.Cached = int64(memoryInfo.Cached>>10) info.Memory.Cached = int64(memoryInfo.Cached >> 10)
info.Memory.Free = int64(memoryInfo.Free>>10) info.Memory.Free = int64(memoryInfo.Free >> 10)
info.Memory.Inactive = int64(memoryInfo.Inactive>>10) info.Memory.Inactive = int64(memoryInfo.Inactive >> 10)
info.Memory.SwapFree = int64(memoryInfo.SwapFree>>10) info.Memory.SwapFree = int64(memoryInfo.SwapFree >> 10)
info.Memory.SwapTotal = int64(memoryInfo.SwapTotal>>10) info.Memory.SwapTotal = int64(memoryInfo.SwapTotal >> 10)
info.Memory.SwapUsed = int64(memoryInfo.SwapUsed>>10) info.Memory.SwapUsed = int64(memoryInfo.SwapUsed >> 10)
info.Memory.Used = int64(memoryInfo.Used>>10) info.Memory.Used = int64(memoryInfo.Used >> 10)
return 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 rxBytes: ", misc.FileSizeIEC(netio.RxBytes))
p.logger.Debug("netio txBytes: ", misc.FileSizeIEC(netio.TxBytes)) p.logger.Debug("netio txBytes: ", misc.FileSizeIEC(netio.TxBytes))
netIoMap[netio.Name] = NetIOInfo{ netIoMap[netio.Name] = NetIOInfo{
Name: netio.Name, Name: netio.Name,
RxKBytes: int64(netio.RxBytes>>10), RxKBytes: int64(netio.RxBytes >> 10),
TxKBytes: int64(netio.TxBytes>>10), TxKBytes: int64(netio.TxBytes >> 10),
} }
} }
info.NetIO = netIoMap 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: system=%d", ct.System)
p.logger.Debugf("readCpuStat: total=%d", ct.Total) p.logger.Debugf("readCpuStat: total=%d", ct.Total)
p.logger.Debugf("readCpuStat: user=%d", ct.User) 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.Total = float64(ct.Total)
info.CPU.Nice = float64(ct.Nice*100) / float64(ct.Total) info.CPU.Idle = float64(ct.Idle)
info.CPU.System = float64(ct.System*100) / float64(ct.Total) info.CPU.Nice = float64(ct.Nice)
info.CPU.User = float64(ct.User*100) / float64(ct.Total) info.CPU.System = float64(ct.System)
info.CPU.User = float64(ct.User)
return return
} }

View File

@ -17,15 +17,15 @@ import (
) )
type NetIOInfo struct { type NetIOInfo struct {
Name string `json:"name"` Name string `json:"name"`
RxKBytes int64 `json:"rx_kbytes"` RxKBytes int64 `json:"rx_kbytes"`
TxKBytes int64 `json:"tx_kbytes"` TxKBytes int64 `json:"tx_kbytes"`
} }
type DiskIOInfo struct { type DiskIOInfo struct {
Name string `json:"name"` Name string `json:"name"`
ReadsCompletedKBytes int64 `json:"reads_completed_kbytes"` ReadsCompletedKBytes int64 `json:"reads_completed_kbytes"`
WritesCompletedKBytes int64 `json:"writes_completed_kbytes"` WritesCompletedKBytes int64 `json:"writes_completed_kbytes"`
} }
type MemoryInfo struct { type MemoryInfo struct {
Total int64 `json:"total_kbytes"` Total int64 `json:"total_kbytes"`
@ -48,6 +48,7 @@ type LoadInfo struct {
} }
type CPUInfo struct { type CPUInfo struct {
Total float64 `json:"total"`
User float64 `json:"user"` User float64 `json:"user"`
Nice float64 `json:"nice"` Nice float64 `json:"nice"`
System float64 `json:"system"` 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 swapCached: ", misc.FileSizeIEC(memoryInfo.SwapCached))
p.logger.Debug("memory swapFree: ", misc.FileSizeIEC(memoryInfo.SwapFree)) p.logger.Debug("memory swapFree: ", misc.FileSizeIEC(memoryInfo.SwapFree))
info.Memory.Total = int64(memoryInfo.Total>>10) info.Memory.Total = int64(memoryInfo.Total >> 10)
info.Memory.Used = int64(memoryInfo.Used>>10) info.Memory.Used = int64(memoryInfo.Used >> 10)
info.Memory.Available = int64(memoryInfo.Available>>10) info.Memory.Available = int64(memoryInfo.Available >> 10)
info.Memory.Buffers = int64(memoryInfo.Buffers>>10) info.Memory.Buffers = int64(memoryInfo.Buffers >> 10)
info.Memory.Cached = int64(memoryInfo.Cached>>10) info.Memory.Cached = int64(memoryInfo.Cached >> 10)
info.Memory.Free = int64(memoryInfo.Free>>10) info.Memory.Free = int64(memoryInfo.Free >> 10)
info.Memory.Active = int64(memoryInfo.Active>>10) info.Memory.Active = int64(memoryInfo.Active >> 10)
info.Memory.Inactive = int64(memoryInfo.Inactive>>10) info.Memory.Inactive = int64(memoryInfo.Inactive >> 10)
info.Memory.SwapTotal = int64(memoryInfo.SwapTotal>>10) info.Memory.SwapTotal = int64(memoryInfo.SwapTotal >> 10)
info.Memory.SwapUsed = int64(memoryInfo.SwapUsed>>10) info.Memory.SwapUsed = int64(memoryInfo.SwapUsed >> 10)
info.Memory.SwapCached = int64(memoryInfo.SwapCached>>10) info.Memory.SwapCached = int64(memoryInfo.SwapCached >> 10)
info.Memory.SwapFree = int64(memoryInfo.SwapFree>>10) info.Memory.SwapFree = int64(memoryInfo.SwapFree >> 10)
} }
func (p *osMetric) readLoadStat(info *OSMetricInfo, errChan chan<- error, waiter *sync.WaitGroup) { 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 rxBytes: ", misc.FileSizeIEC(netio.RxBytes))
p.logger.Debug("netio txBytes: ", misc.FileSizeIEC(netio.TxBytes)) p.logger.Debug("netio txBytes: ", misc.FileSizeIEC(netio.TxBytes))
netIoMap[netio.Name] = NetIOInfo{ netIoMap[netio.Name] = NetIOInfo{
Name: netio.Name, Name: netio.Name,
RxKBytes: int64(netio.RxBytes>>10), RxKBytes: int64(netio.RxBytes >> 10),
TxKBytes: int64(netio.TxBytes>>10), TxKBytes: int64(netio.TxBytes >> 10),
} }
} }
info.NetIO = netIoMap 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 softirq: %f%%", float64(ct.Softirq*100)/float64(ct.Total))
p.logger.Debugf("cpu steal: %f%%", float64(ct.Steal*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.Total = float64(ct.Total)
info.CPU.Nice = float64(ct.Nice*100) / float64(ct.Total) info.CPU.User = float64(ct.User)
info.CPU.System = float64(ct.System*100) / float64(ct.Total) info.CPU.Nice = float64(ct.Nice)
info.CPU.Idle = float64(ct.Idle*100) / float64(ct.Total) info.CPU.System = float64(ct.System)
info.CPU.Iowait = float64(ct.Iowait*100) / float64(ct.Total) info.CPU.Idle = float64(ct.Idle)
info.CPU.Irq = float64(ct.Irq*100) / float64(ct.Total) info.CPU.Iowait = float64(ct.Iowait)
info.CPU.Softirq = float64(ct.Softirq*100) / float64(ct.Total) info.CPU.Irq = float64(ct.Irq)
info.CPU.Steal = float64(ct.Steal*100) / float64(ct.Total) info.CPU.Softirq = float64(ct.Softirq)
info.CPU.Steal = float64(ct.Steal)
return 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 read: ", misc.FileSizeIEC(dsk.ReadsCompleted))
p.logger.Debug("disk written: ", misc.FileSizeIEC(dsk.WritesCompleted)) p.logger.Debug("disk written: ", misc.FileSizeIEC(dsk.WritesCompleted))
diskIoMap[dsk.Name] = DiskIOInfo{ diskIoMap[dsk.Name] = DiskIOInfo{
Name: dsk.Name, Name: dsk.Name,
ReadsCompletedKBytes: int64(dsk.ReadsCompleted>>10), ReadsCompletedKBytes: int64(dsk.ReadsCompleted >> 10),
WritesCompletedKBytes: int64(dsk.WritesCompleted>>10), WritesCompletedKBytes: int64(dsk.WritesCompleted >> 10),
} }
} }
info.DiskIO = diskIoMap info.DiskIO = diskIoMap