Merge pull request #3 from flohoss/dev

More system information
This commit is contained in:
Florian Hoss 2022-10-23 19:25:45 +02:00 committed by GitHub
commit 48499a9b3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 59 deletions

1
go.mod
View file

@ -9,7 +9,6 @@ require (
github.com/go-chi/chi/v5 v5.0.7
github.com/go-chi/cors v1.2.1
github.com/gorilla/websocket v1.5.0
github.com/jaypipes/ghw v0.9.0
github.com/mitchellh/mapstructure v1.5.0
github.com/shirou/gopsutil/v3 v3.22.9
github.com/sirupsen/logrus v1.9.0

15
go.sum
View file

@ -40,7 +40,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
@ -66,7 +65,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
@ -74,7 +72,6 @@ github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vz
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
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=
@ -154,11 +151,6 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jaypipes/ghw v0.9.0 h1:TWF4wNIGtZcgDJaiNcFgby5BR8s2ixcUe0ydxNO2McY=
github.com/jaypipes/ghw v0.9.0/go.mod h1:dXMo19735vXOjpIBDyDYSp31sB2u4hrtRCMxInqQ64k=
github.com/jaypipes/pcidb v1.0.0/go.mod h1:TnYUvqhPBzCKnH34KrIX22kAeEbDCSRJ9cqLRCuNDfk=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
@ -181,8 +173,6 @@ github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@ -208,10 +198,8 @@ github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw=
github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.13.0 h1:BWSJ/M+f+3nmdz9bxB+bWX28kkALN2ok11D0rSo8EJU=
@ -386,7 +374,6 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/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-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -554,7 +541,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
@ -569,7 +555,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

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

@ -62,35 +62,50 @@
{{ if .System.Static.CPU.Name }}
<div class="grid grid-cols-1 md:grid-cols-3 gap-5 mb-6 md:mb-10 select-none text-sm">
<div class="flex items-center">
<svg class="h-6 w-6 shrink-0 mr-2 text-slate-300">
<svg class="h-8 w-8 shrink-0 mr-2 text-slate-700 dark:text-slate-300">
<use xlink:href="#cpu"></use>
</svg>
<div class="w-full truncate">
<div class="truncate">{{ .System.Static.CPU.Name }}</div>
<div class="bg-slate-700 h-px mt-1">
<div id="systemCpuPercentage" class="transition-[width] duration-700 bg-slate-200 h-px" style="width: {{ .System.Live.CPU.Percentage }}%"></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 }}%"
></div>
</div>
</div>
</div>
<div class="flex items-center">
<svg class="h-6 w-6 shrink-0 mr-2 text-slate-300">
<svg class="h-8 w-8 shrink-0 mr-2 text-slate-700 dark:text-slate-300">
<use xlink:href="#ram"></use>
</svg>
<div class="w-full truncate">
<div class="truncate">{{ .System.Live.Ram.Value }} / {{ .System.Static.Ram }}</div>
<div class="bg-slate-700 h-px mt-1">
<div id="systemRamPercentage" class="transition-[width] duration-700 bg-slate-200 h-px" style="width: {{ .System.Live.Ram.Percentage }}%"></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"
class="transition-[width] duration-700 bg-slate-800 dark:bg-slate-200 h-px"
style="width: {{ .System.Live.Ram.Percentage }}%"
></div>
</div>
</div>
</div>
<div class="flex items-center">
<svg class="h-6 w-6 shrink-0 mr-2 text-slate-300">
<svg class="h-8 w-8 shrink-0 mr-2 text-slate-700 dark:text-slate-300">
<use xlink:href="#disk"></use>
</svg>
<div class="w-full truncate">
<div class="truncate">{{ .System.Live.Disk.Value }} / {{ .System.Static.Disk }}</div>
<div class="bg-slate-700 h-px mt-1">
<div id="systemDiskPercentage" class="transition-[width] duration-700 bg-slate-200 h-px" style="width: {{ .System.Live.Disk.Percentage }}%"></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"
class="transition-[width] duration-700 bg-slate-800 dark:bg-slate-200 h-px"
style="width: {{ .System.Live.Disk.Percentage }}%"
></div>
</div>
</div>
</div>