Add more system information

This commit is contained in:
Florian Hoss 2022-10-23 19:24:11 +02:00
parent 05af2c773d
commit eb744b976a
6 changed files with 61 additions and 36 deletions

View file

@ -15,7 +15,9 @@ const weatherSunset = document.getElementById("weatherSunset");
// system elements
const systemCpuPercentage = document.getElementById("systemCpuPercentage");
const systemRamPercentage = document.getElementById("systemRamPercentage");
const systemRamValue = document.getElementById("systemRamValue");
const systemDiskPercentage = document.getElementById("systemDiskPercentage");
const systemDiskValue = document.getElementById("systemDiskValue");
function connect() {
let ws = new WebSocket(apiBase.replace("http", "ws") + "/system/ws");
@ -47,7 +49,9 @@ function replaceWeather(parsed) {
}
function replaceSystem(parsed) {
systemCpuPercentage.style = "width:" + parsed.cpu.percentage + "%";
systemCpuPercentage.style = "width:" + parsed.cpu + "%";
systemRamPercentage.style = "width:" + parsed.ram.percentage + "%";
systemRamValue.innerText = parsed.ram.value;
systemDiskPercentage.style = "width:" + parsed.disk.percentage + "%";
systemDiskValue.innerText = parsed.disk.value;
}

View file

@ -4,11 +4,12 @@ import (
"github.com/shirou/gopsutil/v3/cpu"
"math"
"runtime"
"strconv"
)
func staticCpu() CPU {
var p CPU
p.Threads = runtime.NumCPU()
p.Threads = strconv.Itoa(runtime.NumCPU()) + " threads"
p.Architecture = runtime.GOARCH
c, err := cpu.Info()
if err == nil {
@ -24,5 +25,5 @@ func (s *System) liveCpu() {
if err != nil {
return
}
s.Live.CPU.Percentage = math.RoundToEven(p[0])
s.Live.CPU = math.RoundToEven(p[0])
}

View file

@ -5,14 +5,19 @@ import (
"github.com/dustin/go-humanize"
"github.com/shirou/gopsutil/v3/disk"
"math"
"strconv"
)
func staticDisk() string {
func staticDisk() Disk {
var result = Disk{}
d, err := disk.Usage("/")
if err != nil {
return ""
return result
}
return humanize.IBytes(d.Total)
p, err := disk.Partitions(false)
result.Total = humanize.IBytes(d.Total)
result.Partitions = strconv.Itoa(len(p)) + " partitions"
return result
}
func (s *System) liveDisk() {

View file

@ -7,12 +7,19 @@ import (
"math"
)
func staticRam() string {
func staticRam() Ram {
var result = Ram{}
r, err := mem.VirtualMemory()
if err != nil {
return ""
return result
}
return humanize.IBytes(r.Total)
result.Total = humanize.IBytes(r.Total)
if r.SwapTotal > 0 {
result.Swap = humanize.IBytes(r.SwapTotal) + " swap"
} else {
result.Swap = "No swap"
}
return result
}
func (s *System) liveRam() {

View file

@ -4,35 +4,41 @@ type SystemConfig struct {
LiveSystem bool `mapstructure:"LIVE_SYSTEM"`
}
type BasicSystemInformation struct {
Value string `json:"value" validate:"required"`
Percentage float64 `json:"percentage" validate:"required"`
type LiveStorageInformation struct {
Value string `json:"value"`
Percentage float64 `json:"percentage"`
}
type LiveInformation struct {
CPU CpuSystemInformation `json:"cpu" validate:"required"`
Ram BasicSystemInformation `json:"ram" validate:"required"`
Disk BasicSystemInformation `json:"disk" validate:"required"`
ServerUptime uint64 `json:"server_uptime" validate:"required"`
}
type StaticInformation struct {
CPU CPU `json:"cpu" validate:"required"`
Ram string `json:"ram" validate:"required"`
Disk string `json:"disk" validate:"required"`
}
type System struct {
Live LiveInformation `json:"live" validate:"required"`
Static StaticInformation `json:"static" validate:"required"`
CPU float64 `json:"cpu"`
Ram LiveStorageInformation `json:"ram"`
Disk LiveStorageInformation `json:"disk"`
ServerUptime uint64 `json:"server_uptime"`
}
type CPU struct {
Name string `json:"name" validate:"required"`
Threads int `json:"threads" validate:"required"`
Architecture string `json:"architecture" validate:"required"`
Name string `json:"name"`
Threads string `json:"threads"`
Architecture string `json:"architecture"`
}
type CpuSystemInformation struct {
Percentage float64 `json:"percentage" validate:"required"`
type Ram struct {
Total string `json:"total"`
Swap string `json:"swap"`
}
type Disk struct {
Total string `json:"total"`
Partitions string `json:"partitions"`
}
type StaticInformation struct {
CPU CPU `json:"cpu"`
Ram Ram `json:"ram"`
Disk Disk `json:"disk"`
}
type System struct {
Live LiveInformation `json:"live"`
Static StaticInformation `json:"static"`
}

View file

@ -67,12 +67,12 @@
</svg>
<div class="w-full truncate">
<div class="truncate">{{ .System.Static.CPU.Name }}</div>
<div class="text-slate-700 dark:text-slate-300 truncate">{{ .System.Static.CPU.Threads }} Threads</div>
<div class="text-xs text-slate-700 dark:text-slate-300 truncate">{{ .System.Static.CPU.Threads }}</div>
<div class="bg-slate-300 dark:bg-slate-700 h-px mt-1">
<div
id="systemCpuPercentage"
class="transition-[width] duration-700 bg-slate-800 dark:bg-slate-200 h-px"
style="width: {{ .System.Live.CPU.Percentage }}%"
style="width: {{ .System.Live.CPU }}%"
></div>
</div>
</div>
@ -82,7 +82,8 @@
<use xlink:href="#ram"></use>
</svg>
<div class="w-full truncate">
<div class="truncate">{{ .System.Live.Ram.Value }} / {{ .System.Static.Ram }}</div>
<div class="truncate"><span id="systemRamValue">{{ .System.Live.Ram.Value }}</span> / {{ .System.Static.Ram.Total }}</div>
<div class="text-xs text-slate-700 dark:text-slate-300 truncate">{{ .System.Static.Ram.Swap }}</div>
<div class="bg-slate-300 dark:bg-slate-700 h-px mt-1">
<div
id="systemRamPercentage"
@ -97,7 +98,8 @@
<use xlink:href="#disk"></use>
</svg>
<div class="w-full truncate">
<div class="truncate">{{ .System.Live.Disk.Value }} / {{ .System.Static.Disk }}</div>
<div class="truncate"><span id="systemDiskValue">{{ .System.Live.Disk.Value }}</span> / {{ .System.Static.Disk.Total }}</div>
<div class="text-xs text-slate-700 dark:text-slate-300 truncate">{{ .System.Static.Disk.Partitions }}</div>
<div class="bg-slate-300 dark:bg-slate-700 h-px mt-1">
<div
id="systemDiskPercentage"