Skip to content

Commit c4d65e3

Browse files
committed
Removed console.logs from debugging.
2 parents d471f0b + a9c6838 commit c4d65e3

2 files changed

Lines changed: 70 additions & 7 deletions

File tree

Main.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ ipcMain.on('overviewRequest', (message, index) => {
101101
message.sender.send('overviewResponse', JSON.stringify(err));
102102
}
103103
const queryResults = JSON.stringify(data);
104-
console.log(queryResults);
105104
// Asynchronous event emitter used to transmit query results back to the render process.
106105
message.sender.send('overviewResponse', queryResults);
107106
});
@@ -116,7 +115,6 @@ ipcMain.on('overviewRequest', (message, index) => {
116115
message.sender.send(JSON.stringify('Database info could not be retreived.'));
117116
}
118117
const queryResults = JSON.stringify(result.rows);
119-
console.log(queryResults);
120118
// Asynchronous event emitter used to transmit query results back to the render process.
121119
message.sender.send('overviewResponse', queryResults);
122120
});
@@ -131,14 +129,12 @@ ipcMain.on('detailsRequest', (message, index) => {
131129

132130
if (databaseType === 'MongoDB') {
133131
connectMongoose(index);
134-
console.log(HealthInfoSchema)
135132
HealthInfoSchema.find({}, (err, data) => {
136133
if (err) {
137-
console.log(`An error occured while querying the database: ${err}`);
138134
message.sender.send('detailsResponse', JSON.stringify(err));
139135
}
140136
const queryResults = JSON.stringify(data);
141-
console.log(queryResults);
137+
console.log('QUERY RESULTS =>', queryResults);
142138
// Asynchronous event emitter used to transmit query results back to the render process.
143139
message.sender.send('detailsResponse', queryResults);
144140
});
@@ -149,11 +145,9 @@ ipcMain.on('detailsRequest', (message, index) => {
149145
const getHealth = 'SELECT * FROM healthInfo';
150146
pool.query(getHealth, (err, result) => {
151147
if (err) {
152-
console.log(err);
153148
message.sender.send('detailsResponse', JSON.stringify('Database info could not be retreived.'));
154149
}
155150
const queryResults = JSON.stringify(result.rows);
156-
console.log(queryResults)
157151
// Asynchronous event emitter used to transmit query results back to the render process.
158152
message.sender.send('detailsResponse', queryResults);
159153
});

app/charts/memory-chart.jsx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { useContext } from 'react';
2+
// You can change the chart property imported to the one that suits your needs.
3+
import { Bar } from 'react-chartjs-2';
4+
import HealthContext from '../context/DetailsContext';
5+
6+
const MemoryChart = () => {
7+
// ! Do not change the variables related to context.
8+
const healthData = useContext(HealthContext);
9+
const health = healthData.detailsData;
10+
11+
// Helper function
12+
const createChart = () => {
13+
// Object for storing data
14+
const memoryObj = {
15+
free: 0,
16+
active: 0,
17+
used: 0,
18+
total: 0
19+
};
20+
21+
// Iterate through HealthInfo to creat an object with data needed to create your graph.
22+
for (let i = 0; i < health.length; i += 1) {
23+
//Mongo
24+
if (health[i].freeMemory) {
25+
memoryObj.free += health[i].freeMemory
26+
memoryObj.active += health[i].activeMemory
27+
memoryObj.used += health[i].usedMemory
28+
memoryObj.total += health[i].totalMemory
29+
} else if (health[i].freememory) {
30+
memoryObj.free += health[i].freememory;
31+
memoryObj.active += health[i].activememory;
32+
memoryObj.used += health[i].usedmemory;
33+
memoryObj.total += health[i].totalmemory;
34+
}
35+
}
36+
memoryObj.free /= 1000000000
37+
memoryObj.active /= 1000000000
38+
memoryObj.used /= 1000000000
39+
memoryObj.total /= 100000000
40+
41+
// ! Chart Data
42+
// * --- Change the object used in data to the one you created.
43+
// * --- Labels must be in the same order as the keys in your object.
44+
const chartData = {
45+
datasets: [
46+
{
47+
label: 'Breakdown of Memory in Gigabytes',
48+
data: Object.values(memoryObj),
49+
backgroundColor: [
50+
'rgb(2, 210, 249)',
51+
'rgb(198, 42, 177)',
52+
'rgb(252, 170, 52)',
53+
'rgb(239, 91, 145)',
54+
'rgb(182, 219, 26)',
55+
'rgb(254, 255, 0)',
56+
],
57+
},
58+
],
59+
labels: ['Free Memory', 'Active Memory', 'Used Memory', 'Total Memory'],
60+
};
61+
62+
return <Bar data={chartData} />;
63+
};
64+
65+
// Return div with helper function invoked
66+
return <div>{createChart()}</div>;
67+
};
68+
69+
export default MemoryChart;

0 commit comments

Comments
 (0)