Skip to content

Commit 78e9c3f

Browse files
timlee12RobertoRueMelonixueapptaylrzhang
committed
added ec2 graphs component, deleted npm packages
Co-authored-by: Roberto Meloni <[email protected]> Co-authored-by: Snow X. Bai <[email protected]> Co-authored-by: Taylor Zhang <[email protected]>
1 parent 5be705f commit 78e9c3f

File tree

96 files changed

+127
-23576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+127
-23576
lines changed

app/components/AwsEC2Graphs.tsx

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import React, { useContext, useEffect, useState } from 'react';
2+
import AwsChart from '../charts/AwsChart';
3+
import { AwsContext } from '../context/AwsContext';
4+
import { CircularProgress } from '@material-ui/core';
5+
import zIndex from '@material-ui/core/styles/zIndex';
6+
7+
const AwsEC2Graphs: React.FC = React.memo(props => {
8+
const { awsData, setAwsData } = useContext(AwsContext);
9+
const [isLoading, setLoadingState] = useState<boolean>(true);
10+
11+
useEffect(() => {
12+
console.log('is state loading? ', !!awsData);
13+
if(awsData) setLoadingState(false);
14+
}, []);
15+
16+
useEffect(() => {
17+
return () => {
18+
setAwsData({ CPUUtilization: [], NetworkIn: [], NetworkOut: [], DiskReadBytes: [] })
19+
}
20+
}, [])
21+
22+
const stringToColor = (string: string, recurses = 0) => {
23+
if (recurses > 20) return string;
24+
function hashString(str: string) {
25+
let hash = 0;
26+
for (let i = 0; i < str.length; i++) {
27+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
28+
}
29+
let colour = '#';
30+
for (let i = 0; i < 3; i++) {
31+
const value = (hash >> (i * 8)) & 0xff;
32+
colour += `00${value.toString(16)}`.substring(-2);
33+
}
34+
35+
console.log(colour);
36+
return colour;
37+
}
38+
};
39+
40+
return (
41+
<div className="charts">
42+
{isLoading &&
43+
<div style={{ display: 'flex', width: 100, height:100, justifyContent: 'center', position: 'absolute', alignItems: 'center', zIndex: 50}}>
44+
<CircularProgress />
45+
</div>
46+
}
47+
{Object.keys(awsData)?.map(metric => {
48+
return (
49+
<AwsChart
50+
className='chart'
51+
// key={`Chart${counter}`}
52+
renderService={metric}
53+
metric={awsData[metric][0]?.unit}
54+
timeList={awsData[metric]?.map(el => el.time)}
55+
valueList={awsData[metric]?.map(el => el.value)}
56+
// sizing={props.sizing}
57+
colourGenerator={stringToColor}
58+
/>
59+
)
60+
})}
61+
{/* <AwsChart
62+
className='chart'
63+
// key={`Chart${counter}`}
64+
renderService="CPU Utilization"
65+
metric="Percent"
66+
timeList={awsData.CPUUtilization?.map(el => el.time)}
67+
valueList={awsData.CPUUtilization?.map(el => el.value)}
68+
// sizing={props.sizing}
69+
colourGenerator={stringToColor}
70+
/>
71+
<AwsChart
72+
className='chart'
73+
// key={`Chart${counter}`}
74+
renderService="Network In"
75+
metric="Percent"
76+
timeList={awsData.NetworkIn?.map(el => el.time)}
77+
valueList={awsData.NetworkIn?.map(el => el.value)}
78+
// sizing={props.sizing}
79+
colourGenerator={stringToColor}
80+
/>
81+
<AwsChart
82+
className='chart'
83+
// key={`Chart${counter}`}
84+
renderService="Network Out"
85+
metric="Percent"
86+
timeList={awsData.NetworkOut?.map(el => el.time)}
87+
valueList={awsData.NetworkOut?.map(el => el.value)}
88+
// sizing={props.sizing}
89+
colourGenerator={stringToColor}
90+
/>
91+
<AwsChart
92+
className='chart'
93+
// key={`Chart${counter}`}
94+
renderService="DiskReadBytes"
95+
metric="Percent"
96+
timeList={awsData.DiskReadBytes?.map(el => el.time)}
97+
valueList={awsData.DiskReadBytes?.map(el => el.value)}
98+
// sizing={props.sizing}
99+
colourGenerator={stringToColor}
100+
/> */}
101+
</div>
102+
)
103+
});
104+
105+
export default AwsEC2Graphs;

