mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-05 22:25:49 +08:00
feat: 监控数据采集落库
This commit is contained in:
parent
c46bf0ec4f
commit
4ba55298b4
18 changed files with 380 additions and 14 deletions
24
backend/app/api/v1/monitor.go
Normal file
24
backend/app/api/v1/monitor.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/app/api/v1/helper"
|
||||
"github.com/1Panel-dev/1Panel/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/constant"
|
||||
"github.com/1Panel-dev/1Panel/global"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (b *BaseApi) LoadMonitor(c *gin.Context) {
|
||||
var req dto.MonitorSearch
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
}
|
||||
if err := global.VALID.Struct(req); err != nil {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||
return
|
||||
}
|
||||
|
||||
// stampStart := req.StartTime.Unix()
|
||||
// stampEnd := req.EndTime.Unix()
|
||||
}
|
47
backend/app/api/v1/monitor_test.go
Normal file
47
backend/app/api/v1/monitor_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
"github.com/shirou/gopsutil/net"
|
||||
)
|
||||
|
||||
func TestMonito(t *testing.T) {
|
||||
totalPercent, _ := cpu.Percent(3*time.Second, false) // 总 cpu 使用
|
||||
perPercents, _ := cpu.Percent(3*time.Second, true) // 各 cpu 使用
|
||||
fmt.Println("================totalPercent============", totalPercent)
|
||||
fmt.Println("================perPercents=============", perPercents)
|
||||
|
||||
info, _ := load.Avg()
|
||||
info2, _ := load.Misc()
|
||||
fmt.Printf("load: \n loadxx: %v load1: %v, load5: %v, load15: %v \n\n", info2, info.Load1, info.Load5, info.Load15)
|
||||
|
||||
memory, _ := mem.VirtualMemory()
|
||||
fmt.Printf("memory: \n memory used: %v, use persent: %v \n\n", memory.Used, memory.UsedPercent)
|
||||
|
||||
diskPart, _ := disk.Partitions(true)
|
||||
// fmt.Println("================disk=============", diskPart)
|
||||
for _, part := range diskPart {
|
||||
diskInfo, _ := disk.Usage(part.Mountpoint)
|
||||
fmt.Printf("inode,disk(%v): \n inode persent: %v, disk used: %v, persent: %v \n", part.Mountpoint, diskInfo.InodesUsedPercent, diskInfo.Used, diskInfo.UsedPercent)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
ioStat, _ := disk.IOCounters()
|
||||
for _, v := range ioStat {
|
||||
fmt.Printf("io: \n name: %v, readCount: %v, writeCount: %v \n\n", v.Name, v.ReadCount, v.WriteCount)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
net, _ := net.IOCounters(false)
|
||||
for _, v := range net {
|
||||
fmt.Printf("netio: \n %v: send:%v recv:%v \n\n", v.Name, v.BytesSent, v.BytesRecv)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
10
backend/app/dto/monitor.go
Normal file
10
backend/app/dto/monitor.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package dto
|
||||
|
||||
import "time"
|
||||
|
||||
type MonitorSearch struct {
|
||||
Param string `json:"param" validate:"required,oneof=all cpu memory load disk inode io iops network"`
|
||||
StartTime time.Time `json:"startTime"`
|
||||
EndTime time.Time `json:"endTime"`
|
||||
Unit string `josn:"unit"`
|
||||
}
|
31
backend/app/model/monitor.go
Normal file
31
backend/app/model/monitor.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package model
|
||||
|
||||
type MonitorBase struct {
|
||||
BaseModel
|
||||
Cpu float64 `gorm:"type:float" json:"cpu"`
|
||||
|
||||
LoadUsage float64 `gorm:"type:float" json:"loadUsage"`
|
||||
CpuLoad1 float64 `gorm:"type:float" json:"cpuLoad1"`
|
||||
CpuLoad5 float64 `gorm:"type:float" json:"cpuLoad5"`
|
||||
CpuLoad15 float64 `gorm:"type:float" json:"cpuLoad15"`
|
||||
|
||||
Memory float64 `gorm:"type:float" json:"memory"`
|
||||
}
|
||||
|
||||
type MonitorIO struct {
|
||||
BaseModel
|
||||
Name string `json:"name"`
|
||||
ReadCount uint64 `gorm:"type:decimal" json:"readCount"`
|
||||
WriteCount uint64 `gorm:"type:decimal" json:"writeCount"`
|
||||
ReadTime uint64 `gorm:"type:decimal" json:"readTime"`
|
||||
WriteTime uint64 `gorm:"type:decimal" json:"writeTime"`
|
||||
ReadByte uint64 `gorm:"type:decimal(32)" json:"readByte"`
|
||||
WriteByte uint64 `gorm:"type:decimal(32)" json:"writeByte"`
|
||||
}
|
||||
|
||||
type MonitorNetwork struct {
|
||||
BaseModel
|
||||
Name string `json:"name"`
|
||||
BytesSent uint64 `gorm:"type:decimal(32)" json:"bytesSent"`
|
||||
BytesRecv uint64 `gorm:"type:decimal(32)" json:"bytesRecv"`
|
||||
}
|
21
backend/cron/corn.go
Normal file
21
backend/cron/corn.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package cron
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/cron/job"
|
||||
"github.com/1Panel-dev/1Panel/global"
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
func Run() {
|
||||
nyc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
Cron := cron.New(cron.WithLocation(nyc))
|
||||
_, err := Cron.AddJob("@every 1m", job.NewMonitorJob())
|
||||
if err != nil {
|
||||
global.LOG.Errorf("can not add corn job: %s", err.Error())
|
||||
}
|
||||
Cron.Start()
|
||||
|
||||
global.Corn = Cron
|
||||
}
|
61
backend/cron/job/monitor.go
Normal file
61
backend/cron/job/monitor.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
package job
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/app/model"
|
||||
"github.com/1Panel-dev/1Panel/global"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
"github.com/shirou/gopsutil/net"
|
||||
)
|
||||
|
||||
type monitor struct{}
|
||||
|
||||
func NewMonitorJob() *monitor {
|
||||
return &monitor{}
|
||||
}
|
||||
|
||||
func (m *monitor) Run() {
|
||||
var itemModel model.MonitorBase
|
||||
totalPercent, _ := cpu.Percent(3*time.Second, false)
|
||||
if len(totalPercent) == 1 {
|
||||
itemModel.Cpu = totalPercent[0]
|
||||
}
|
||||
cpuCount, _ := cpu.Counts(false)
|
||||
|
||||
loadInfo, _ := load.Avg()
|
||||
itemModel.CpuLoad1 = loadInfo.Load1
|
||||
itemModel.CpuLoad5 = loadInfo.Load5
|
||||
itemModel.CpuLoad15 = loadInfo.Load15
|
||||
itemModel.LoadUsage = loadInfo.Load1 / (float64(cpuCount*2) * 0.75) * 100
|
||||
|
||||
memoryInfo, _ := mem.VirtualMemory()
|
||||
itemModel.Memory = memoryInfo.UsedPercent
|
||||
|
||||
_ = global.DB.Create(&itemModel)
|
||||
|
||||
ioStat, _ := disk.IOCounters()
|
||||
for _, v := range ioStat {
|
||||
var itemIO model.MonitorIO
|
||||
itemIO.Name = v.Name
|
||||
itemIO.ReadCount = v.ReadCount
|
||||
itemIO.WriteCount = v.WriteCount
|
||||
itemIO.ReadByte = v.ReadBytes
|
||||
itemIO.WriteByte = v.WriteBytes
|
||||
itemIO.ReadTime = v.ReadTime
|
||||
itemIO.WriteTime = v.WriteTime
|
||||
_ = global.DB.Create(&itemIO)
|
||||
}
|
||||
|
||||
netStat, _ := net.IOCounters(true)
|
||||
for _, v := range netStat {
|
||||
var itemNet model.MonitorNetwork
|
||||
itemNet.Name = v.Name
|
||||
itemNet.BytesSent = v.BytesSent
|
||||
itemNet.BytesRecv = v.BytesRecv
|
||||
_ = global.DB.Create(&itemNet)
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||
"github.com/1Panel-dev/1Panel/init/cache/badger_db"
|
||||
"github.com/1Panel-dev/1Panel/init/session/psession"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/robfig/cron/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
@ -16,4 +17,6 @@ var (
|
|||
VALID *validator.Validate
|
||||
SESSION *psession.PSession
|
||||
CACHE *badger_db.Cache
|
||||
|
||||
Corn *cron.Cron
|
||||
)
|
||||
|
|
|
@ -20,7 +20,9 @@ require (
|
|||
github.com/natefinch/lumberjack v2.0.0+incompatible
|
||||
github.com/nicksnyder/go-i18n/v2 v2.1.2
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/spf13/viper v1.12.0
|
||||
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
|
||||
|
@ -43,6 +45,7 @@ require (
|
|||
github.com/dgraph-io/ristretto v0.1.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.5 // indirect
|
||||
github.com/go-openapi/jsonreference v0.19.6 // indirect
|
||||
github.com/go-openapi/spec v0.20.4 // indirect
|
||||
|
@ -80,7 +83,10 @@ require (
|
|||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.3.0 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||
github.com/tklauser/numcpus v0.4.0 // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b // indirect
|
||||
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
|
||||
|
|
|
@ -106,6 +106,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
|
|||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.0.2 h1:YV4Lc5yMQX8ahVW0ENPq6sPhrhdkGukc6fPRYmZ1R6Y=
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.0.2/go.mod h1:vld36QpBTfTzLealsHsmQQJK5lSwJt6wiORv+oFX8/I=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
|
@ -313,6 +315,8 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR
|
|||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
|
@ -321,6 +325,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
|
|||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
|
@ -367,6 +373,10 @@ github.com/swaggo/gin-swagger v1.5.1/go.mod h1:Cbj/MlHApPOjZdf4joWFXLLgmZVPyh54G
|
|||
github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ=
|
||||
github.com/swaggo/swag v1.8.4 h1:oGB351qH1JqUqK1tsMYEE5qTBbPk394BhsZxmUfebcI=
|
||||
github.com/swaggo/swag v1.8.4/go.mod h1:jMLeXOOmYyjk8PvHTsXBdrubsNd9gUJTTCzL5iBnseg=
|
||||
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
|
||||
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
|
||||
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
|
||||
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
|
@ -380,6 +390,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
|||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
|
@ -505,6 +517,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -538,6 +551,7 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
5
backend/init/cache/badger_db/badger_db.go
vendored
5
backend/init/cache/badger_db/badger_db.go
vendored
|
@ -2,9 +2,10 @@ package badger_db
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
"github.com/pkg/errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
|
@ -53,7 +54,7 @@ func (c *Cache) Get(key string) ([]byte, error) {
|
|||
}
|
||||
err = item.Value(func(val []byte) error {
|
||||
result = append([]byte{}, val...)
|
||||
return nil
|
||||
return err
|
||||
})
|
||||
return nil
|
||||
})
|
||||
|
|
|
@ -13,6 +13,7 @@ func Init() {
|
|||
migrations.AddData,
|
||||
migrations.AddTableOperationLog,
|
||||
migrations.AddTableHost,
|
||||
migrations.AddTablemonitor,
|
||||
})
|
||||
if err := m.Migrate(); err != nil {
|
||||
global.LOG.Error(err)
|
||||
|
|
|
@ -53,3 +53,10 @@ var AddTableHost = &gormigrate.Migration{
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var AddTablemonitor = &gormigrate.Migration{
|
||||
ID: "20200905-add-table-monitor",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.AutoMigrate(&model.MonitorBase{}, &model.MonitorIO{}, &model.MonitorNetwork{})
|
||||
},
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/cron"
|
||||
"github.com/1Panel-dev/1Panel/init/cache"
|
||||
"github.com/1Panel-dev/1Panel/init/session"
|
||||
"github.com/1Panel-dev/1Panel/init/session/psession"
|
||||
|
@ -31,6 +32,7 @@ func Start() {
|
|||
cache.Init()
|
||||
session.Init()
|
||||
gin.SetMode(global.CONF.System.Level)
|
||||
cron.Run()
|
||||
|
||||
routers := router.Routers()
|
||||
address := fmt.Sprintf(":%d", global.CONF.System.Port)
|
||||
|
|
|
@ -64,6 +64,7 @@ export default {
|
|||
menu: {
|
||||
home: 'Dashboard',
|
||||
demo: 'Demo',
|
||||
monitor: 'Monitor',
|
||||
terminal: 'Terminal',
|
||||
operations: 'Operation logs',
|
||||
},
|
||||
|
|
|
@ -65,6 +65,7 @@ export default {
|
|||
home: '概览',
|
||||
demo: '样例',
|
||||
terminal: '终端管理',
|
||||
monitor: '监控',
|
||||
operations: '操作记录',
|
||||
},
|
||||
home: {
|
||||
|
|
28
frontend/src/routers/modules/monitor.ts
Normal file
28
frontend/src/routers/modules/monitor.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { Layout } from '@/routers/constant';
|
||||
|
||||
const monitorRouter = {
|
||||
sort: 2,
|
||||
path: '/monitors',
|
||||
component: Layout,
|
||||
redirect: '/monitor',
|
||||
meta: {
|
||||
title: 'menu.monitor',
|
||||
icon: 'monitor',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/monitors/monitor',
|
||||
name: 'Monitor',
|
||||
component: () => import('@/views/monitor/index.vue'),
|
||||
meta: {
|
||||
requiresAuth: true,
|
||||
key: 'Monitor',
|
||||
title: 'menu.monitor',
|
||||
icon: 'Connection',
|
||||
activeMenu: '/monitors',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default monitorRouter;
|
119
frontend/src/views/monitor/index.vue
Normal file
119
frontend/src/views/monitor/index.vue
Normal file
|
@ -0,0 +1,119 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="24">
|
||||
<el-card style="overflow: inherit">
|
||||
<template #header>
|
||||
<span style="font-size: '30px'; font-weight: 500">平均负载</span>
|
||||
<el-radio-group style="float: right" size="small" v-model="loadRadio">
|
||||
<el-radio-button label="昨天" />
|
||||
<el-radio-button label="今天" />
|
||||
<el-radio-button label="最近 7 天" />
|
||||
<el-radio-button label="最近 30 天" />
|
||||
<el-radio-button label="自定义时间" />
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<div id="loadChart1" style="width: 100%; height: 300%"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-card style="overflow: inherit">
|
||||
<template #header>
|
||||
<span style="font-size: '30px'; font-weight: 500">CPU</span>
|
||||
<el-radio-group style="float: right" size="small" v-model="loadRadio">
|
||||
<el-radio-button label="昨天" />
|
||||
<el-radio-button label="今天" />
|
||||
<el-radio-button label="最近 7 天" />
|
||||
<el-radio-button label="最近 30 天" />
|
||||
<el-radio-button label="自定义时间" />
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<div id="loadChart2" style="width: 100%; height: 300%"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card style="overflow: inherit">
|
||||
<template #header>
|
||||
<span style="font-size: '30px'; font-weight: 500">内存</span>
|
||||
<el-radio-group style="float: right" size="small" v-model="loadRadio">
|
||||
<el-radio-button label="昨天" />
|
||||
<el-radio-button label="今天" />
|
||||
<el-radio-button label="最近 7 天" />
|
||||
<el-radio-button label="最近 30 天" />
|
||||
<el-radio-button label="自定义时间" />
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<div id="loadChart3" style="width: 100%; height: 300%"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-card style="overflow: inherit">
|
||||
<template #header>
|
||||
<span style="font-size: '30px'; font-weight: 500">磁盘IO</span>
|
||||
<el-radio-group style="float: right" size="small" v-model="loadRadio">
|
||||
<el-radio-button label="昨天" />
|
||||
<el-radio-button label="今天" />
|
||||
<el-radio-button label="最近 7 天" />
|
||||
<el-radio-button label="最近 30 天" />
|
||||
<el-radio-button label="自定义时间" />
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<div id="loadChart4" style="width: 100%; height: 300%"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card style="overflow: inherit">
|
||||
<template #header>
|
||||
<span style="font-size: '30px'; font-weight: 500">网络IO:</span>
|
||||
<el-radio-group style="float: right" size="small" v-model="loadRadio">
|
||||
<el-radio-button label="昨天" />
|
||||
<el-radio-button label="今天" />
|
||||
<el-radio-button label="最近 7 天" />
|
||||
<el-radio-button label="最近 30 天" />
|
||||
<el-radio-button label="自定义时间" />
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<div id="loadChart5" style="width: 100%; height: 300%"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import * as echarts from 'echarts';
|
||||
|
||||
const loadRadio = ref();
|
||||
|
||||
function initCharts(key: string) {
|
||||
console.log(key);
|
||||
const lineChart = echarts.init(document.getElementById(key) as HTMLElement);
|
||||
const option = {
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
data: [820, 932, 901, 934, 1290, 1330, 1320],
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
lineChart.setOption(option, true);
|
||||
}
|
||||
onMounted(() => {
|
||||
for (let i = 1; i < 6; i++) {
|
||||
initCharts('loadChart' + i);
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -174,7 +174,7 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onBeforeMount, ref, watch, nextTick, reactive, getCurrentInstance } from 'vue';
|
||||
import { onMounted, onBeforeMount, ref, watch, reactive, getCurrentInstance } from 'vue';
|
||||
import { Rules } from '@/global/form-rues';
|
||||
import { testConn, getHostTree, addHost } from '@/api/modules/host';
|
||||
import { getCommandList } from '@/api/modules/command';
|
||||
|
@ -396,13 +396,6 @@ const onConnLocal = () => {
|
|||
terminalValue.value = `127.0.0.1-${tabIndex}`;
|
||||
};
|
||||
|
||||
function changeFrameHeight() {
|
||||
let ifm = document.getElementById('iframeTerminal') as HTMLInputElement | null;
|
||||
if (ifm) {
|
||||
ifm.style.height = document.documentElement.clientHeight - 300 + 'px';
|
||||
}
|
||||
}
|
||||
|
||||
function syncTerminal() {
|
||||
for (const terminal of terminalTabs.value) {
|
||||
if (ctx && ctx.refs[`Ref${terminal.key}`][0]) {
|
||||
|
@ -413,10 +406,6 @@ function syncTerminal() {
|
|||
|
||||
onMounted(() => {
|
||||
onConnLocal();
|
||||
nextTick(() => {
|
||||
changeFrameHeight();
|
||||
window.addEventListener('resize', changeFrameHeight);
|
||||
});
|
||||
loadHost();
|
||||
loadCommand();
|
||||
timer = setInterval(() => {
|
||||
|
|
Loading…
Add table
Reference in a new issue