mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-12 16:36:12 +08:00
feat: 网络模块增加全部选项
This commit is contained in:
parent
7a42e34c2b
commit
4e56e041be
3 changed files with 23 additions and 9 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue