mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-05 21:47:48 +01:00
Feature: Proxmox status & stats integration (#5385)
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
65
src/pages/api/proxmox/stats/[...service].js
Normal file
65
src/pages/api/proxmox/stats/[...service].js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { getProxmoxConfig } from "utils/config/proxmox";
|
||||
import createLogger from "utils/logger";
|
||||
import { httpProxy } from "utils/proxy/http";
|
||||
|
||||
const logger = createLogger("proxmoxStatsService");
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { service, type: vmType } = req.query;
|
||||
|
||||
const [node, vmid] = service;
|
||||
|
||||
if (!node) {
|
||||
return res.status(400).send({
|
||||
error: "Proxmox node parameter is required",
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const proxmoxConfig = getProxmoxConfig();
|
||||
|
||||
if (!proxmoxConfig) {
|
||||
return res.status(500).send({
|
||||
error: "Proxmox server configuration not found",
|
||||
});
|
||||
}
|
||||
|
||||
const baseUrl = `${proxmoxConfig.url}/api2/json`;
|
||||
const headers = {
|
||||
Authorization: `PVEAPIToken=${proxmoxConfig.token}=${proxmoxConfig.secret}`,
|
||||
};
|
||||
|
||||
const statusUrl = `${baseUrl}/nodes/${node}/${vmType}/${vmid}/status/current`;
|
||||
|
||||
const [status, , data] = await httpProxy(statusUrl, {
|
||||
method: "GET",
|
||||
headers,
|
||||
});
|
||||
|
||||
if (status !== 200) {
|
||||
logger.error("HTTP Error %d calling Proxmox API", status);
|
||||
return res.status(status).send({
|
||||
error: `Failed to fetch Proxmox ${vmType} status`,
|
||||
});
|
||||
}
|
||||
|
||||
let parsedData = JSON.parse(Buffer.from(data).toString());
|
||||
|
||||
if (!parsedData || !parsedData.data) {
|
||||
return res.status(500).send({
|
||||
error: "Invalid response from Proxmox API",
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
status: parsedData.data.status || "unknown",
|
||||
cpu: parsedData.data.cpu,
|
||||
mem: parsedData.data.mem,
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error("Error fetching Proxmox status:", error);
|
||||
return res.status(500).send({
|
||||
error: "Failed to fetch Proxmox status",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import checkAndCopyConfig from "utils/config/config";
|
||||
|
||||
const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml", "kubernetes.yaml"];
|
||||
const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml", "kubernetes.yaml", "proxmox.yaml"];
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const errors = configs.map((config) => checkAndCopyConfig(config)).filter((status) => status !== true);
|
||||
|
||||
Reference in New Issue
Block a user