Skip to content

Commit

Permalink
added dynamic drive name for diskstats
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed Jan 23, 2024
1 parent 9623d9f commit fb47927
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type Config struct {
FFmpegH264Width int64

PluginPgsServer string

StatsDriveName string `validate:"required,min=1,max=255"`
}

type PublicConfig struct {
Expand Down Expand Up @@ -129,6 +131,7 @@ func Setup() {
ENV.FolderVideoQualitysPriv = getEnv("FolderVideoQualitysPriv", "./videos/qualitys")
ENV.FolderVideoQualitysPub = getEnv("FolderVideoQualitysPub", "/videos/qualitys")
ENV.FolderVideoUploadsPriv = getEnv("FolderVideoUploadsPriv", "./videos/uploads")
ENV.StatsDriveName = getEnv("StatsDriveName", "nvme0n1")
}

// getters
Expand Down
15 changes: 8 additions & 7 deletions services/Resources.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package services

import (
"ch/kirari04/videocms/config"
"ch/kirari04/videocms/inits"
"ch/kirari04/videocms/models"
"log"
Expand Down Expand Up @@ -36,7 +37,7 @@ func Resources() {
v, _ := mem.VirtualMemory()
c, _ := cpu.Percent(time.Second*2, false)
n, _ := net.IOCounters(false)
d, _ := disk.IOCounters("nvme0n1")
d, _ := disk.IOCounters(config.ENV.StatsDriveName)

printCpu := c[0]
printRam := v.UsedPercent
Expand All @@ -59,18 +60,18 @@ func Resources() {

var printDiskWrite uint64 = 0
if diskWrite == 0 {
diskWrite = d["nvme0n1"].WriteBytes
diskWrite = d[config.ENV.StatsDriveName].WriteBytes
} else {
printDiskWrite = d["nvme0n1"].WriteBytes - diskWrite
diskWrite = d["nvme0n1"].WriteBytes
printDiskWrite = d[config.ENV.StatsDriveName].WriteBytes - diskWrite
diskWrite = d[config.ENV.StatsDriveName].WriteBytes
}

var printDiskRead uint64 = 0
if diskRead == 0 {
diskRead = d["nvme0n1"].ReadBytes
diskRead = d[config.ENV.StatsDriveName].ReadBytes
} else {
printDiskRead = d["nvme0n1"].ReadBytes - diskRead
diskRead = d["nvme0n1"].ReadBytes
printDiskRead = d[config.ENV.StatsDriveName].ReadBytes - diskRead
diskRead = d[config.ENV.StatsDriveName].ReadBytes
}
if res := inits.DB.Create(&models.SystemResource{
Cpu: printCpu,
Expand Down

0 comments on commit fb47927

Please sign in to comment.