Skip to content

Commit e7f2488

Browse files
committed
Added docker stats chart & applied minimal styling.
1 parent 47c6edf commit e7f2488

4 files changed

Lines changed: 98 additions & 1 deletion

File tree

app/charts/docker-stats-chart.jsx

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

user/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"setupRequired":false,"services":[["Test","MongoDB","mongodb+srv://alon:testing123@cluster0-phsei.mongodb.net/test?retryWrites=true&w=majority"]],"splash":false}
1+
{"setupRequired":false,"services":[["docker-mongo","MongoDB","mongodb+srv://alon:testing123@cluster0-phsei.mongodb.net/test?retryWrites=true&w=majority"]],"splash":false}

0 commit comments

Comments
 (0)