Skip to content

Commit 1632351

Browse files
committed
added traffic chart
1 parent 4f24fdf commit 1632351

File tree

6 files changed

+149
-15
lines changed

6 files changed

+149
-15
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import React, { useContext } from 'react';
2+
import { Bar } from 'react-chartjs-2';
3+
import CommunicationsContext from '../context/OverviewContext';
4+
5+
const MicroServiceTraffic = (props) => {
6+
const communicationsData = useContext(CommunicationsContext).overviewData;
7+
8+
//initialize an empty object resObj. This object will store the microservice names as values and its corresponding correlatingId or correlatingid as keys. The microservice names will be stored in array within the order it was to the database.
9+
const resObj = {};
10+
11+
if(communicationsData.length>0 && communicationsData[0]["_id"]){
12+
//Sort the communication array from latest to earliest document
13+
communicationsData.sort((a,b)=>{
14+
if(new Date(a.timeSent) > new Date(b.timeSent)) return 1;
15+
if(new Date(a.timeSent) < new Date(b.timeSent)) return -1;
16+
return 0;
17+
});
18+
19+
//Iterate over sorted communicationsData array from the end to the beginning
20+
for (let i = 0; i < communicationsData.length; i+=1) {
21+
//declare a constant element and initialize it as the object at index i of the communicationsData array
22+
const element = communicationsData[i];
23+
//Pushes the microservice name into the object
24+
if (resObj[element.correlatingId]) {
25+
resObj[element.correlatingId].push(element.currentMicroservice);
26+
}
27+
else resObj[element.correlatingId] = [element.currentMicroservice];
28+
}
29+
}
30+
31+
else {
32+
33+
for (let i = communicationsData.length-1; i >= 0; i--) {
34+
const element = communicationsData[i];
35+
if (resObj[element.correlatingid]) resObj[element.correlatingid].push(element.currentmicroservice);
36+
else resObj[element.correlatingid] = [element.currentmicroservice];
37+
// initializing the object with the first microservice
38+
};
39+
}
40+
41+
//use object values to destructure locations
42+
const tracePoints = Object.values(resObj);
43+
let position = communicationsData[0].correlatingid ? 0 : tracePoints.length-1;
44+
45+
// Declare Micro-server-count dictinary to capture the amount of times a particular server is hit
46+
const microServiceCountdictionary = {};
47+
48+
// iterate over Trace Points
49+
for (let i = 0; i < tracePoints[position].length; i+=1) {
50+
51+
// populate Micro-count dictionary
52+
if (!microServiceCountdictionary[tracePoints[position][i]]) {
53+
microServiceCountdictionary[tracePoints[position][i]] = 1;
54+
} else {
55+
microServiceCountdictionary[tracePoints[position][i]]+=1
56+
}
57+
};
58+
59+
// capture values of microServiceCountdictionary to use as data to populate chart object
60+
const serverPingCount = Object.values(microServiceCountdictionary);
61+
62+
63+
// Create chart object data to feed into bar component
64+
const myChart = {
65+
//spread dictionary keys inorder to properly label chart x axis
66+
labels: [...Object.keys(microServiceCountdictionary)],
67+
datasets: [
68+
{
69+
label: 'Times server Pinged',
70+
backgroundColor: 'rgba(241, 207, 70,1)',
71+
borderColor: 'rgba(0,0,0,1)',
72+
borderWidth: 1,
73+
data: [...serverPingCount, 0] // spread ping count array into data array to have chart populate the Y axis
74+
}
75+
]
76+
}
77+
78+
79+
// return div with Bar component and Trace Points data
80+
return (
81+
<div>
82+
<h1>THIS IS FROM MS TRAFFIC</h1>
83+
<Bar
84+
data={myChart}
85+
width={100}
86+
height={50}
87+
options={{
88+
title:{
89+
display:true,
90+
text:'Microservices Overview',
91+
fontSize:20
92+
},
93+
legend:{
94+
display:true,
95+
position:'right'
96+
}
97+
}}
98+
/>
99+
</div>
100+
)
101+
};
102+
103+
export default MicroServiceTraffic;
104+

app/charts/route-trace.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useContext } from 'react';
2+
import { Bar } from 'react-chartjs-2';
23
import CommunicationsContext from '../context/OverviewContext';
34

