11import path from "node:path" ;
2- import { paths } from "@dokploy/server/constants" ;
2+ import { IS_CLOUD , paths } from "@dokploy/server/constants" ;
3+ import { getDokployUrl } from "@dokploy/server/services/admin" ;
34import {
45 createServerDeployment ,
56 updateDeploymentStatus ,
67} from "@dokploy/server/services/deployment" ;
7- import { findServerById } from "@dokploy/server/services/server" ;
8+ import {
9+ findServerById ,
10+ updateServerById ,
11+ } from "@dokploy/server/services/server" ;
812import {
913 getDefaultMiddlewares ,
1014 getDefaultServerTraefikConfig ,
@@ -16,6 +20,15 @@ import {
1620import slug from "slugify" ;
1721import { Client } from "ssh2" ;
1822import { recreateDirectory } from "../utils/filesystem/directory" ;
23+ import { setupMonitoring } from "./monitoring-setup" ;
24+
25+ const generateToken = ( ) => {
26+ const array = new Uint8Array ( 64 ) ;
27+ crypto . getRandomValues ( array ) ;
28+ return Array . from ( array , ( byte ) => byte . toString ( 16 ) . padStart ( 2 , "0" ) ) . join (
29+ "" ,
30+ ) ;
31+ } ;
1932
2033export const slugify = ( text : string | undefined ) => {
2134 if ( ! text ) {
@@ -59,6 +72,29 @@ export const serverSetup = async (
5972 ) ;
6073 await installRequirements ( serverId , onData ) ;
6174
75+ if ( IS_CLOUD ) {
76+ onData ?.( "\nConfiguring Monitoring: 🔄\n" ) ;
77+
78+ const baseUrl = await getDokployUrl ( ) ;
79+ const token = generateToken ( ) ;
80+ const urlCallback = `${ baseUrl } /api/trpc/notification.receiveNotification` ;
81+
82+ // Update server with monitoring configuration
83+ await updateServerById ( serverId , {
84+ metricsConfig : {
85+ server : {
86+ ...server . metricsConfig . server ,
87+ token : token ,
88+ urlCallback : urlCallback ,
89+ } ,
90+ containers : server . metricsConfig . containers ,
91+ } ,
92+ } ) ;
93+
94+ await setupMonitoring ( serverId ) ;
95+ onData ?.( "\nMonitoring Configured: ✅\n" ) ;
96+ }
97+
6298 await updateDeploymentStatus ( deployment . deploymentId , "done" ) ;
6399
64100 onData ?.( "\nSetup Server: ✅\n" ) ;
0 commit comments