@@ -20,7 +20,7 @@ const postgresFetch = fetchData.postgresFetch;
20
20
const AWS = require ( 'aws-sdk' ) ;
21
21
22
22
require ( 'dotenv' ) . config ( {
23
- path : path . join ( __dirname , './.env' )
23
+ path : path . join ( __dirname , './.env' ) ,
24
24
} ) ;
25
25
// Initiate pool variable for SQL setup
26
26
let pool : any ;
@@ -116,7 +116,6 @@ ipcMain.on('commsRequest', async (message: Electron.IpcMainEvent) => {
116
116
} catch ( error ) {
117
117
// Catch errors
118
118
console . log ( 'Error in "commsRequest" event: ' , error ) ;
119
-
120
119
}
121
120
} ) ;
122
121
@@ -126,14 +125,12 @@ ipcMain.on('commsRequest', async (message: Electron.IpcMainEvent) => {
126
125
*/
127
126
ipcMain . on ( 'healthRequest' , async ( message : Electron . IpcMainEvent , service : string ) => {
128
127
try {
129
-
130
128
let result : any ;
131
129
132
130
// Mongo Database
133
131
if ( currentDatabaseType === 'MongoDB' ) {
134
132
result = await mongoFetch ( service ) ;
135
133
}
136
-
137
134
138
135
// SQL Database
139
136
if ( currentDatabaseType === 'SQL' ) {
@@ -224,53 +221,55 @@ ipcMain.on('updateSavedMetrics', async (message: Electron.IpcMainEvent, args: Ob
224
221
if ( currentDatabaseType === 'MongoDB' && args . length ) {
225
222
// Update the 'selected' option for each metric
226
223
args . forEach ( async ( el : any ) => {
227
- await MetricsModel . updateOne ( { metric : el . metric } , {
228
- $set : {
229
- selected : el . selected
224
+ await MetricsModel . updateOne (
225
+ { metric : el . metric } ,
226
+ {
227
+ $set : {
228
+ selected : el . selected ,
229
+ } ,
230
230
}
231
- } )
232
- } )
231
+ ) ;
232
+ } ) ;
233
233
// let result = await MetricsModel.update();
234
234
}
235
235
if ( currentDatabaseType === 'SQL' && args . length ) {
236
236
args . forEach ( async ( el : any ) => {
237
- await pool . query ( `UPDATE metrics SET selected=${ el . selected } WHERE metric='${ el . metric } '` )
238
- } )
237
+ await pool . query ( `UPDATE metrics SET selected=${ el . selected } WHERE metric='${ el . metric } '` ) ;
238
+ } ) ;
239
239
}
240
+ } catch ( err ) {
241
+ if ( err ) console . error ( err ) ;
240
242
}
241
-
242
- catch ( err ) {
243
- if ( err ) console . error ( err )
244
- }
245
- } )
246
-
247
-
248
-
249
-
243
+ } ) ;
250
244
251
245
/**
252
246
* @event eventRequest/EventResponse
253
- * @desc
247
+ * @desc
254
248
*/
255
249
256
-
257
250
// start fetch
258
251
function extractWord ( str : string ) {
259
- const res : any [ ] = [ ] ;
252
+ const res : any [ ] = [ ] ;
260
253
const arr = str . split ( '\n' ) ; // `/\n/`
261
254
for ( const element of arr ) {
262
- if ( element && element . length !== 0 && element [ 0 ] !== '#' && element . substring ( 0 , 3 ) !== 'jmx' && element . substring ( 0 , 4 ) !== '\'jmx' ) {
255
+ if (
256
+ element &&
257
+ element . length !== 0 &&
258
+ element [ 0 ] !== '#' &&
259
+ element . substring ( 0 , 3 ) !== 'jmx' &&
260
+ element . substring ( 0 , 4 ) !== "'jmx"
261
+ ) {
263
262
const metric = element . split ( ' ' ) [ 0 ] ;
264
263
const metricValue = Number ( element . split ( ' ' ) [ 1 ] ) ;
265
264
const time = Date . now ( ) ;
266
- const temp = { ' metric' : metric , ' category' : 'Event' , ' value' : metricValue , ' time' : time } ;
265
+ const temp = { metric : metric , category : 'Event' , value : metricValue , time : time } ;
267
266
res . push ( temp ) ;
268
267
}
269
268
}
270
269
return res ;
271
270
}
272
271
273
- ipcMain . on ( 'kafkaRequest' , async ( message ) => {
272
+ ipcMain . on ( 'kafkaRequest' , async message => {
274
273
try {
275
274
let result : any ;
276
275
// Mongo Database
@@ -280,7 +279,7 @@ ipcMain.on('kafkaRequest', async (message) => {
280
279
// SQL Database
281
280
if ( currentDatabaseType === 'SQL' ) {
282
281
// Get last 50 documents. If less than 50 get all
283
- result = await postgresFetch ( 'kafkametrics' , pool ) ;
282
+ result = await postgresFetch ( 'kafkametrics' , pool ) ;
284
283
}
285
284
286
285
message . sender . send ( 'kafkaResponse' , JSON . stringify ( result ) ) ;
@@ -292,7 +291,7 @@ ipcMain.on('kafkaRequest', async (message) => {
292
291
} ) ;
293
292
294
293
// JJ-ADDITION
295
- ipcMain . on ( 'kubernetesRequest' , async ( message ) => {
294
+ ipcMain . on ( 'kubernetesRequest' , async message => {
296
295
try {
297
296
let result : any ;
298
297
// Mongo Database
@@ -302,27 +301,27 @@ ipcMain.on('kubernetesRequest', async (message) => {
302
301
// SQL Database
303
302
if ( currentDatabaseType === 'SQL' ) {
304
303
// Get last 50 documents. If less than 50 get all
305
- result = await postgresFetch ( 'kubernetesmetrics' , pool ) ;
304
+ result = await postgresFetch ( 'kubernetesmetrics' , pool ) ;
306
305
}
307
306
message . sender . send ( 'kubernetesResponse' , JSON . stringify ( result ) ) ;
308
307
} catch ( error ) {
309
308
// Catch errors
310
309
console . log ( 'Error in "kubernetesRequest" event' , message ) ;
311
310
message . sender . send ( 'kubernetesResponse' , { } ) ;
312
311
}
313
- } )
312
+ } ) ;
314
313
315
314
ipcMain . on ( 'awsMetricsRequest' , async ( message : Electron . IpcMainEvent ) => {
316
315
try {
317
316
// message.sender.send('awsMetricsResponse', 'hello from chronos team')
318
317
// console.log('i am inside the ipcmain')
319
-
318
+
320
319
const cloudwatch = new AWS . CloudWatch ( {
321
320
region : 'us-west-1' ,
322
321
accessKeyId : process . env . AWS_ACCESS_KEY ,
323
322
secretAccessKey : process . env . AWS_SECRET_KEY
324
323
} ) ;
325
-
324
+
326
325
const metricsNamesArray = [ 'CPUUtilization' , 'NetworkIn' , 'NetworkOut' , 'DiskReadBytes' ] ;
327
326
// const awsData = {};
328
327
const paramsArray = metricsNamesArray . map ( metric => {
@@ -333,7 +332,7 @@ ipcMain.on('awsMetricsRequest', async (message: Electron.IpcMainEvent) => {
333
332
Period : 60 ,
334
333
StartTime : new Date ( new Date ( ) . getTime ( ) - 60 * 60 * 1000 ) ,
335
334
Statistics : [ 'Average' ] ,
336
- Dimensions : [ {
335
+ Dimensions : [ {
337
336
Name : 'InstanceId' ,
338
337
Value : 'i-0c5656a0366bc6027'
339
338
} ]
@@ -351,12 +350,12 @@ ipcMain.on('awsMetricsRequest', async (message: Electron.IpcMainEvent) => {
351
350
352
351
const newData = data . Datapoints . map ( ( el , index : number ) => {
353
352
let transformedData = { } ;
354
-
353
+
355
354
transformedData [ 'time' ] = data . Datapoints [ index ] . Timestamp ,
356
355
transformedData [ 'metric' ] = data . Label ,
357
356
transformedData [ 'value' ] = data . Datapoints [ index ] . Average ,
358
357
transformedData [ 'unit' ] = data . Datapoints [ index ] . Unit
359
-
358
+
360
359
return transformedData ;
361
360
} ) ;
362
361
@@ -365,7 +364,7 @@ ipcMain.on('awsMetricsRequest', async (message: Electron.IpcMainEvent) => {
365
364
366
365
return fetched ;
367
366
} ;
368
-
367
+
369
368
fetchData ( ) . then ( data => {
370
369
message . sender . send ( 'awsMetricsResponse' , JSON . stringify ( data ) ) // send data to frontend
371
370
} )
@@ -375,6 +374,4 @@ ipcMain.on('awsMetricsRequest', async (message: Electron.IpcMainEvent) => {
375
374
}
376
375
} ) ;
377
376
378
-
379
-
380
377
// end fetch
0 commit comments