Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
import { estimateTextWidth } from '@/utils/format';
import { getMetricColorClass } from '@/utils/metricThresholds';
import type { MetricDisplayThresholds, MetricType } from '@/utils/metricThresholds';
export interface MetricBarProps {
value: number;
label: string;
animatedLabelValue?: number;
animatedLabelFormat?: (value: number) => string;
sublabel?: string;
showLabel?: boolean;
type?: 'cpu' | 'memory' | 'disk' | 'generic';
thresholds?: MetricDisplayThresholds | null;
resourceId?: string;
class?: string;
}
export interface MetricBarPresentation {
progressColorClass: string;
showLabel: boolean;
showSublabel: boolean;
width: number;
}
// Horizontal padding around the label inside the bar (px-0.5 in MetricBar.tsx).
const LABEL_PADDING_PX = 4;
export function buildMetricBarPresentation(
props: MetricBarProps,
containerWidth: number,
): MetricBarPresentation {
const width = Math.min(props.value, 100);
const showLabel = props.showLabel !== false && props.label.trim().length > 0;
const showSublabel =
showLabel &&
Boolean(props.sublabel) &&
containerWidth >=
estimateTextWidth(props.label, { detail: ` (${props.sublabel})` }) + LABEL_PADDING_PX;
const metric = props.type || 'cpu';
const metricType: MetricType = metric === 'generic' ? 'cpu' : metric;
return {
progressColorClass: getMetricColorClass(props.value, metricType, props.thresholds),
showLabel,
showSublabel,
width,
};
}