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

@ -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
}
@ -250,8 +251,8 @@ func (p *osMetric) readNetworkStat(info *OSMetricInfo, errChan chan<- error, wai
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),
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
}

View File

@ -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) {
@ -294,8 +295,8 @@ func (p *osMetric) readNetworkStat(info *OSMetricInfo, errChan chan<- error, wai
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),
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
}
@ -396,8 +398,8 @@ func (p *osMetric) readDiskStat(info *OSMetricInfo, errChan chan<- error, waiter
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),
ReadsCompletedKBytes: int64(dsk.ReadsCompleted >> 10),
WritesCompletedKBytes: int64(dsk.WritesCompleted >> 10),
}
}
info.DiskIO = diskIoMap