@@ -38,6 +38,7 @@ import { getImporterStatistics } from './getImporterStatistics';
3838import { getServicesStatistics } from './getServicesStatistics' ;
3939import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred' ;
4040import { isRunningMs } from '../../../../server/lib/isRunningMs' ;
41+ import { SystemLogger } from '../../../../server/lib/logger/system' ;
4142import { getControl } from '../../../../server/lib/migrations' ;
4243import { getSettingsStatistics } from '../../../../server/lib/statistics/getSettingsStatistics' ;
4344import { getMatrixFederationStatistics } from '../../../../server/services/federation/infrastructure/rocket-chat/adapters/Statistics' ;
@@ -599,4 +600,58 @@ export const statistics = {
599600
600601 return rcStatistics ;
601602 } ,
603+ async updateDeploymentData ( ) : Promise < void > {
604+ try {
605+ const lastStatistics = await Statistics . findLast ( ) ;
606+
607+ if ( ! lastStatistics ) {
608+ return ;
609+ }
610+
611+ const { mongoVersion, mongoStorageEngine } = await getMongoInfo ( ) ;
612+
613+ const deploymentInfo : Partial < IStats > = {
614+ os : {
615+ type : os . type ( ) ,
616+ platform : os . platform ( ) ,
617+ arch : os . arch ( ) ,
618+ release : os . release ( ) ,
619+ uptime : os . uptime ( ) ,
620+ loadavg : os . loadavg ( ) ,
621+ totalmem : os . totalmem ( ) ,
622+ freemem : os . freemem ( ) ,
623+ cpus : os . cpus ( ) ,
624+ } ,
625+ process : {
626+ nodeVersion : process . version ,
627+ pid : process . pid ,
628+ uptime : process . uptime ( ) ,
629+ } ,
630+ deploy : {
631+ method : process . env . DEPLOY_METHOD || 'tar' ,
632+ platform : process . env . DEPLOY_PLATFORM || 'selfinstall' ,
633+ } ,
634+ msEnabled : isRunningMs ( ) ,
635+ mongoVersion,
636+ mongoStorageEngine : mongoStorageEngine || '' ,
637+ migration : await getControl ( ) ,
638+ } ;
639+
640+ if ( Info ) {
641+ deploymentInfo . version = Info . version ;
642+ }
643+
644+ const { _id, ...baseStatistics } = lastStatistics ;
645+
646+ const newStatistics : Omit < IStats , '_id' > = {
647+ ...baseStatistics ,
648+ ...deploymentInfo ,
649+ createdAt : new Date ( ) ,
650+ } ;
651+
652+ await Statistics . insertOne ( newStatistics ) ;
653+ } catch ( error ) {
654+ SystemLogger . error ( { msg : 'Error saving statistics with new deployment data' , err : error } ) ;
655+ }
656+ } ,
602657} ;
0 commit comments