mirror of
https://github.com/dokploy/dokploy.git
synced 2026-06-13 19:09:49 +00:00
Merge pull request #3462 from Dokploy/activate-monitoring-on-remote-servers-cloud-version
feat(server): add monitoring configuration for cloud setup
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import path from "node:path";
|
||||
import { paths } from "@dokploy/server/constants";
|
||||
import { IS_CLOUD, paths } from "@dokploy/server/constants";
|
||||
import { getDokployUrl } from "@dokploy/server/services/admin";
|
||||
import {
|
||||
createServerDeployment,
|
||||
updateDeploymentStatus,
|
||||
} from "@dokploy/server/services/deployment";
|
||||
import { findServerById } from "@dokploy/server/services/server";
|
||||
import {
|
||||
findServerById,
|
||||
updateServerById,
|
||||
} from "@dokploy/server/services/server";
|
||||
import {
|
||||
getDefaultMiddlewares,
|
||||
getDefaultServerTraefikConfig,
|
||||
@@ -16,6 +20,15 @@ import {
|
||||
import slug from "slugify";
|
||||
import { Client } from "ssh2";
|
||||
import { recreateDirectory } from "../utils/filesystem/directory";
|
||||
import { setupMonitoring } from "./monitoring-setup";
|
||||
|
||||
const generateToken = () => {
|
||||
const array = new Uint8Array(64);
|
||||
crypto.getRandomValues(array);
|
||||
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join(
|
||||
"",
|
||||
);
|
||||
};
|
||||
|
||||
export const slugify = (text: string | undefined) => {
|
||||
if (!text) {
|
||||
@@ -59,6 +72,29 @@ export const serverSetup = async (
|
||||
);
|
||||
await installRequirements(serverId, onData);
|
||||
|
||||
if (IS_CLOUD) {
|
||||
onData?.("\nConfiguring Monitoring: 🔄\n");
|
||||
|
||||
const baseUrl = await getDokployUrl();
|
||||
const token = generateToken();
|
||||
const urlCallback = `${baseUrl}/api/trpc/notification.receiveNotification`;
|
||||
|
||||
// Update server with monitoring configuration
|
||||
await updateServerById(serverId, {
|
||||
metricsConfig: {
|
||||
server: {
|
||||
...server.metricsConfig.server,
|
||||
token: token,
|
||||
urlCallback: urlCallback,
|
||||
},
|
||||
containers: server.metricsConfig.containers,
|
||||
},
|
||||
});
|
||||
|
||||
await setupMonitoring(serverId);
|
||||
onData?.("\nMonitoring Configured: ✅\n");
|
||||
}
|
||||
|
||||
await updateDeploymentStatus(deployment.deploymentId, "done");
|
||||
|
||||
onData?.("\nSetup Server: ✅\n");
|
||||
|
||||
Reference in New Issue
Block a user