diff --git a/backend/app/api/v1/monitor.go b/backend/app/api/v1/monitor.go index d1208c4c8..0fdc4cf4e 100644 --- a/backend/app/api/v1/monitor.go +++ b/backend/app/api/v1/monitor.go @@ -85,6 +85,7 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) { func (b *BaseApi) GetNetworkOptions(c *gin.Context) { netStat, _ := net.IOCounters(true) var options []string + options = append(options, "all") for _, net := range netStat { options = append(options, net.Name) } diff --git a/backend/cron/job/monitor.go b/backend/cron/job/monitor.go index 1549d3cb4..008242e80 100644 --- a/backend/cron/job/monitor.go +++ b/backend/cron/job/monitor.go @@ -86,4 +86,20 @@ func (m *monitor) Run() { itemNet.Down = float64(v.BytesRecv-aheadData.BytesRecv) / 1024 / stime _ = global.DB.Create(&itemNet) } + netStatAll, _ := net.IOCounters(false) + if len(netStatAll) != 0 { + var itemNet model.MonitorNetwork + var aheadData model.MonitorNetwork + itemNet.Name = netStatAll[0].Name + itemNet.BytesSent = netStatAll[0].BytesSent + itemNet.BytesRecv = netStatAll[0].BytesRecv + if err := global.DB.Where("name = ?", netStatAll[0].Name).Order("created_at").Find(&aheadData).Error; err != nil { + _ = global.DB.Create(&itemNet) + return + } + stime := time.Since(aheadData.CreatedAt).Seconds() + itemNet.Up = float64(netStatAll[0].BytesSent-aheadData.BytesSent) / 1024 / stime + itemNet.Down = float64(netStatAll[0].BytesRecv-aheadData.BytesRecv) / 1024 / stime + _ = global.DB.Create(&itemNet) + } } diff --git a/frontend/src/views/monitor/index.vue b/frontend/src/views/monitor/index.vue index 2a6456d6b..9d43e1aac 100644 --- a/frontend/src/views/monitor/index.vue +++ b/frontend/src/views/monitor/index.vue @@ -158,27 +158,24 @@ const shortcuts = [ { text: i18n.global.t('monitor.lastNDay', [3]), value: () => { - const yestoday = new Date(new Date().getTime() - 3600 * 1000 * 24 * 3); - const end = new Date(yestoday.setHours(23, 59, 59, 999)); - const start = new Date(yestoday.setHours(0, 0, 0, 0)); + const start = new Date(new Date().getTime() - 3600 * 1000 * 24 * 3); + const end = new Date(); return [start, end]; }, }, { text: i18n.global.t('monitor.lastNDay', [7]), value: () => { - const lastweek = new Date(new Date().getTime() - 3600 * 1000 * 24 * 7); - const end = new Date(lastweek.setHours(23, 59, 59, 999)); - const start = new Date(lastweek.setHours(0, 0, 0, 0)); + const start = new Date(new Date().getTime() - 3600 * 1000 * 24 * 7); + const end = new Date(); return [start, end]; }, }, { text: i18n.global.t('monitor.lastNDay', [30]), value: () => { - const lastmonth = new Date(new Date().getTime() - 3600 * 1000 * 24 * 7); - const end = new Date(lastmonth.setHours(23, 59, 59, 999)); - const start = new Date(lastmonth.setHours(0, 0, 0, 0)); + const start = new Date(new Date().getTime() - 3600 * 1000 * 24 * 30); + const end = new Date(); return [start, end]; }, },