Skip to content

Commit 8b58d65

Browse files
authored
Merge pull request #16 from ajlee12/master
Combining docker-stats feature into latest UI revamp (before presentation)
2 parents b40dce7 + 7d46770 commit 8b58d65

8 files changed

Lines changed: 432 additions & 3001 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
package-lock.json
44
.DS_Store
55
user/settings.json
6+
dist

app/charts/docker-stats-chart.jsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { useContext } from 'react';
2+
import HealthContext from '../context/DetailsContext';
3+
// import Plot from 'react-plotly.js';
4+
5+
// A table that displays real-time Docker container stats.
6+
// Just need to pull data from most recent (last) obj in healthData.
7+
const DockerStatsChart = (props) => {
8+
let length = useContext(HealthContext).detailData.length;
9+
// const healthData = useContext(HealthContext).detailData[length - 1]; // <== only used if only getting the last data pt.
10+
const healthData = useContext(HealthContext).detailData;
11+
12+
// console.log('healthData (in docker-stats-chart):', healthData);
13+
14+
// Declare a dockerStats obj to store extracted Docker stats.
15+
let dockerStats = {};
16+
17+
// Scan from the end of the data collection in heathData. (End = most recent)
18+
// Break the loop as soon as we find a data pt that matches current srvc (props.service).
19+
// We are only extracting this most recent data pt.
20+
for (let i = length - 1; i >= 0; i -= 1) {
21+
// The difference btw MongoDB and pSQL is whether a stat title is camelCased (mongo = yes, psql = no).
22+
// If user-chosen DB is MongoDB:
23+
if (healthData[i].currentMicroservice === props.service) {
24+
// Extract Docker-related data (MongoDB) and save to dockerStats obj.
25+
dockerStats = {
26+
'Containerized service': healthData[i].currentMicroservice,
27+
'Container ID': healthData[i].containerId.slice(0, 7) + '[...]',
28+
'CPU usage %': parseFloat(healthData[i].containerCpuPercent).toFixed(2) + '%',
29+
'Mem usage %': parseFloat(healthData[i].containerMemPercent).toFixed(2) + '%',
30+
'Mem limit (Mb)': parseFloat(healthData[i].containerMemLimit / 1000000).toFixed(2),
31+
'Mem usage (Mb)': parseFloat(healthData[i].containerMemUsage / 1000000).toFixed(2),
32+
'Network I/O - Received (Kb)': parseFloat(healthData[i].networkReceived / 1000).toFixed(2),
33+
'Network I/O - Sent (Kb)': parseFloat(healthData[i].networkSent / 1000).toFixed(2),
34+
'Process count': healthData[i].containerProcessCount,
35+
'Restart count': healthData[i].containerRestartCount,
36+
};
37+
break;
38+
}
39+
40+
// If postgreSQL:
41+
if (healthData[i].currentmicroservice === props.service) {
42+
dockerStats = {
43+
'Containerized service': healthData[i].currentmicroservice,
44+
'Container ID': healthData[i].containerid.slice(0, 7) + '[...]',
45+
'CPU usage %': parseFloat(healthData[i].containercpupercent).toFixed(2) + '%',
46+
'Mem usage %': parseFloat(healthData[i].containermempercent).toFixed(2) + '%',
47+
'Mem limit (Mb)': parseFloat(healthData[i].containermemlimit / 1000000).toFixed(2),
48+
'Mem usage (Mb)': parseFloat(healthData[i].containermemusage / 1000000).toFixed(2),
49+
'Network I/O - Received (Kb)': parseFloat(healthData[i].networkreceived / 1000).toFixed(2),
50+
'Network I/O - Sent (Kb)': parseFloat(healthData[i].networksent / 1000).toFixed(2),
51+
'Process count': healthData[i].containerprocesscount,
52+
'Restart count': healthData[i].containerrestartcount,
53+
};
54+
break;
55+
}
56+
}
57+
58+
59+
// Build an array of <span>s that'll be rendered. Each <span> contains one stat.
60+
const dockerStatsArr = [];
61+
62+
for (let stat in dockerStats) {
63+
dockerStatsArr.push(
64+
<span key={stat}>
65+
{stat}: {dockerStats[stat]}
66+
</span>
67+
)
68+
}
69+
70+
return (
71+
<div id="docker-stats-chart">
72+
<header id="docker-stats-chart-header">Docker Container Stats</header>
73+
{dockerStatsArr}
74+
</div>
75+
)
76+
}
77+
78+
export default DockerStatsChart;

app/containers/GraphsContainer.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import MemoryChart from '../charts/memory-chart.jsx';
99
import RouteTrace from '../charts/route-trace.jsx';
1010
// import RouteLocations from '../charts/route-copy.jsx';
1111
import MicroServiceTraffic from '../charts/microservice-traffic.jsx';
12+
import DockerStatsChart from '../charts/docker-stats-chart.jsx';
1213
import '../stylesheets/graphs.css';
1314

1415
let vis;
@@ -70,6 +71,7 @@ const GraphsContainer = (props) => {
7071
<LatencyChart service={service} />
7172
<MicroServiceTraffic service={service} />
7273
<MemoryChart service={service} />
74+
<DockerStatsChart service={service}/>
7375
</div>
7476
);
7577
};

app/stylesheets/graphs.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,21 @@ svg {
1010
border-radius: 2px;
1111
box-shadow: 2px 2px 2px rgba(216, 210, 247, .5);
1212
}
13+
14+
#docker-stats-chart {
15+
position: relative;
16+
font-family: "Open Sans", verdana, arial, sans-serif;
17+
display: flex;
18+
flex-direction: column;
19+
background-color: white;
20+
border-radius: 2px;
21+
box-shadow: 2px 2px 2px rgba(216, 210, 247, .5);
22+
height: 400;
23+
width: 400;
24+
padding: 10px 10px 10px 10px;
25+
}
26+
27+
#docker-stats-chart-header {
28+
align-self: center;
29+
font-size: 1.5em;
30+
}

dist/index_bundle.js

Lines changed: 269 additions & 2877 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)