Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/components/TransferColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { EventContext } from '../context/EventContext';
import { DataGrid } from '@material-ui/data-grid';
import * as DashboardContext from '../context/DashboardContext';
import lightAndDark from './Styling';

import { Button, TextField } from '@mui/material';
import SearchBar from './SearchBar/SearchBar';


interface Params {
service: string;
}
Expand Down
12 changes: 7 additions & 5 deletions app/containers/GraphsContainer/GraphsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Params {
const GraphsContainer: React.FC = React.memo(() => {
const { app, service } = useParams<keyof Params>() as Params;
const [live, setLive] = useState<boolean>(false);
const { intervalID, setIntervalID, example, chart, setChart } = useContext(ApplicationContext);
const { intervalID, setIntervalID, chart, setChart } = useContext(ApplicationContext);
const { getSavedMetrics } = useContext(ApplicationContext);
const { fetchHealthData, setHealthData } = useContext(HealthContext);
const { setDockerData, dockerData } = useContext(DockerContext);
Expand All @@ -47,7 +47,6 @@ const GraphsContainer: React.FC = React.memo(() => {

useEffect(() => {
const serviceArray = service.split(' ');
// You would think you should add "kubernetesmetrics" into the below for consistency's sake but it makes it not work correctly, so it has been omitted
const healthServiceArray = serviceArray.filter(
(value: string) => value !== 'kafkametrics' && value !== 'kubernetesmetrics'
);
Expand All @@ -60,23 +59,27 @@ const GraphsContainer: React.FC = React.memo(() => {
if (service.includes('kafkametrics')) {
fetchEventData('kafkametrics');
}
// JJ-ADDITION
if (service.includes('kubernetesmetrics')) {
fetchEventData('kubernetesmetrics');
}
}, 10000)
);
} else {
//This block gets data from the metrics db, the health data from each of the services respective dbs and the communcations logs in the communications db
//The respective states are commsData, healthData and savedMetrics
if (intervalID) clearInterval(intervalID);
// gets all the communication logs from the communications database and sets the communications data state
fetchCommsData(app, live);
// gets all health data stored in each of the services databases
fetchHealthData(healthServiceArray);
//kafka and kubernetes are currently not hooked up so these blocks will never fire
if (service.includes('kafkametrics')) {
fetchEventData('kafkametrics');
}
// JJ-ADDITION
if (service.includes('kubernetesmetrics')) {
fetchEventData('kubernetesmetrics');
}
// gets all metric data (cpu related metrics)
getSavedMetrics();
}

Expand All @@ -88,7 +91,6 @@ const GraphsContainer: React.FC = React.memo(() => {
};
}, [service, live]);

//random variable to hold the light or dark mode of the display?..ok....sure
const currentMode = mode === 'light' ? lightAndDark.lightModeText : lightAndDark.darkModeText;

return (
Expand Down
12 changes: 1 addition & 11 deletions app/context/ApplicationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
const children = props.children;
const [ example,setExample ] = useState(false)
const [chart, setChart] = useState<string>('all');

const [servicesData, setServicesData] = useState([]);
const [app, setApp] = useState<string>('');
const [savedMetrics, setSavedMetrics] = useState({});
const [appIndex, setAppIndex] = useState<number>(0);
const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);


/**
* @function fetchServicesNames - a function that will take an application name and update the state of `serviceData` based on backend response
* 1. Take in an application name
Expand All @@ -41,17 +39,11 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
// v10: Invoked by connectToDB, passing in app (card title)
const fetchServicesNames = useCallback((application: string) => {

console.log({application});
// console.log('Hi, inside ApplicationConext - fetchServicesNames callback. Sending servicesRequest to ipcMain.');
console.log('app when fetch services name: ', application);

ipcRenderer.send('servicesRequest');
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
//data here refers to the data coming the services document of the database
//data here refers to the services coming the services document of the database
let result: any;
result = JSON.parse(data);

// console.log('Calling setServicesData passing in above result. Current servicesData is the following: ', servicesData);
setServicesData(result);
ipcRenderer.removeAllListeners('servicesResponse');
});
Expand Down Expand Up @@ -90,8 +82,6 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
data.forEach(el => {
store[el.metric] = el;
});
// console.log({store})
// console.log('result from getSavedMetrics is: ', store);
setSavedMetrics(store);
});
}, []);
Expand Down
2 changes: 1 addition & 1 deletion app/context/CommsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const CommsContextProvider: React.FC<Props> = React.memo((props) => {
ipcRenderer.send('commsRequest');
ipcRenderer.on('commsResponse', (event: Electron.Event, data: any) => {
let result: any;
//Here we are grabbing all the data from our test database
//Here we are grabbing all the data from our communications database
if (tryParseJSON(data)) result = JSON.parse(data);
setCommsData(result);
});
Expand Down
73 changes: 36 additions & 37 deletions app/context/HealthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,47 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
*/

const fetchHealthData = useCallback(async servers => {
// console.log({servers})
ipcRenderer.removeAllListeners('healthResponse');

let temp: HealthDataObject[] = [];
//Promise.all(
let promises = await Promise.all(servers.map( async (service: string) => {
//NOT WORKING HERE
try {
const newPromise: any = await new Promise((resolve, reject) => {
ipcRenderer.send('healthRequest', `${service}`);
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
let result: object[];
// console.log({data})
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
result = JSON.parse(data);
// console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
//result exists, has a length prop, and the service name and database name are same
if (result && result.length && `${service}` === Object.keys(result[0])[0]) {
resolve(result[0]);
}
}
});
})
temp.push(newPromise);
// console.log('HealthContext.tsx line 80 temp populates?: ', temp, serv)
if (checkServicesComplete(temp, [`${service}`])) {
setServices([`${service}`]);
let transformedData: any = {};
// console.log('original healthData before transformation: ', temp);
// transformedData = {
// healthDataList: [1,2,3,4,5],
// healthTimeList: [1,2,3,4,5]
// } //testing typescript, transformedDATA of type 2 arrays with basic entries?
transformedData = healthTransformer(temp); //must match the setHealthData STATE format
// console.log('healthData after tranformation: ', transformedData);
setHealthData(transformedData);
await Promise.all(servers.map( async (service: string) => {
//NOT WORKING HERE
try {
const newPromise: any = await new Promise((resolve, reject) => {
ipcRenderer.send('healthRequest', `${service}`);
ipcRenderer.on('healthResponse', (event: Electron.Event, data: string) => {
let result: object[];
// console.log({data})
if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
result = JSON.parse(data);
// console.log({result})
// console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
//result exists, has a length prop, and the service name and database name are same
if (result && result.length && `${service}` === Object.keys(result[0])[0]) {
resolve(result[0]);
}
}
} catch (err) {
// console.log("healthcontext.tsx ERROR: ", err);
};
});
})
temp.push(newPromise);
// console.log('HealthContext.tsx line 80 temp populates?: ', temp, serv)
if (checkServicesComplete(temp, [`${service}`])) {
setServices([`${service}`]);
let transformedData: any = {};
// console.log('original healthData before transformation: ', temp);
// transformedData = {
// healthDataList: [1,2,3,4,5],
// healthTimeList: [1,2,3,4,5]
// } //testing typescript, transformedDATA of type 2 arrays with basic entries?
transformedData = healthTransformer(temp); //must match the setHealthData STATE format
// console.log('healthData after tranformation: ', transformedData);
setHealthData(transformedData);
}
))
} catch (err) {
// console.log("healthcontext.tsx ERROR: ", err);
};
}
))
} , []);

const checkServicesComplete = (temp: any[], servers: string[]) => {
Expand Down
3 changes: 2 additions & 1 deletion chronos_npm_package/chronos.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ class Chronos {
* endpoint that the user Request travels through (tracked with hpropograte) for express routes
*/
if (database.type === 'MongoDB') {
//mongo is referring to controller function defined locally, not the actual mongodb object
mongo.connect(this.config);
mongo.services(this.config);
// console.log('dockerized really? chronos.js LN 75', dockerized, this.config)
dockerized ? mongo.docker(this.config) : mongo.health(this.config);

if (database.connection === 'REST') {
return mongo.communications(this.config);
}
Expand Down
28 changes: 17 additions & 11 deletions chronos_npm_package/controllers/healthHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ const collectedMetrics = {
* @returns Promise array with each metric in an object
*/

healthHelpers.collectHealthData = () => {
healthHelpers.collectHealthData = async() => {

const healthDataCollection = [];
const time = Date.now();

/** obtains core CPU metrics and creates and pushes object with
* metric name and value to the healthDataCollection array
*/
si.cpu()
await si.cpu()
.then(data => {
// console.log(data)
const siMethodName = 'cpu';
for (let metricName in collectedMetrics[siMethodName]) {
healthDataCollection.push({
Expand All @@ -76,6 +78,7 @@ healthHelpers.collectHealthData = () => {
time,
});
}
// console.log('CPU HEALTH METRICS',healthDataCollection)
})
.catch(err => {
if (err) {
Expand All @@ -86,7 +89,7 @@ healthHelpers.collectHealthData = () => {
/** obtains CPU speed metrics and creates and pushes object with
* metric name and value to the healthDataCollection array
*/
si.cpuCurrentSpeed()
await si.cpuCurrentSpeed()
.then(data => {
const siMethodName = 'cpuCurrentSpeed';
for (let metricName in collectedMetrics[siMethodName]) {
Expand All @@ -108,7 +111,7 @@ healthHelpers.collectHealthData = () => {
* metric name and value to the healthDataCollection array
*/

si.cpuTemperature()
await si.cpuTemperature()
.then(data => {
const siMethodName = 'cpuTemperature';
for (let metricName in collectedMetrics[siMethodName]) {
Expand All @@ -130,7 +133,7 @@ healthHelpers.collectHealthData = () => {
* obtains metrics relating to current load and creates and pushes object with
* metric name and value to the healthDataCollection array
*/
si.currentLoad()
await si.currentLoad()
.then(data => {
const siMethodName = 'currentLoad';
for (let metricName in collectedMetrics[siMethodName]) {
Expand All @@ -152,7 +155,7 @@ healthHelpers.collectHealthData = () => {
* obtains metrics relating to memory and creates and pushes object with
* metric name and value to the healthDataCollection array
*/
si.mem()
await si.mem()
.then(data => {
const siMethodName = 'mem';
for (let metricName in collectedMetrics[siMethodName]) {
Expand All @@ -173,7 +176,7 @@ healthHelpers.collectHealthData = () => {
/** obtains metrics relating to current processes and creates and pushes object with
* metric name and value to the healthDataCollection array
*/
si.processes()
await si.processes()
.then(data => {
const siMethodName = 'processes';
for (let metricName in collectedMetrics[siMethodName]) {
Expand All @@ -194,7 +197,7 @@ healthHelpers.collectHealthData = () => {
/** obtains latency and creates and pushes object with
* metric name and value to the healthDataCollection array
*/
si.inetLatency()
await si.inetLatency()
.then(data => {
const siMethodName = 'inetLatency';
healthDataCollection.push({
Expand All @@ -203,6 +206,7 @@ healthHelpers.collectHealthData = () => {
category: 'Latency',
time,
});

})
.catch(err => {
if (err) {
Expand All @@ -213,11 +217,13 @@ healthHelpers.collectHealthData = () => {
/** Return a promise that resolves to an array of all of the data points
* and removes any empty strings, NaN, or "NaN" from values prevent database errors
*/
return Promise.all(healthDataCollection).then(array =>
array.filter(metric => {
if (isNaN(metric.value) || metric.value === 'NaN' || metric.value === '') return false;
return Promise.all(healthDataCollection).then(array => {
// console.log("PROMISE ARRAY",array)
return array.filter(metric => {
if (isNaN(metric.value) || metric.value === 'NaN' || metric.value === '' || metric.value === null) return false;
else return true;
})
}
);
};

Expand Down
Loading