Skip to content

Commit

Permalink
implemented the tracking of encoding queue stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed Jan 23, 2024
1 parent 4e24ca5 commit 78c9190
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 29 deletions.
37 changes: 23 additions & 14 deletions controllers/GetSystemStatsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import (
)

type StatItem struct {
CreatedAt time.Time
Cpu float64
Mem float64
NetOut float64
NetIn float64
DiskW float64
DiskR float64
CreatedAt time.Time
Cpu float64
Mem float64
NetOut float64
NetIn float64
DiskW float64
DiskR float64
ENCQualityQueue float64
ENCAudioQueue float64
ENCSubtitleQueue float64
}

func GetSystemStats(c echo.Context) error {
Expand Down Expand Up @@ -58,6 +61,9 @@ func GetSystemStats(c echo.Context) error {
"AVG(net_in) as net_in",
"AVG(disk_w) as disk_w",
"AVG(disk_r) as disk_ru",
"AVG(enc_quality_queue) as enc_quality_queue",
"AVG(enc_audio_queue) as enc_audio_queue",
"AVG(enc_subtitle_queue) as enc_subtitle_queue",
).
Where("created_at > ?", from).
Where("created_at < ?", until).
Expand All @@ -67,13 +73,16 @@ func GetSystemStats(c echo.Context) error {
return c.NoContent(http.StatusInternalServerError)
}
response = append(response, StatItem{
CreatedAt: time.Now().Add(duration * time.Duration(amount-(i+1)) * -1),
Cpu: resources.Cpu,
Mem: resources.Mem,
NetOut: resources.NetOut,
NetIn: resources.NetIn,
DiskW: resources.DiskW,
DiskR: resources.DiskR,
CreatedAt: time.Now().Add(duration * time.Duration(amount-(i+1)) * -1),
Cpu: resources.Cpu,
Mem: resources.Mem,
NetOut: resources.NetOut,
NetIn: resources.NetIn,
DiskW: resources.DiskW,
DiskR: resources.DiskR,
ENCQualityQueue: resources.ENCQualityQueue,
ENCAudioQueue: resources.ENCAudioQueue,
ENCSubtitleQueue: resources.ENCSubtitleQueue,
})
}

Expand Down
19 changes: 11 additions & 8 deletions models/SystemResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package models

type SystemResource struct {
Model
ServerID *uint `gorm:"index" json:"-"`
Server *Server
Cpu float64
Mem float64
NetOut uint64
NetIn uint64
DiskW uint64
DiskR uint64
ServerID *uint `gorm:"index" json:"-"`
Server *Server
Cpu float64
Mem float64
NetOut uint64
NetIn uint64
DiskW uint64
DiskR uint64
ENCQualityQueue int64
ENCAudioQueue int64
ENCSubtitleQueue int64
}

type SystemResourceGetValidation struct {
Expand Down
46 changes: 39 additions & 7 deletions services/Resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/shirou/gopsutil/v3/net"
)

var resourcesInterval = time.Second * 1
var resourcesInterval = time.Second * 10
var netSent uint64 = 0
var netRecv uint64 = 0

Expand Down Expand Up @@ -73,13 +73,45 @@ func Resources() {
printDiskRead = d[config.ENV.StatsDriveName].ReadBytes - diskRead
diskRead = d[config.ENV.StatsDriveName].ReadBytes
}

var printENCQualityQueue int64
if res := inits.DB.Model(&models.Quality{}).
Where(&models.Quality{
Ready: false,
Failed: false,
}, "Ready", "Failed").
Count(&printENCQualityQueue); res.Error != nil {
log.Println("Failed to count printENCQualityQueue", res.Error)
}
var printENCAudioQueue int64
if res := inits.DB.Model(&models.Audio{}).
Where(&models.Audio{
Ready: false,
Failed: false,
}, "Ready", "Failed").
Count(&printENCAudioQueue); res.Error != nil {
log.Println("Failed to count printENCAudioQueue", res.Error)
}
var printENCSubtitleQueue int64
if res := inits.DB.Model(&models.Subtitle{}).
Where(&models.Subtitle{
Ready: false,
Failed: false,
}, "Ready", "Failed").
Count(&printENCSubtitleQueue); res.Error != nil {
log.Println("Failed to count printENCSubtitleQueue", res.Error)
}

if res := inits.DB.Create(&models.SystemResource{
Cpu: printCpu,
Mem: printRam,
NetOut: printNetSent / uint64(resourcesInterval.Seconds()),
NetIn: printNetRecv / uint64(resourcesInterval.Seconds()),
DiskW: printDiskWrite / uint64(resourcesInterval.Seconds()),
DiskR: printDiskRead / uint64(resourcesInterval.Seconds()),
Cpu: printCpu,
Mem: printRam,
NetOut: printNetSent / uint64(resourcesInterval.Seconds()),
NetIn: printNetRecv / uint64(resourcesInterval.Seconds()),
DiskW: printDiskWrite / uint64(resourcesInterval.Seconds()),
DiskR: printDiskRead / uint64(resourcesInterval.Seconds()),
ENCQualityQueue: printENCQualityQueue,
ENCAudioQueue: printENCAudioQueue,
ENCSubtitleQueue: printENCSubtitleQueue,
}); res.Error != nil {
log.Println("Failed to save system resources", res.Error)
}
Expand Down

0 comments on commit 78c9190

Please sign in to comment.