app/components/ClusterTable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useContext, useState } from 'react';
22
import {
33
Table,
44
TableBody,
@@ -41,6 +41,7 @@ export interface ClusterTableProps {
4141

4242
const ClusterTable: React.FC<ClusterTableProps> = React.memo(({ region }) => {
4343
const classes = useStyles();
44+
const { awsEcsData } = useContext(AwsContext);
4445
// const {clusterName, servicesNum, tasksNum, status} = useContext(DashboardContext);
4546

4647
return (
@@ -58,7 +59,7 @@ const ClusterTable: React.FC<ClusterTableProps> = React.memo(({ region }) => {
5859
<TableBody>
5960
<TableCell className={classes.body}>
6061
<div className={classes.column}>
61-
<div>test</div>
62+
<div>{awsEcsData ? awsEcsData.clusterInfo?.clusterName : 'Loading...'}</div>
6263
<div>
6364
<span className="region">{region}</span>
6465
</div>

app/components/Occupied.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ interface StyleProps {
5757
type ClickEvent = React.MouseEvent<HTMLElement>;
5858

5959
const Occupied = React.memo(() => {
60-
const { awsData, fetchAwsData } = useContext(AwsContext);
60+
const { awsData, fetchAwsData, fetchAwsAppInfo } = useContext(AwsContext);
6161
const { setServicesData, app, setApp } = useContext(ApplicationContext);
6262
const { user, applications, getApplications, deleteApp, mode } = useContext(DashboardContext);
6363
const { commsData } = useContext(CommsContext);
@@ -103,7 +103,8 @@ const Occupied = React.memo(() => {
103103
if (selectedService === 'AWS' || selectedService === 'AWS/EC2' || selectedService === 'AWS/ECS') {
104104
setAppIndex(i);
105105
setApp(selectedApp);
106-
navigate(`/aws/:${app}`);
106+
console.log('the selected AWS service is: ', selectedService)
107+
navigate(`/aws/:${app}`, { state: { typeOfService: selectedService }});
107108
} else {
108109
setAppIndex(i);
109110
setApp(selectedApp);

app/context/AwsContext.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ interface Props {
1010
children: any;
1111
}
1212

13+
interface AwsData {
14+
CPUUtilization: [],
15+
NetworkIn: [],
16+
NetworkOut: [],
17+
DiskReadBytes: []
18+
}
19+
20+
interface AwsAppInfo {
21+
typeOfService: string,
22+
region: string
23+
}
24+
1325
const AwsContextProvider: React.FC<Props> = React.memo(({ children }) => {
14-
const [awsData, setAwsData] = useState<any>({ CPUUtilization: [], NetworkIn: [], NetworkOut: [], DiskReadBytes: [] })
15-
const [awsEcsData, setAwsEcsData] = useState<any>({ CPUUtilization: [], MemoryUtilization: [] });
16-
const [awsAppInfo, setAwsAppInfo] = useState<any>({ typeOfService: '', region: '' });
26+
const [awsData, setAwsData] = useState<AwsData>({ CPUUtilization: [], NetworkIn: [], NetworkOut: [], DiskReadBytes: [] })
27+
const [awsEcsData, setAwsEcsData] = useState<any>({});
28+
const [awsAppInfo, setAwsAppInfo] = useState<AwsAppInfo>({ typeOfService: '', region: '' });
1729

1830
const fetchAwsData = (username: string, index: number) => {
1931
ipcRenderer.removeAllListeners('ec2MetricsResponse');
@@ -53,7 +65,7 @@ const AwsContextProvider: React.FC<Props> = React.memo(({ children }) => {
5365

5466
return (
5567
<AwsContext.Provider
56-
value={{ fetchAwsData, awsData, setAwsData, fetchAwsEcsData, awsEcsData, setAwsEcsData, awsAppInfo, fetchAwsAppInfo}}
68+
value={{ fetchAwsData, awsData, setAwsData, fetchAwsEcsData, awsEcsData, setAwsEcsData, awsAppInfo, setAwsAppInfo, fetchAwsAppInfo}}
5769
>
5870
{children}
5971
</AwsContext.Provider>

examples/docker/books/chronos_npm_package/.npmignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)