mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 10:19:27 +08:00
add peak values for cpu and net
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
Cpu float64 `json:"cpu"`
|
Cpu float64 `json:"cpu"`
|
||||||
|
PeakCpu float64 `json:"pcpu,omitempty"`
|
||||||
Mem float64 `json:"m"`
|
Mem float64 `json:"m"`
|
||||||
MemUsed float64 `json:"mu"`
|
MemUsed float64 `json:"mu"`
|
||||||
MemPct float64 `json:"mp"`
|
MemPct float64 `json:"mp"`
|
||||||
@@ -20,7 +21,9 @@ type Stats struct {
|
|||||||
DiskReadPs float64 `json:"dr"`
|
DiskReadPs float64 `json:"dr"`
|
||||||
DiskWritePs float64 `json:"dw"`
|
DiskWritePs float64 `json:"dw"`
|
||||||
NetworkSent float64 `json:"ns"`
|
NetworkSent float64 `json:"ns"`
|
||||||
|
PeakNetworkSent float64 `json:"pns,omitempty"`
|
||||||
NetworkRecv float64 `json:"nr"`
|
NetworkRecv float64 `json:"nr"`
|
||||||
|
PeakNetworkRecv float64 `json:"pnr,omitempty"`
|
||||||
Temperatures map[string]float64 `json:"t,omitempty"`
|
Temperatures map[string]float64 `json:"t,omitempty"`
|
||||||
ExtraFs map[string]*FsStats `json:"efs,omitempty"`
|
ExtraFs map[string]*FsStats `json:"efs,omitempty"`
|
||||||
}
|
}
|
||||||
|
@@ -153,6 +153,11 @@ func (rm *RecordManager) AverageSystemStats(records []*models.Record) system.Sta
|
|||||||
// use different counter for temps in case some records don't have them
|
// use different counter for temps in case some records don't have them
|
||||||
tempCount := float64(0)
|
tempCount := float64(0)
|
||||||
|
|
||||||
|
// peak values
|
||||||
|
peakCpu := float64(0)
|
||||||
|
peakNs := float64(0)
|
||||||
|
peakNr := float64(0)
|
||||||
|
|
||||||
var stats system.Stats
|
var stats system.Stats
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
record.UnmarshalJSONField("stats", &stats)
|
record.UnmarshalJSONField("stats", &stats)
|
||||||
@@ -171,6 +176,10 @@ func (rm *RecordManager) AverageSystemStats(records []*models.Record) system.Sta
|
|||||||
sum.DiskWritePs += stats.DiskWritePs
|
sum.DiskWritePs += stats.DiskWritePs
|
||||||
sum.NetworkSent += stats.NetworkSent
|
sum.NetworkSent += stats.NetworkSent
|
||||||
sum.NetworkRecv += stats.NetworkRecv
|
sum.NetworkRecv += stats.NetworkRecv
|
||||||
|
// set peak values
|
||||||
|
peakCpu = max(peakCpu, stats.PeakCpu, stats.Cpu)
|
||||||
|
peakNs = max(peakNs, stats.PeakNetworkSent, stats.NetworkSent)
|
||||||
|
peakNr = max(peakNr, stats.PeakNetworkRecv, stats.NetworkRecv)
|
||||||
// add temps to sum
|
// add temps to sum
|
||||||
if stats.Temperatures != nil {
|
if stats.Temperatures != nil {
|
||||||
tempCount++
|
tempCount++
|
||||||
@@ -197,6 +206,7 @@ func (rm *RecordManager) AverageSystemStats(records []*models.Record) system.Sta
|
|||||||
|
|
||||||
stats = system.Stats{
|
stats = system.Stats{
|
||||||
Cpu: twoDecimals(sum.Cpu / count),
|
Cpu: twoDecimals(sum.Cpu / count),
|
||||||
|
PeakCpu: twoDecimals(peakCpu),
|
||||||
Mem: twoDecimals(sum.Mem / count),
|
Mem: twoDecimals(sum.Mem / count),
|
||||||
MemUsed: twoDecimals(sum.MemUsed / count),
|
MemUsed: twoDecimals(sum.MemUsed / count),
|
||||||
MemPct: twoDecimals(sum.MemPct / count),
|
MemPct: twoDecimals(sum.MemPct / count),
|
||||||
@@ -210,7 +220,9 @@ func (rm *RecordManager) AverageSystemStats(records []*models.Record) system.Sta
|
|||||||
DiskReadPs: twoDecimals(sum.DiskReadPs / count),
|
DiskReadPs: twoDecimals(sum.DiskReadPs / count),
|
||||||
DiskWritePs: twoDecimals(sum.DiskWritePs / count),
|
DiskWritePs: twoDecimals(sum.DiskWritePs / count),
|
||||||
NetworkSent: twoDecimals(sum.NetworkSent / count),
|
NetworkSent: twoDecimals(sum.NetworkSent / count),
|
||||||
|
PeakNetworkSent: twoDecimals(peakNs),
|
||||||
NetworkRecv: twoDecimals(sum.NetworkRecv / count),
|
NetworkRecv: twoDecimals(sum.NetworkRecv / count),
|
||||||
|
PeakNetworkRecv: twoDecimals(peakNr),
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sum.Temperatures) != 0 {
|
if len(sum.Temperatures) != 0 {
|
||||||
|
6
beszel/site/src/types.d.ts
vendored
6
beszel/site/src/types.d.ts
vendored
@@ -35,6 +35,8 @@ export interface SystemInfo {
|
|||||||
export interface SystemStats {
|
export interface SystemStats {
|
||||||
/** cpu percent */
|
/** cpu percent */
|
||||||
cpu: number
|
cpu: number
|
||||||
|
/** peak cpu */
|
||||||
|
pcpu?: number
|
||||||
/** total memory (gb) */
|
/** total memory (gb) */
|
||||||
m: number
|
m: number
|
||||||
/** memory used (gb) */
|
/** memory used (gb) */
|
||||||
@@ -61,8 +63,12 @@ export interface SystemStats {
|
|||||||
dw: number
|
dw: number
|
||||||
/** network sent (mb) */
|
/** network sent (mb) */
|
||||||
ns: number
|
ns: number
|
||||||
|
/** peak network sent (mb) */
|
||||||
|
pns?: number
|
||||||
/** network received (mb) */
|
/** network received (mb) */
|
||||||
nr: number
|
nr: number
|
||||||
|
/** peak network received (mb) */
|
||||||
|
pnr?: number
|
||||||
/** temperatures */
|
/** temperatures */
|
||||||
t?: Record<string, number>
|
t?: Record<string, number>
|
||||||
/** extra filesystems */
|
/** extra filesystems */
|
||||||
|
Reference in New Issue
Block a user