mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 02:36:17 +01:00
add gpu usage alerts
This commit is contained in:
@@ -40,13 +40,18 @@ type UserNotificationSettings struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SystemAlertStats struct {
|
type SystemAlertStats struct {
|
||||||
Cpu float64 `json:"cpu"`
|
Cpu float64 `json:"cpu"`
|
||||||
Mem float64 `json:"mp"`
|
Mem float64 `json:"mp"`
|
||||||
Disk float64 `json:"dp"`
|
Disk float64 `json:"dp"`
|
||||||
NetSent float64 `json:"ns"`
|
NetSent float64 `json:"ns"`
|
||||||
NetRecv float64 `json:"nr"`
|
NetRecv float64 `json:"nr"`
|
||||||
Temperatures map[string]float32 `json:"t"`
|
GPU map[string]SystemAlertGPUData `json:"g"`
|
||||||
LoadAvg [3]float64 `json:"la"`
|
Temperatures map[string]float32 `json:"t"`
|
||||||
|
LoadAvg [3]float64 `json:"la"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SystemAlertGPUData struct {
|
||||||
|
Usage float64 `json:"u"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemAlertData struct {
|
type SystemAlertData struct {
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ func (am *AlertManager) HandleSystemAlerts(systemRecord *core.Record, data *syst
|
|||||||
case "LoadAvg15":
|
case "LoadAvg15":
|
||||||
val = data.Info.LoadAvg[2]
|
val = data.Info.LoadAvg[2]
|
||||||
unit = ""
|
unit = ""
|
||||||
|
case "GPU":
|
||||||
|
val = data.Info.GpuPct
|
||||||
}
|
}
|
||||||
|
|
||||||
triggered := alertRecord.GetBool("triggered")
|
triggered := alertRecord.GetBool("triggered")
|
||||||
@@ -206,6 +208,17 @@ func (am *AlertManager) HandleSystemAlerts(systemRecord *core.Record, data *syst
|
|||||||
alert.val += stats.LoadAvg[1]
|
alert.val += stats.LoadAvg[1]
|
||||||
case "LoadAvg15":
|
case "LoadAvg15":
|
||||||
alert.val += stats.LoadAvg[2]
|
alert.val += stats.LoadAvg[2]
|
||||||
|
case "GPU":
|
||||||
|
if len(stats.GPU) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
maxUsage := 0.0
|
||||||
|
for _, gpu := range stats.GPU {
|
||||||
|
if gpu.Usage > maxUsage {
|
||||||
|
maxUsage = gpu.Usage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alert.val += maxUsage
|
||||||
default:
|
default:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func init() {
|
|||||||
"Disk",
|
"Disk",
|
||||||
"Temperature",
|
"Temperature",
|
||||||
"Bandwidth",
|
"Bandwidth",
|
||||||
|
"GPU",
|
||||||
"LoadAvg1",
|
"LoadAvg1",
|
||||||
"LoadAvg5",
|
"LoadAvg5",
|
||||||
"LoadAvg15"
|
"LoadAvg15"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { t } from "@lingui/core/macro"
|
import { t } from "@lingui/core/macro"
|
||||||
import { CpuIcon, HardDriveIcon, HourglassIcon, MemoryStickIcon, ServerIcon, ThermometerIcon } from "lucide-react"
|
import { CpuIcon, HardDriveIcon, HourglassIcon, MemoryStickIcon, ServerIcon, ThermometerIcon } from "lucide-react"
|
||||||
import type { RecordSubscription } from "pocketbase"
|
import type { RecordSubscription } from "pocketbase"
|
||||||
import { EthernetIcon } from "@/components/ui/icons"
|
import { EthernetIcon, GpuIcon } from "@/components/ui/icons"
|
||||||
import { $alerts } from "@/lib/stores"
|
import { $alerts } from "@/lib/stores"
|
||||||
import type { AlertInfo, AlertRecord } from "@/types"
|
import type { AlertInfo, AlertRecord } from "@/types"
|
||||||
import { pb } from "./api"
|
import { pb } from "./api"
|
||||||
@@ -41,6 +41,12 @@ export const alertInfo: Record<string, AlertInfo> = {
|
|||||||
desc: () => t`Triggers when combined up/down exceeds a threshold`,
|
desc: () => t`Triggers when combined up/down exceeds a threshold`,
|
||||||
max: 125,
|
max: 125,
|
||||||
},
|
},
|
||||||
|
GPU: {
|
||||||
|
name: () => t`GPU Usage`,
|
||||||
|
unit: "%",
|
||||||
|
icon: GpuIcon,
|
||||||
|
desc: () => t`Triggers when GPU usage exceeds a threshold`,
|
||||||
|
},
|
||||||
Temperature: {
|
Temperature: {
|
||||||
name: () => t`Temperature`,
|
name: () => t`Temperature`,
|
||||||
unit: "°C",
|
unit: "°C",
|
||||||
|
|||||||
24
internal/site/src/types.d.ts
vendored
24
internal/site/src/types.d.ts
vendored
@@ -301,18 +301,18 @@ export interface ChartData {
|
|||||||
chartTime: ChartTimes
|
chartTime: ChartTimes
|
||||||
}
|
}
|
||||||
|
|
||||||
// interface AlertInfo {
|
export interface AlertInfo {
|
||||||
// name: () => string
|
name: () => string
|
||||||
// unit: string
|
unit: string
|
||||||
// icon: any
|
icon: any
|
||||||
// desc: () => string
|
desc: () => string
|
||||||
// max?: number
|
max?: number
|
||||||
// min?: number
|
min?: number
|
||||||
// step?: number
|
step?: number
|
||||||
// start?: number
|
start?: number
|
||||||
// /** Single value description (when there's only one value, like status) */
|
/** Single value description (when there's only one value, like status) */
|
||||||
// singleDesc?: () => string
|
singleDesc?: () => string
|
||||||
// }
|
}
|
||||||
|
|
||||||
export type AlertMap = Record<string, Map<string, AlertRecord>>
|
export type AlertMap = Record<string, Map<string, AlertRecord>>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user