mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 11:36:17 +00:00
Update AppImage
This commit is contained in:
@@ -187,7 +187,6 @@ export function VirtualMachines() {
|
|||||||
const [vmConfigs, setVmConfigs] = useState<Record<number, string>>({})
|
const [vmConfigs, setVmConfigs] = useState<Record<number, string>>({})
|
||||||
const [currentView, setCurrentView] = useState<"main" | "metrics">("main")
|
const [currentView, setCurrentView] = useState<"main" | "metrics">("main")
|
||||||
const [selectedMetric, setSelectedMetric] = useState<"cpu" | "memory" | "disk" | "network" | null>(null)
|
const [selectedMetric, setSelectedMetric] = useState<"cpu" | "memory" | "disk" | "network" | null>(null)
|
||||||
const [metricsDialogOpen, setMetricsDialogOpen] = useState(false) // Declare and initialize metricsDialogOpen
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchLXCIPs = async () => {
|
const fetchLXCIPs = async () => {
|
||||||
@@ -239,7 +238,6 @@ export function VirtualMachines() {
|
|||||||
const handleMetricClick = (metric: "cpu" | "memory" | "disk" | "network") => {
|
const handleMetricClick = (metric: "cpu" | "memory" | "disk" | "network") => {
|
||||||
setSelectedMetric(metric)
|
setSelectedMetric(metric)
|
||||||
setCurrentView("metrics")
|
setCurrentView("metrics")
|
||||||
setMetricsDialogOpen(true) // Open the metrics dialog
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleBackToMain = () => {
|
const handleBackToMain = () => {
|
||||||
@@ -561,7 +559,6 @@ export function VirtualMachines() {
|
|||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedMetric("cpu")
|
setSelectedMetric("cpu")
|
||||||
setMetricsDialogOpen(true)
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -582,7 +579,6 @@ export function VirtualMachines() {
|
|||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedMetric("memory")
|
setSelectedMetric("memory")
|
||||||
setMetricsDialogOpen(true)
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -603,7 +599,6 @@ export function VirtualMachines() {
|
|||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedMetric("disk")
|
setSelectedMetric("disk")
|
||||||
setMetricsDialogOpen(true)
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -723,7 +718,6 @@ export function VirtualMachines() {
|
|||||||
setVMDetails(null)
|
setVMDetails(null)
|
||||||
setCurrentView("main")
|
setCurrentView("main")
|
||||||
setSelectedMetric(null)
|
setSelectedMetric(null)
|
||||||
setMetricsDialogOpen(false) // Close the metrics dialog when the VM dialog is closed
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="max-w-4xl max-h-[95vh] flex flex-col p-0">
|
<DialogContent className="max-w-4xl max-h-[95vh] flex flex-col p-0">
|
||||||
@@ -770,7 +764,9 @@ export function VirtualMachines() {
|
|||||||
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
|
<div className="text-xs text-muted-foreground mb-1">CPU Usage</div>
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => handleMetricClick("cpu")}
|
onClick={() => {
|
||||||
|
setSelectedMetric("cpu")
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
|
<div className={`font-semibold mb-1 ${getUsageColor(selectedVM.cpu * 100)}`}>
|
||||||
{(selectedVM.cpu * 100).toFixed(1)}%
|
{(selectedVM.cpu * 100).toFixed(1)}%
|
||||||
@@ -785,7 +781,9 @@ export function VirtualMachines() {
|
|||||||
<div className="text-xs text-muted-foreground mb-1">Memory</div>
|
<div className="text-xs text-muted-foreground mb-1">Memory</div>
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => handleMetricClick("memory")}
|
onClick={() => {
|
||||||
|
setSelectedMetric("memory")
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
|
className={`font-semibold mb-1 ${getUsageColor((selectedVM.mem / selectedVM.maxmem) * 100)}`}
|
||||||
@@ -803,7 +801,9 @@ export function VirtualMachines() {
|
|||||||
<div className="text-xs text-muted-foreground mb-1">Disk</div>
|
<div className="text-xs text-muted-foreground mb-1">Disk</div>
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => handleMetricClick("disk")}
|
onClick={() => {
|
||||||
|
setSelectedMetric("disk")
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
|
className={`font-semibold mb-1 ${getUsageColor((selectedVM.disk / selectedVM.maxdisk) * 100)}`}
|
||||||
@@ -825,7 +825,9 @@ export function VirtualMachines() {
|
|||||||
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
|
<div className="text-xs text-muted-foreground mb-1">Disk I/O</div>
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => handleMetricClick("disk")}
|
onClick={() => {
|
||||||
|
setSelectedMetric("disk")
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="text-sm text-green-500 flex items-center gap-1">
|
<div className="text-sm text-green-500 flex items-center gap-1">
|
||||||
<span>↓</span>
|
<span>↓</span>
|
||||||
@@ -841,7 +843,9 @@ export function VirtualMachines() {
|
|||||||
<div className="text-xs text-muted-foreground mb-1">Network I/O</div>
|
<div className="text-xs text-muted-foreground mb-1">Network I/O</div>
|
||||||
<div
|
<div
|
||||||
className="cursor-pointer hover:opacity-80 transition-opacity"
|
className="cursor-pointer hover:opacity-80 transition-opacity"
|
||||||
onClick={() => handleMetricClick("network")}
|
onClick={() => {
|
||||||
|
setSelectedMetric("network")
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="text-sm text-green-500 flex items-center gap-1">
|
<div className="text-sm text-green-500 flex items-center gap-1">
|
||||||
<span>↓</span>
|
<span>↓</span>
|
||||||
|
|||||||
@@ -3758,35 +3758,52 @@ def api_vm_metrics(vmid):
|
|||||||
try:
|
try:
|
||||||
timeframe = request.args.get('timeframe', 'week') # hour, day, week, month, year
|
timeframe = request.args.get('timeframe', 'week') # hour, day, week, month, year
|
||||||
|
|
||||||
|
print(f"[v0] ===== METRICS REQUEST =====")
|
||||||
|
print(f"[v0] VMID: {vmid}")
|
||||||
|
print(f"[v0] Timeframe: {timeframe}")
|
||||||
|
|
||||||
# Validate timeframe
|
# Validate timeframe
|
||||||
valid_timeframes = ['hour', 'day', 'week', 'month', 'year']
|
valid_timeframes = ['hour', 'day', 'week', 'month', 'year']
|
||||||
if timeframe not in valid_timeframes:
|
if timeframe not in valid_timeframes:
|
||||||
|
print(f"[v0] ERROR: Invalid timeframe: {timeframe}")
|
||||||
return jsonify({'error': f'Invalid timeframe. Must be one of: {", ".join(valid_timeframes)}'}), 400
|
return jsonify({'error': f'Invalid timeframe. Must be one of: {", ".join(valid_timeframes)}'}), 400
|
||||||
|
|
||||||
# Get local node name
|
# Get local node name
|
||||||
local_node = socket.gethostname()
|
local_node = socket.gethostname()
|
||||||
|
print(f"[v0] Local node: {local_node}")
|
||||||
|
|
||||||
# First, determine if it's a qemu VM or lxc container
|
# First, determine if it's a qemu VM or lxc container
|
||||||
|
print(f"[v0] Checking if VMID {vmid} is QEMU...")
|
||||||
result = subprocess.run(['pvesh', 'get', f'/nodes/{local_node}/qemu/{vmid}/status/current', '--output-format', 'json'],
|
result = subprocess.run(['pvesh', 'get', f'/nodes/{local_node}/qemu/{vmid}/status/current', '--output-format', 'json'],
|
||||||
capture_output=True, text=True, timeout=10)
|
capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
vm_type = 'qemu'
|
vm_type = 'qemu'
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
|
print(f"[v0] Not QEMU, checking if LXC...")
|
||||||
# Try LXC
|
# Try LXC
|
||||||
result = subprocess.run(['pvesh', 'get', f'/nodes/{local_node}/lxc/{vmid}/status/current', '--output-format', 'json'],
|
result = subprocess.run(['pvesh', 'get', f'/nodes/{local_node}/lxc/{vmid}/status/current', '--output-format', 'json'],
|
||||||
capture_output=True, text=True, timeout=10)
|
capture_output=True, text=True, timeout=10)
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
vm_type = 'lxc'
|
vm_type = 'lxc'
|
||||||
|
print(f"[v0] Found as LXC")
|
||||||
else:
|
else:
|
||||||
|
print(f"[v0] ERROR: VM/LXC {vmid} not found")
|
||||||
return jsonify({'error': f'VM/LXC {vmid} not found'}), 404
|
return jsonify({'error': f'VM/LXC {vmid} not found'}), 404
|
||||||
|
else:
|
||||||
|
print(f"[v0] Found as QEMU")
|
||||||
|
|
||||||
# Get RRD data
|
# Get RRD data
|
||||||
|
print(f"[v0] Fetching RRD data for {vm_type} {vmid} with timeframe {timeframe}...")
|
||||||
rrd_result = subprocess.run(['pvesh', 'get', f'/nodes/{local_node}/{vm_type}/{vmid}/rrddata',
|
rrd_result = subprocess.run(['pvesh', 'get', f'/nodes/{local_node}/{vm_type}/{vmid}/rrddata',
|
||||||
'--timeframe', timeframe, '--output-format', 'json'],
|
'--timeframe', timeframe, '--output-format', 'json'],
|
||||||
capture_output=True, text=True, timeout=10)
|
capture_output=True, text=True, timeout=10)
|
||||||
|
|
||||||
if rrd_result.returncode == 0:
|
if rrd_result.returncode == 0:
|
||||||
|
print(f"[v0] RRD data fetched successfully")
|
||||||
|
print(f"[v0] RRD output length: {len(rrd_result.stdout)} bytes")
|
||||||
rrd_data = json.loads(rrd_result.stdout)
|
rrd_data = json.loads(rrd_result.stdout)
|
||||||
|
print(f"[v0] RRD data points: {len(rrd_data)}")
|
||||||
|
print(f"[v0] ===== METRICS REQUEST SUCCESS =====")
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'vmid': vmid,
|
'vmid': vmid,
|
||||||
'type': vm_type,
|
'type': vm_type,
|
||||||
@@ -3794,10 +3811,14 @@ def api_vm_metrics(vmid):
|
|||||||
'data': rrd_data
|
'data': rrd_data
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
|
print(f"[v0] ERROR: Failed to get RRD data")
|
||||||
|
print(f"[v0] stderr: {rrd_result.stderr}")
|
||||||
|
print(f"[v0] ===== METRICS REQUEST FAILED =====")
|
||||||
return jsonify({'error': f'Failed to get RRD data: {rrd_result.stderr}'}), 500
|
return jsonify({'error': f'Failed to get RRD data: {rrd_result.stderr}'}), 500
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error getting VM metrics: {e}")
|
print(f"[v0] EXCEPTION in api_vm_metrics: {e}")
|
||||||
|
print(f"[v0] ===== METRICS REQUEST EXCEPTION =====")
|
||||||
return jsonify({'error': str(e)}), 500
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
@app.route('/api/logs', methods=['GET'])
|
@app.route('/api/logs', methods=['GET'])
|
||||||
|
|||||||
Reference in New Issue
Block a user