From f7f1ba850f744d88926b6c5a81374272a3320248 Mon Sep 17 00:00:00 2001 From: hirzidevs Date: Fri, 13 Sep 2024 21:20:35 +0700 Subject: [PATCH] feat: display panel or nodes host --- config.yml | 4 +++- handlers/app.js | 7 +++++-- handlers/getStats.js | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.yml b/config.yml index d081870..8e0b7f2 100644 --- a/config.yml +++ b/config.yml @@ -75,14 +75,16 @@ nodes_settings: details: true # Show node details such as memory and disk usage (true/false). servers: false # Show server details (true/false). allocations_as_max_servers: false # Show allocations as max servers (true/false). + host: false # Show node host (true/false). unit: "byte" # Unit for node usage, Available types: "byte" or "percentage". uptime: true # Enable or disable node uptime (true/false). limit: 100 # Node limit for usage statistics display. # Panel Users and Servers Settings panel_settings: + status: true # Display panel stats above node stats (true/false). + host: false # Show panel host (true/false). uptime: true # Enable or disable node uptime (true/false). - status: true # Display panel stats under node stats (true/false). servers: true # Display servers count (true/false). users: true # Display users count (true/false). diff --git a/handlers/app.js b/handlers/app.js index 26edaa3..7a57e63 100644 --- a/handlers/app.js +++ b/handlers/app.js @@ -23,7 +23,8 @@ module.exports = function App() { servers: results.servers, users: results.users, }); - } catch { + } catch (error) { + if (config.log_error) console.error(error) console.log(cliColor.cyanBright("[PteroStats] ") + cliColor.redBright("Panel is currently offline.")); fs.readFile(require('node:path').join(__dirname, "../cache.json"), (err, data) => { @@ -113,6 +114,7 @@ module.exports = function App() { name: `${node.attributes.name} - ${node.status ? config.status.online : config.status.offline}`, value: "```\n" + + (config.nodes_settings.host ? `Host : ${node.attributes.fqdn}\n` : "") + `Memory : ${convertUnits(node.attributes.allocated_resources.memory, node.attributes.memory, config.nodes_settings.unit)}\n` + `Disk : ${convertUnits(node.attributes.allocated_resources.disk, node.attributes.disk, config.nodes_settings.unit)}` + (node.attributes?.allocated_resources?.cpu ? `\nCPU : ${node.attributes?.allocated_resources?.cpu || 0}%` : "") + @@ -151,6 +153,7 @@ module.exports = function App() { name: `Panel - ${panel ? config.status.online : config.status.offline}`, value: "```\n" + + (config.panel_settings.host ? `Host : ${new URL(process.env.PanelURL).host}\n` : "") + `Nodes : ${nodes.length}\n` + (config.panel_settings.servers ? `Servers: ${servers || "Unknown"}\n` : "") + (config.panel_settings.users ? `Users : ${users || "Unknown"}\n` : "") + @@ -230,7 +233,7 @@ module.exports = function App() { } process.exit(); } catch (err) { - console.log(error) + console.error(error) process.exit(); } } diff --git a/handlers/getStats.js b/handlers/getStats.js index b1c4280..bced1a9 100644 --- a/handlers/getStats.js +++ b/handlers/getStats.js @@ -39,6 +39,7 @@ module.exports = async function getStats() { memory: node.attributes.memory, disk: node.attributes.disk, cpu: node.attributes.cpu, + fqdn: node.attributes.fqdn, allocated_resources: node.attributes.allocated_resources, relationships: { allocations: node.attributes.relationships.allocations.data.length,