45
const RouteLocations = (props) => {
@@ -9,14 +10,11 @@ const RouteLocations = (props) => {
910

1011
if(communicationsData.length>0 && communicationsData[0]["_id"]){
1112
//Sort the communication array from latest to earliest document
12-
// communicationsData.sort((a,b)=>{ new Date(a.timeSent) - new Date(b.timeSent)})
1313
communicationsData.sort((a,b)=>{
1414
if(new Date(a.timeSent) > new Date(b.timeSent)) return 1;
1515
if(new Date(a.timeSent) < new Date(b.timeSent)) return -1;
1616
return 0;
1717
});
18-
19-
2018

2119
//Iterate over sorted communicationsData array from the end to the beginning
2220
for (let i = 0; i < communicationsData.length; i+=1) {
@@ -27,35 +25,40 @@ const RouteLocations = (props) => {
2725
resObj[element.correlatingId].push(element.currentMicroservice);
2826
}
2927
else resObj[element.correlatingId] = [element.currentMicroservice];
30-
// initializing the object with the first microservice
3128
}
3229
}
33-
else{
34-
for (let i = communicationsData.length-1; i >= 0; i--) {
30+
31+
else {
32+
33+
for (let i = communicationsData.length-1; i >= 0; i--) {
3534
const element = communicationsData[i];
3635
if (resObj[element.correlatingid]) resObj[element.correlatingid].push(element.currentmicroservice);
3736
else resObj[element.correlatingid] = [element.currentmicroservice];
3837
// initializing the object with the first microservice
39-
};
40-
}
38+
};
39+
}
4140

4241
//use object values to destructure locations
4342
const tracePoints = Object.values(resObj);
4443
let position = communicationsData[0].correlatingid ? 0 : tracePoints.length-1;
4544

4645
const resArray = [];
4746

47+
// iterate over Trace Points
4848
for (let i = 0; i < tracePoints[position].length; i+=1) {
49+
//push into resulting array current tracepoint as div
4950
resArray.push(
5051
<div className="RouteCircle" key={i}>
5152
<p id="routeText">Point {i+1}: {tracePoints[position][i]}</p>
5253
</div>
5354
)
5455
};
5556

57+
58+
// return div with Trace Points data
5659
return (
5760
<div>
58-
{resArray}
61+
{resArray}
5962
</div>
6063
)
6164
};

app/components/Modal.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TemperatureChart from '../charts/temperature-chart.jsx';
77
import LatencyChart from '../charts/latency-chart.jsx';
88
import MemoryChart from '../charts/memory-chart.jsx';
99
import RouteTrace from '../charts/route-trace.jsx';
10+
import MicroServiceTraffic from '../charts/microservice-traffic.jsx';
1011

1112
const Modal = (props) => {
1213
// Destructuring props to make linter happy
@@ -21,6 +22,7 @@ const Modal = (props) => {
2122
speed: <SpeedChart service={service} />,
2223
processes: <ProcessesChart service={service} />,
2324
latency: <LatencyChart service={service} />,
25+
traffic: <MicroServiceTraffic service={service} />,
2426
temperature: <TemperatureChart service={service} />,
2527
memory: <MemoryChart service={service} />,
2628
};

app/components/ServiceOverview.jsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,33 @@ const ServiceOverview = (props) => {
4040
// Hook used to set the Modal Component title. The "alt" attribute
4141
// is grabbed from the onClick event via event.path[0].alt
4242
const [chartTitle, setChartTitle] = useState();
43-
44-
const routeButtonProperty = { id: 'routes', alt: 'Route Trace', src: routeChart };
43+
44+
const routeButtonProperty = { traffic: {id: 'traffic', alt: 'Microservice Traffic', src: routeChart}, routes: {id: 'routes', alt: 'Route Trace', src: routeChart} };
45+
4546
const routes = [];
47+
const traffic = [];
48+
traffic.push (
49+
<div>
50+
<div className="healthChartContainer">
51+
<input
52+
onClick={() => {
53+
setChartTitle(event.path[0].alt);
54+
setModalChart(event.path[0].id);
55+
toggleModalDisplay(!modalDisplay);
56+
}}
57+
type="image"
58+
id={routeButtonProperty.traffic.id}
59+
src={routeButtonProperty.traffic.src}
60+
width="60px"
61+
alt={routeButtonProperty.traffic.alt}
62+
/>
63+
<br/>
64+
<div style={{color:'white', paddingLeft:'7px'}}>
65+
{routeButtonProperty.id}
66+
</div>
67+
</div>
68+
</div>
69+
);
4670
routes.push(
4771
<div>
4872
<div className="healthChartContainer">
@@ -53,10 +77,10 @@ const ServiceOverview = (props) => {
5377
toggleModalDisplay(!modalDisplay);
5478
}}
5579
type="image"
56-
id={routeButtonProperty.id}
57-
src={routeButtonProperty.src}
80+
id={routeButtonProperty.routes.id}
81+
src={routeButtonProperty.routes.src}
5882
width="60px"
59-
alt={routeButtonProperty.alt}
83+
alt={routeButtonProperty.routes.alt}
6084
/>
6185
<br/>
6286
<div style={{color:'white', paddingLeft:'7px'}}>
@@ -160,6 +184,7 @@ const ServiceOverview = (props) => {
160184
/>
161185
) : null}
162186
{routes}
187+
{traffic}
163188
</div>
164189
);
165190
};

user/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":true, "services":["hard","coded","in"]}
1+
{"setupRequired":false,"services":[["Ousman Microservice","SQL","\tpostgres://wcdnbpvl:[email protected]:5432/wcdnbpvl"],["MSlocation1 - Ousman","SQL","postgres://mnspuhgt:[email protected]:5432/mnspuhgt"]]}

0 commit comments

Comments
 (0)