mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-02 02:02:18 +00:00
chore: update node-os-utils to version 2.0.1 and refactor lodash imports
- Upgraded `node-os-utils` from version 1.3.7 to 2.0.1 across multiple package.json files. - Removed deprecated `@types/node-os-utils` dependency. - Refactored lodash imports to use a single import statement for consistency. - Enhanced Docker stats monitoring by integrating new features from `node-os-utils` version 2.0.1.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import copy from "copy-to-clipboard";
|
import copy from "copy-to-clipboard";
|
||||||
import { debounce } from "lodash";
|
import _ from "lodash";
|
||||||
import {
|
import {
|
||||||
CheckIcon,
|
CheckIcon,
|
||||||
ChevronsUpDown,
|
ChevronsUpDown,
|
||||||
@@ -236,7 +236,7 @@ export const RestoreBackup = ({
|
|||||||
const currentDatabaseType = form.watch("databaseType");
|
const currentDatabaseType = form.watch("databaseType");
|
||||||
const metadata = form.watch("metadata");
|
const metadata = form.watch("metadata");
|
||||||
|
|
||||||
const debouncedSetSearch = debounce((value: string) => {
|
const debouncedSetSearch = _.debounce((value: string) => {
|
||||||
setDebouncedSearchTerm(value);
|
setDebouncedSearchTerm(value);
|
||||||
}, 350);
|
}, 350);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { FancyAnsi } from "fancy-ansi";
|
import { FancyAnsi } from "fancy-ansi";
|
||||||
import { escapeRegExp } from "lodash";
|
import _ from "lodash";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
@@ -47,7 +47,7 @@ export function TerminalLine({ log, noTimestamp, searchTerm }: LogLineProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const htmlContent = fancyAnsi.toHtml(text);
|
const htmlContent = fancyAnsi.toHtml(text);
|
||||||
const searchRegex = new RegExp(`(${escapeRegExp(term)})`, "gi");
|
const searchRegex = new RegExp(`(${_.escapeRegExp(term)})`, "gi");
|
||||||
|
|
||||||
const modifiedContent = htmlContent.replace(
|
const modifiedContent = htmlContent.replace(
|
||||||
searchRegex,
|
searchRegex,
|
||||||
|
|||||||
@@ -120,7 +120,7 @@
|
|||||||
"next": "^15.3.2",
|
"next": "^15.3.2",
|
||||||
"next-i18next": "^15.4.2",
|
"next-i18next": "^15.4.2",
|
||||||
"next-themes": "^0.2.1",
|
"next-themes": "^0.2.1",
|
||||||
"node-os-utils": "1.3.7",
|
"node-os-utils": "2.0.1",
|
||||||
"node-pty": "1.0.0",
|
"node-pty": "1.0.0",
|
||||||
"node-schedule": "2.1.1",
|
"node-schedule": "2.1.1",
|
||||||
"nodemailer": "6.9.14",
|
"nodemailer": "6.9.14",
|
||||||
@@ -163,7 +163,6 @@
|
|||||||
"@types/lodash": "4.17.4",
|
"@types/lodash": "4.17.4",
|
||||||
"@types/micromatch": "4.0.9",
|
"@types/micromatch": "4.0.9",
|
||||||
"@types/node": "^18.19.104",
|
"@types/node": "^18.19.104",
|
||||||
"@types/node-os-utils": "1.3.4",
|
|
||||||
"@types/node-schedule": "2.1.6",
|
"@types/node-schedule": "2.1.6",
|
||||||
"@types/nodemailer": "^6.4.17",
|
"@types/nodemailer": "^6.4.17",
|
||||||
"@types/qrcode": "^1.5.5",
|
"@types/qrcode": "^1.5.5",
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ import {
|
|||||||
recordAdvancedStats,
|
recordAdvancedStats,
|
||||||
validateRequest,
|
validateRequest,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
|
import { OSUtils } from "node-os-utils";
|
||||||
import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
|
import { formatBytes } from "@/components/dashboard/database/backups/restore-backup";
|
||||||
|
|
||||||
export const setupDockerStatsMonitoringSocketServer = (
|
export const setupDockerStatsMonitoringSocketServer = (
|
||||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||||
@@ -49,6 +51,83 @@ export const setupDockerStatsMonitoringSocketServer = (
|
|||||||
}
|
}
|
||||||
const intervalId = setInterval(async () => {
|
const intervalId = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
|
// Special case: when monitoring "dokploy", get host system stats instead of container stats
|
||||||
|
if (appName === "dokploy") {
|
||||||
|
const osutils = new OSUtils();
|
||||||
|
|
||||||
|
// Get CPU usage
|
||||||
|
const cpuResult = await osutils.cpu.usage();
|
||||||
|
const cpuUsage = cpuResult.success ? cpuResult.data : 0;
|
||||||
|
|
||||||
|
// Get memory info
|
||||||
|
const memResult = await osutils.memory.info();
|
||||||
|
let memUsedGB = 0;
|
||||||
|
let memTotalGB = 0;
|
||||||
|
let memUsedPercent = 0;
|
||||||
|
if (memResult.success) {
|
||||||
|
memTotalGB = memResult.data.total.toGB();
|
||||||
|
memUsedGB = memResult.data.used.toGB();
|
||||||
|
memUsedPercent = memResult.data.usagePercentage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get network stats from network.overview() or network.statsAsync()
|
||||||
|
let netInputBytes = 0;
|
||||||
|
let netOutputBytes = 0;
|
||||||
|
const networkOverview = await osutils.network.overview();
|
||||||
|
if (networkOverview.success) {
|
||||||
|
netInputBytes = networkOverview.data.totalRxBytes.toBytes();
|
||||||
|
netOutputBytes = networkOverview.data.totalTxBytes.toBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Block I/O from disk.stats() (available in v2.0!)
|
||||||
|
// If disk.stats() doesn't work in container, fallback to /proc/diskstats
|
||||||
|
let blockReadBytes = 0;
|
||||||
|
let blockWriteBytes = 0;
|
||||||
|
const diskStats = await osutils.disk.stats();
|
||||||
|
if (diskStats.success && diskStats.data.length > 0) {
|
||||||
|
for (const stat of diskStats.data) {
|
||||||
|
blockReadBytes += stat.readBytes.toBytes();
|
||||||
|
blockWriteBytes += stat.writeBytes.toBytes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format memory usage similar to docker stats format: "used / total"
|
||||||
|
const memUsedFormatted = `${memUsedGB.toFixed(2)}GiB`;
|
||||||
|
const memTotalFormatted = `${memTotalGB.toFixed(2)}GiB`;
|
||||||
|
const memUsageFormatted = `${memUsedFormatted} / ${memTotalFormatted}`;
|
||||||
|
|
||||||
|
// Format network I/O
|
||||||
|
const netInputMb = netInputBytes / (1024 * 1024);
|
||||||
|
const netOutputMb = netOutputBytes / (1024 * 1024);
|
||||||
|
const netIOFormatted = `${netInputMb.toFixed(2)}MB / ${netOutputMb.toFixed(2)}MB`;
|
||||||
|
|
||||||
|
// Format Block I/O
|
||||||
|
const blockIOFormatted = `${formatBytes(blockReadBytes)} / ${formatBytes(blockWriteBytes)}`;
|
||||||
|
|
||||||
|
// Create a stat object compatible with recordAdvancedStats
|
||||||
|
const stat = {
|
||||||
|
CPUPerc: `${cpuUsage.toFixed(2)}%`,
|
||||||
|
MemPerc: `${memUsedPercent.toFixed(2)}%`,
|
||||||
|
MemUsage: memUsageFormatted,
|
||||||
|
BlockIO: blockIOFormatted,
|
||||||
|
NetIO: netIOFormatted,
|
||||||
|
Container: "dokploy",
|
||||||
|
ID: "host-system",
|
||||||
|
Name: "dokploy",
|
||||||
|
};
|
||||||
|
|
||||||
|
await recordAdvancedStats(stat, appName);
|
||||||
|
const data = await getLastAdvancedStatsFile(appName);
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
ws.send(
|
||||||
|
JSON.stringify({
|
||||||
|
data,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
status: ["running"],
|
status: ["running"],
|
||||||
...(appType === "application" && {
|
...(appType === "application" && {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"micromatch": "4.0.8",
|
"micromatch": "4.0.8",
|
||||||
"nanoid": "3.3.11",
|
"nanoid": "3.3.11",
|
||||||
"node-os-utils": "1.3.7",
|
"node-os-utils": "2.0.1",
|
||||||
"node-pty": "1.0.0",
|
"node-pty": "1.0.0",
|
||||||
"node-schedule": "2.1.1",
|
"node-schedule": "2.1.1",
|
||||||
"nodemailer": "6.9.14",
|
"nodemailer": "6.9.14",
|
||||||
@@ -88,7 +88,6 @@
|
|||||||
"@types/lodash": "4.17.4",
|
"@types/lodash": "4.17.4",
|
||||||
"@types/micromatch": "4.0.9",
|
"@types/micromatch": "4.0.9",
|
||||||
"@types/node": "^18.19.104",
|
"@types/node": "^18.19.104",
|
||||||
"@types/node-os-utils": "1.3.4",
|
|
||||||
"@types/node-schedule": "2.1.6",
|
"@types/node-schedule": "2.1.6",
|
||||||
"@types/nodemailer": "^6.4.17",
|
"@types/nodemailer": "^6.4.17",
|
||||||
"@types/qrcode": "^1.5.5",
|
"@types/qrcode": "^1.5.5",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { promises } from "node:fs";
|
import { promises } from "node:fs";
|
||||||
import osUtils from "node-os-utils";
|
import { OSUtils } from "node-os-utils";
|
||||||
import { paths } from "../constants";
|
import { paths } from "../constants";
|
||||||
|
|
||||||
export interface Container {
|
export interface Container {
|
||||||
BlockIO: string;
|
BlockIO: string;
|
||||||
CPUPerc: string;
|
CPUPerc: string;
|
||||||
@@ -38,19 +37,23 @@ export const recordAdvancedStats = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (appName === "dokploy") {
|
if (appName === "dokploy") {
|
||||||
const disk = await osUtils.drive.info("/");
|
const osutils = new OSUtils();
|
||||||
|
const diskResult = await osutils.disk.usageByMountPoint("/");
|
||||||
|
|
||||||
const diskUsage = disk.usedGb;
|
if (diskResult.success && diskResult.data) {
|
||||||
const diskTotal = disk.totalGb;
|
const disk = diskResult.data;
|
||||||
const diskUsedPercentage = disk.usedPercentage;
|
const diskUsage = disk.used.toGB().toFixed(2);
|
||||||
const diskFree = disk.freeGb;
|
const diskTotal = disk.total.toGB().toFixed(2);
|
||||||
|
const diskUsedPercentage = disk.usagePercentage;
|
||||||
|
const diskFree = disk.available.toGB().toFixed(2);
|
||||||
|
|
||||||
await updateStatsFile(appName, "disk", {
|
await updateStatsFile(appName, "disk", {
|
||||||
diskTotal: +diskTotal,
|
diskTotal: +diskTotal,
|
||||||
diskUsedPercentage: +diskUsedPercentage,
|
diskUsedPercentage: +diskUsedPercentage,
|
||||||
diskUsage: +diskUsage,
|
diskUsage: +diskUsage,
|
||||||
diskFree: +diskFree,
|
diskFree: +diskFree,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -419,6 +419,9 @@ export const deployPreviewApplication = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getApplicationStats = async (appName: string) => {
|
export const getApplicationStats = async (appName: string) => {
|
||||||
|
if (appName === "dokploy") {
|
||||||
|
return await getAdvancedStats(appName);
|
||||||
|
}
|
||||||
const filter = {
|
const filter = {
|
||||||
status: ["running"],
|
status: ["running"],
|
||||||
label: [`com.docker.swarm.service.name=${appName}`],
|
label: [`com.docker.swarm.service.name=${appName}`],
|
||||||
|
|||||||
Generated
+8
-18
@@ -347,8 +347,8 @@ importers:
|
|||||||
specifier: ^0.2.1
|
specifier: ^0.2.1
|
||||||
version: 0.2.1([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])
|
version: 0.2.1([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])
|
||||||
node-os-utils:
|
node-os-utils:
|
||||||
specifier: 1.3.7
|
specifier: 2.0.1
|
||||||
version: 1.3.7
|
version: 2.0.1
|
||||||
node-pty:
|
node-pty:
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
@@ -473,9 +473,6 @@ importers:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^18.19.104
|
specifier: ^18.19.104
|
||||||
version: 18.19.104
|
version: 18.19.104
|
||||||
'@types/node-os-utils':
|
|
||||||
specifier: 1.3.4
|
|
||||||
version: 1.3.4
|
|
||||||
'@types/node-schedule':
|
'@types/node-schedule':
|
||||||
specifier: 2.1.6
|
specifier: 2.1.6
|
||||||
version: 2.1.6
|
version: 2.1.6
|
||||||
@@ -688,8 +685,8 @@ importers:
|
|||||||
specifier: 3.3.11
|
specifier: 3.3.11
|
||||||
version: 3.3.11
|
version: 3.3.11
|
||||||
node-os-utils:
|
node-os-utils:
|
||||||
specifier: 1.3.7
|
specifier: 2.0.1
|
||||||
version: 1.3.7
|
version: 2.0.1
|
||||||
node-pty:
|
node-pty:
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
@@ -766,9 +763,6 @@ importers:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: ^18.19.104
|
specifier: ^18.19.104
|
||||||
version: 18.19.104
|
version: 18.19.104
|
||||||
'@types/node-os-utils':
|
|
||||||
specifier: 1.3.4
|
|
||||||
version: 1.3.4
|
|
||||||
'@types/node-schedule':
|
'@types/node-schedule':
|
||||||
specifier: 2.1.6
|
specifier: 2.1.6
|
||||||
version: 2.1.6
|
version: 2.1.6
|
||||||
@@ -4000,9 +3994,6 @@ packages:
|
|||||||
'@types/[email protected]':
|
'@types/[email protected]':
|
||||||
resolution: {integrity: sha512-DSLCOXhkvfS5WNNPbfn2KdICAmk8lLc+/PNvnPnF7gOdMZCxopXduqv0OQ13y/yA/zXTSikZZqVgybUxOEg6YQ==}
|
resolution: {integrity: sha512-DSLCOXhkvfS5WNNPbfn2KdICAmk8lLc+/PNvnPnF7gOdMZCxopXduqv0OQ13y/yA/zXTSikZZqVgybUxOEg6YQ==}
|
||||||
|
|
||||||
'@types/[email protected]':
|
|
||||||
resolution: {integrity: sha512-BCUYrbdoO4FUbx6MB9atLNFnkxdliFaxdiTJMIPPiecXIApc5zf4NIqV5G1jWv/ReZvtYyHLs40RkBjHX+vykA==}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
'@types/[email protected]':
|
||||||
resolution: {integrity: sha512-6AlZSUiNTdaVmH5jXYxX9YgmF1zfOlbjUqw0EllTBmZCnN1R5RR/m/u3No1OiWR05bnQ4jM4/+w4FcGvkAtnKQ==}
|
resolution: {integrity: sha512-6AlZSUiNTdaVmH5jXYxX9YgmF1zfOlbjUqw0EllTBmZCnN1R5RR/m/u3No1OiWR05bnQ4jM4/+w4FcGvkAtnKQ==}
|
||||||
|
|
||||||
@@ -6312,8 +6303,9 @@ packages:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
node-os-utils@1.3.7:
|
node-os-utils@2.0.1:
|
||||||
resolution: {integrity: sha512-fvnX9tZbR7WfCG5BAy3yO/nCLyjVWD6MghEq0z5FDfN+ZXpLWNITBdbifxQkQ25ebr16G0N7eRWJisOcMEHG3Q==}
|
resolution: {integrity: sha512-rH2N3qHZETLhdgTGhMMCE8zU3gsWO4we1MFtrSiAI7tYWrnJRc6dk2PseV4co3Lb0v/MbRONLQI2biHQYbpTpg==}
|
||||||
|
engines: {node: '>=18.0.0'}
|
||||||
|
|
||||||
[email protected]:
|
[email protected]:
|
||||||
resolution: {integrity: sha512-wtBMWWS7dFZm/VgqElrTvtfMq4GzJ6+edFI0Y0zyzygUSZMgZdraDUMUhCIvkjhJjme15qWmbyJbtAx4ot4uZA==}
|
resolution: {integrity: sha512-wtBMWWS7dFZm/VgqElrTvtfMq4GzJ6+edFI0Y0zyzygUSZMgZdraDUMUhCIvkjhJjme15qWmbyJbtAx4ot4uZA==}
|
||||||
@@ -11338,8 +11330,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 20.17.51
|
'@types/node': 20.17.51
|
||||||
|
|
||||||
'@types/[email protected]': {}
|
|
||||||
|
|
||||||
'@types/[email protected]':
|
'@types/[email protected]':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 20.17.51
|
'@types/node': 20.17.51
|
||||||
@@ -13852,7 +13842,7 @@ snapshots:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@types/node': 18.19.104
|
'@types/node': 18.19.104
|
||||||
|
|
||||||
node-os-utils@1.3.7: {}
|
node-os-utils@2.0.1: {}
|
||||||
|
|
||||||
[email protected]:
|
[email protected]:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user