mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 19:46:18 +00:00
Update metrics-dialog.tsx
This commit is contained in:
@@ -65,24 +65,61 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
const result = await response.json()
|
const result = await response.json()
|
||||||
console.log("[v0] Metrics data received:", result)
|
console.log("[v0] Metrics data received:", result)
|
||||||
|
|
||||||
// Transform data for charts
|
const transformedData = result.data.map((item: any) => {
|
||||||
const transformedData = result.data.map((item: any) => ({
|
const date = new Date(item.time * 1000)
|
||||||
time: new Date(item.time * 1000).toLocaleString("en-US", {
|
let timeLabel = ""
|
||||||
month: "short",
|
|
||||||
day: "numeric",
|
// Format time based on timeframe
|
||||||
hour: timeframe === "hour" ? "2-digit" : undefined,
|
if (timeframe === "hour") {
|
||||||
minute: timeframe === "hour" ? "2-digit" : undefined,
|
// For 1 hour: show HH:mm
|
||||||
}),
|
timeLabel = date.toLocaleString("en-US", {
|
||||||
timestamp: item.time,
|
hour: "2-digit",
|
||||||
cpu: item.cpu ? (item.cpu * 100).toFixed(2) : 0,
|
minute: "2-digit",
|
||||||
memory: item.mem ? ((item.mem / item.maxmem) * 100).toFixed(2) : 0,
|
hour12: false,
|
||||||
memoryMB: item.mem ? (item.mem / 1024 / 1024).toFixed(0) : 0,
|
})
|
||||||
maxMemoryMB: item.maxmem ? (item.maxmem / 1024 / 1024).toFixed(0) : 0,
|
} else if (timeframe === "day") {
|
||||||
netin: item.netin ? (item.netin / 1024 / 1024).toFixed(2) : 0,
|
// For 24 hours: show HH:mm
|
||||||
netout: item.netout ? (item.netout / 1024 / 1024).toFixed(2) : 0,
|
timeLabel = date.toLocaleString("en-US", {
|
||||||
diskread: item.diskread ? (item.diskread / 1024 / 1024).toFixed(2) : 0,
|
hour: "2-digit",
|
||||||
diskwrite: item.diskwrite ? (item.diskwrite / 1024 / 1024).toFixed(2) : 0,
|
minute: "2-digit",
|
||||||
}))
|
hour12: false,
|
||||||
|
})
|
||||||
|
} else if (timeframe === "week") {
|
||||||
|
// For 7 days: show Mon DD HH:mm
|
||||||
|
timeLabel = date.toLocaleString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
hour12: false,
|
||||||
|
})
|
||||||
|
} else if (timeframe === "month") {
|
||||||
|
// For 30 days: show Mon DD
|
||||||
|
timeLabel = date.toLocaleString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// For 1 year: show Mon YYYY
|
||||||
|
timeLabel = date.toLocaleString("en-US", {
|
||||||
|
month: "short",
|
||||||
|
year: "numeric",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
time: timeLabel,
|
||||||
|
timestamp: item.time,
|
||||||
|
cpu: item.cpu ? (item.cpu * 100).toFixed(2) : 0,
|
||||||
|
memory: item.mem ? ((item.mem / item.maxmem) * 100).toFixed(2) : 0,
|
||||||
|
memoryMB: item.mem ? (item.mem / 1024 / 1024).toFixed(0) : 0,
|
||||||
|
maxMemoryMB: item.maxmem ? (item.maxmem / 1024 / 1024).toFixed(0) : 0,
|
||||||
|
netin: item.netin ? (item.netin / 1024 / 1024).toFixed(2) : 0,
|
||||||
|
netout: item.netout ? (item.netout / 1024 / 1024).toFixed(2) : 0,
|
||||||
|
diskread: item.diskread ? (item.diskread / 1024 / 1024).toFixed(2) : 0,
|
||||||
|
diskwrite: item.diskwrite ? (item.diskwrite / 1024 / 1024).toFixed(2) : 0,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
console.log("[v0] Transformed data:", transformedData.length, "points")
|
console.log("[v0] Transformed data:", transformedData.length, "points")
|
||||||
setData(transformedData)
|
setData(transformedData)
|
||||||
@@ -119,13 +156,24 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tickInterval = Math.ceil(data.length / 10)
|
||||||
|
|
||||||
switch (metricType) {
|
switch (metricType) {
|
||||||
case "cpu":
|
case "cpu":
|
||||||
return (
|
return (
|
||||||
<ResponsiveContainer width="100%" height={400}>
|
<ResponsiveContainer width="100%" height={400}>
|
||||||
<LineChart data={data}>
|
<LineChart data={data}>
|
||||||
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
||||||
<XAxis dataKey="time" stroke="currentColor" tick={{ fill: "currentColor" }} className="text-foreground" />
|
<XAxis
|
||||||
|
dataKey="time"
|
||||||
|
stroke="currentColor"
|
||||||
|
tick={{ fill: "currentColor", fontSize: 12 }}
|
||||||
|
className="text-foreground"
|
||||||
|
angle={-45}
|
||||||
|
textAnchor="end"
|
||||||
|
height={80}
|
||||||
|
interval={tickInterval}
|
||||||
|
/>
|
||||||
<YAxis
|
<YAxis
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
tick={{ fill: "currentColor" }}
|
tick={{ fill: "currentColor" }}
|
||||||
@@ -147,7 +195,16 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
<ResponsiveContainer width="100%" height={400}>
|
<ResponsiveContainer width="100%" height={400}>
|
||||||
<LineChart data={data}>
|
<LineChart data={data}>
|
||||||
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
||||||
<XAxis dataKey="time" stroke="currentColor" tick={{ fill: "currentColor" }} className="text-foreground" />
|
<XAxis
|
||||||
|
dataKey="time"
|
||||||
|
stroke="currentColor"
|
||||||
|
tick={{ fill: "currentColor", fontSize: 12 }}
|
||||||
|
className="text-foreground"
|
||||||
|
angle={-45}
|
||||||
|
textAnchor="end"
|
||||||
|
height={80}
|
||||||
|
interval={tickInterval}
|
||||||
|
/>
|
||||||
<YAxis
|
<YAxis
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
tick={{ fill: "currentColor" }}
|
tick={{ fill: "currentColor" }}
|
||||||
@@ -169,7 +226,16 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
<ResponsiveContainer width="100%" height={400}>
|
<ResponsiveContainer width="100%" height={400}>
|
||||||
<LineChart data={data}>
|
<LineChart data={data}>
|
||||||
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
||||||
<XAxis dataKey="time" stroke="currentColor" tick={{ fill: "currentColor" }} className="text-foreground" />
|
<XAxis
|
||||||
|
dataKey="time"
|
||||||
|
stroke="currentColor"
|
||||||
|
tick={{ fill: "currentColor", fontSize: 12 }}
|
||||||
|
className="text-foreground"
|
||||||
|
angle={-45}
|
||||||
|
textAnchor="end"
|
||||||
|
height={80}
|
||||||
|
interval={tickInterval}
|
||||||
|
/>
|
||||||
<YAxis
|
<YAxis
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
tick={{ fill: "currentColor" }}
|
tick={{ fill: "currentColor" }}
|
||||||
@@ -181,8 +247,8 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
labelStyle={{ color: "hsl(var(--foreground))" }}
|
labelStyle={{ color: "hsl(var(--foreground))" }}
|
||||||
/>
|
/>
|
||||||
<Legend />
|
<Legend />
|
||||||
<Line type="monotone" dataKey="netin" stroke="#3b82f6" name="In (MB)" strokeWidth={2} dot={false} />
|
<Line type="monotone" dataKey="netin" stroke="#10b981" name="Download (MB)" strokeWidth={2} dot={false} />
|
||||||
<Line type="monotone" dataKey="netout" stroke="#8b5cf6" name="Out (MB)" strokeWidth={2} dot={false} />
|
<Line type="monotone" dataKey="netout" stroke="#3b82f6" name="Upload (MB)" strokeWidth={2} dot={false} />
|
||||||
</LineChart>
|
</LineChart>
|
||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
)
|
)
|
||||||
@@ -192,7 +258,16 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
<ResponsiveContainer width="100%" height={400}>
|
<ResponsiveContainer width="100%" height={400}>
|
||||||
<LineChart data={data}>
|
<LineChart data={data}>
|
||||||
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
<CartesianGrid strokeDasharray="3 3" stroke="hsl(var(--border))" />
|
||||||
<XAxis dataKey="time" stroke="currentColor" tick={{ fill: "currentColor" }} className="text-foreground" />
|
<XAxis
|
||||||
|
dataKey="time"
|
||||||
|
stroke="currentColor"
|
||||||
|
tick={{ fill: "currentColor", fontSize: 12 }}
|
||||||
|
className="text-foreground"
|
||||||
|
angle={-45}
|
||||||
|
textAnchor="end"
|
||||||
|
height={80}
|
||||||
|
interval={tickInterval}
|
||||||
|
/>
|
||||||
<YAxis
|
<YAxis
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
tick={{ fill: "currentColor" }}
|
tick={{ fill: "currentColor" }}
|
||||||
@@ -208,7 +283,7 @@ export function MetricsView({ vmid, vmName, vmType, metricType, onBack }: Metric
|
|||||||
<Line
|
<Line
|
||||||
type="monotone"
|
type="monotone"
|
||||||
dataKey="diskwrite"
|
dataKey="diskwrite"
|
||||||
stroke="#f59e0b"
|
stroke="#3b82f6"
|
||||||
name="Write (MB)"
|
name="Write (MB)"
|
||||||
strokeWidth={2}
|
strokeWidth={2}
|
||||||
dot={false}
|
dot={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user