mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-10 09:02:42 +08:00
fix: 监控数据改为批量插入 (#512)
This commit is contained in:
parent
8902fdc78a
commit
c63967158b
1 changed files with 12 additions and 9 deletions
|
@ -66,6 +66,7 @@ func loadDiskIO() {
|
|||
time.Sleep(60 * time.Second)
|
||||
|
||||
ioStat2, _ := disk.IOCounters()
|
||||
var ioList []model.MonitorIO
|
||||
for _, io2 := range ioStat2 {
|
||||
for _, io1 := range ioStat {
|
||||
if io2.Name == io1.Name {
|
||||
|
@ -85,13 +86,14 @@ func loadDiskIO() {
|
|||
if writeTime > itemIO.Time {
|
||||
itemIO.Time = writeTime
|
||||
}
|
||||
if err := global.DB.Create(&itemIO).Error; err != nil {
|
||||
global.LOG.Errorf("Insert io monitoring data failed, err: %v", err)
|
||||
}
|
||||
ioList = append(ioList, itemIO)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := global.DB.CreateInBatches(ioList, len(ioList)).Error; err != nil {
|
||||
global.LOG.Errorf("Insert io monitoring data failed, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func loadNetIO() {
|
||||
|
@ -101,6 +103,7 @@ func loadNetIO() {
|
|||
time.Sleep(60 * time.Second)
|
||||
|
||||
netStat2, _ := net.IOCounters(true)
|
||||
var netList []model.MonitorNetwork
|
||||
for _, net2 := range netStat2 {
|
||||
for _, net1 := range netStat {
|
||||
if net2.Name == net1.Name {
|
||||
|
@ -108,9 +111,7 @@ func loadNetIO() {
|
|||
itemNet.Name = net1.Name
|
||||
itemNet.Up = float64(net2.BytesSent-net1.BytesSent) / 1024 / 60
|
||||
itemNet.Down = float64(net2.BytesRecv-net1.BytesRecv) / 1024 / 60
|
||||
if err := global.DB.Create(&itemNet).Error; err != nil {
|
||||
global.LOG.Errorf("Insert network monitoring data failed, err: %v", err)
|
||||
}
|
||||
netList = append(netList, itemNet)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -126,11 +127,13 @@ func loadNetIO() {
|
|||
itemNet.Name = net1.Name
|
||||
itemNet.Up = float64(net2.BytesSent-net1.BytesSent) / 1024 / 60
|
||||
itemNet.Down = float64(net2.BytesRecv-net1.BytesRecv) / 1024 / 60
|
||||
if err := global.DB.Create(&itemNet).Error; err != nil {
|
||||
global.LOG.Errorf("Insert network all monitoring data failed, err: %v", err)
|
||||
}
|
||||
netList = append(netList, itemNet)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := global.DB.CreateInBatches(netList, len(netList)).Error; err != nil {
|
||||
global.LOG.Errorf("Insert network monitoring data failed, err: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue