@@ -108,28 +108,25 @@ mongo.communications = ({ microservice, slack, email }) => {
108108 * @param {number } interval Interval for continuous data collection
109109 */
110110mongo . health = async ( { microservice, interval, mode } ) => {
111-
111+ //MetricsModel tracks which metrics are selected in the MetricsContainer component
112+ //HealthModel tracks all the cpu health data in each of the services databases
112113 const getCurrentMets = async ( ) => await MetricsModel . find ( { mode } ) ;
113114 const currentMetrics = async ( ) => await getCurrentMets ( )
114115 currentMetrics ( )
115- // const currentMetrics = await MetricsModel.find({mode})
116- // const getCurrentMetsLength = async() =>
117- // console.log("CURR METS",currentMetrics.length)
116+ // let currentMetricNames = {}
117+
118+ // l = await mongo.getSavedMetricsLength(mode, currentMetricNames);
119+
118120 setInterval ( ( ) => {
119121 collectHealthData ( )
120122 . then ( async healthMetrics => {
121- // console.log("HEALTH METRICS",healthMetrics)
122-
123- // if (l !== healthMetrics.length) {
124- // l = await mongo.addMetrics(healthMetrics, mode, currentMetricNames);
125- // }
126- // if(currentMetrics.length !== healthMetrics.length) {
127- // const test = await mongo.mikesAdd(healthMetrics,currentMetrics,mode)
128- // console.log("FIRST DB",test)
129- // }
123+
124+ if ( currentMetrics . length !== healthMetrics . length ) {
125+ await mongo . addMetrics ( healthMetrics , mode , currentMetrics ) ;
126+ }
130127 const HealthModel = HealthModelFunc ( `${ microservice } ` ) ;
131- // await HealthModel.insertMany(healthMetrics);
132- // return
128+ await HealthModel . insertMany ( healthMetrics ) ;
129+ return
133130
134131 } )
135132 . then ( ( ) => {
@@ -282,9 +279,7 @@ mongo.setQueryOnInterval = async config => {
282279} ;
283280
284281mongo . getSavedMetricsLength = async ( mode , currentMetricNames ) => {
285- // console.log('mongo.getSavedMetricsLength',{mode,currentMetricNames})
286282 let currentMetrics = await MetricsModel . find ( { mode : mode } ) ;
287- // console.log("CURRENT METRICS",currentMetrics)
288283 if ( currentMetrics . length > 0 ) {
289284 currentMetrics . forEach ( el => {
290285 const { metric, selected } = el ;
@@ -296,24 +291,19 @@ mongo.getSavedMetricsLength = async (mode, currentMetricNames) => {
296291
297292mongo . addMetrics = async ( healthMetrics , mode , currentMetricNames ) => {
298293 //This function adds only the new metrics from metrics model to the metrics database
299- const metrics = [ ] ;
300294 const newMets = [ ] ;
301295 for ( let metric of healthMetrics ) {
302- // console.log("OUR METRICS",metric)
303296 if ( ! ( metric . metric in currentMetricNames ) ) {
304297 const name = metric . metric ;
305298 newMets . push ( { metric : name , mode : mode } ) ;
306- metrics . push ( metric ) ;
307299 currentMetricNames [ metric . metric ] = true ;
308300 }
309301 } ;
310- // console.log("NEW METS",newMets)
311- await MetricsModel . create ( { newMets} ) ;
312- // await model.create(metrics);
302+ await MetricsModel . create ( newMets ) ;
313303 return healthMetrics . length ;
314304} ;
315305
316- mongo . mikesAdd = async ( healthMetrics , currentMetrics , mode ) => {
306+ mongo . mikesAdd = async ( healthMetrics , mode , currentMetrics ) => {
317307 // console.log("INSIDE MIKES ADD")
318308 const metricMetaData = [ ]
319309 for ( let healthMetric of healthMetrics ) {
0 commit comments