Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes node order on all components #27

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Edits node order for CPU & Disk
  • Loading branch information
ronke11 committed Aug 26, 2021
commit 1807935cf0b1d18d1c3caebee7dff5bb86b33aed
9 changes: 8 additions & 1 deletion dashboard/client/components/CPU.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ const CPU = (props) => {
const [render, setRender] = useState(false);
if (props.cpu.data) {
const nodes = props.cpu.data.result;
const nodeNums = props.nodeNums;
nodes[0].values.forEach((x, i) => {
const dataPoint = {};
let current = new Date(x[0] * 1000);
dataPoint.time = current.toLocaleString();

for (let j = 0; j < nodes.length; j++) {
dataPoint[`node${j + 1}`] = (parseFloat(nodes[j].values[i][1])*100).toFixed(
// match length of instance to length of ip addresses in node list
const len = nodeNums[0].length;
const internal_ip = nodes[j].metric.instance.slice(0, len);
// find position of node in reference list
const position = nodeNums.findIndex((ip) => ip === internal_ip);
dataPoint[`node${position + 1}`] = (parseFloat(nodes[j].values[i][1])*100).toFixed(
2);
}
resultArr.push(dataPoint);
Expand Down
4 changes: 2 additions & 2 deletions dashboard/client/components/ClusterInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ClusterInfo = ({ clusterInfo }) => {

// component for each node
const nodes = [];
console.log('nodes', nodes);
// console.log('nodes', nodes);
for (let i = 0; i < clusterInfoArr.length; i++) {
const nodeName = clusterInfoArr[i].metric.node;
const nodeNumber = 'node' + (i + 1);
Expand All @@ -29,7 +29,7 @@ const ClusterInfo = ({ clusterInfo }) => {
// />
// );
}
console.log('nodes', nodes);
// console.log('nodes', nodes);

// const data = React.useMemo(() => {
// nodes;
Expand Down
28 changes: 21 additions & 7 deletions dashboard/client/components/DiskUsage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,55 @@ const DiskUsage = (props) => {
if (props.free.data) {
const total = props.total.data?.result;
const free = props.free.data?.result;
const nodes = props.total.data.result;
const nodes = {};
const nodeNums = props.nodeNums;
// loop through freediskspace and get the times

// loops through totalDiskSpace query and pushes the name of node and total diskspace of node into an object
for (let i = 0; i < total.length; i++) {
// push each node #: diskSpace
nodes[`node${i + 1}`] = total[i].value[1];

// match length of instance to length of ip addresses in node list
const len = nodeNums[0].length;
const internal_ip = total[i].metric.instance.slice(0, len);
// // find position of node in reference list
const position = nodeNums.findIndex((ip) => ip === internal_ip);

nodes[`node${position + 1}`] = total[i].value[1];
}

// loops through FreeDiskSpace and sends time and value @ time to new object
for (let i = 0; i < free.length; i++) {
const nodeNum = `node${i + 1}`;
const values = free[i].values;
//find correct nodeNum
// match length of instance to length of ip addresses in node list
const len = nodeNums[0].length;
const internal_ip = free[i].metric.instance.slice(0, len);
// // find position of node in reference list
const position = nodeNums.findIndex((ip) => ip === internal_ip);

// grab all the times from the first index of the array
if (i === 0) {
for (let j = 0; j < values.length; j++) {
// grab the time: values[j][0] and convert time to human readable format
const time = new Date(values[j][0] * 1000).toLocaleString();
data.push({ time: time });
}
}
// put the node # & it's value in each time object
for (let k = 0; k < data.length; k++) {
// (total size - value at each time) / total size
const totalDisk = nodes[nodeNum];
const totalDisk = nodes[`node${position + 1}`];
const freeDiskSpace = values[k][1];
data[k][nodeNum] = (((totalDisk - freeDiskSpace) / totalDisk)*100).toFixed(2);
data[k][`node${position + 1}`] = (((totalDisk - freeDiskSpace) / totalDisk)*100).toFixed(2);
}
}

if (render === false) {
setDiskUsage(data);
setRender(true);
}
for (let i = 0; i < nodes.length; i++) {

for (let i = 0; i < total.length; i++) {
lines.push(
<Line
type='monotone'
Expand Down
5 changes: 2 additions & 3 deletions dashboard/client/container/mainContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const mainContainer = () => {

if (!isLoading && !called) {
const result = [];
console.log(clusterInfo.data.result);
for (let i = 1; i <= clusterInfo.data.result.length; i++){
// create nodes 1 through x based on internal Ip addresses
result.push(clusterInfo.data.result[i - 1].metric.internal_ip);
Expand All @@ -45,13 +44,13 @@ const mainContainer = () => {
:
<div className='main-container'>
<div id='CPU' className='components'>
<CPU cpu={cpu} />
<CPU cpu={cpu} nodeNums={nodeNums}/>
</div>
<div className='components' id='Memory'>
<Memory nodeMemory={nodeMemory} nodeNums={nodeNums} />
</div>
<div id='disk-usage' className='components'>
<DiskUsage total={totalDisk} free={freeDisk} />
<DiskUsage total={totalDisk} free={freeDisk} nodeNums={nodeNums} />
</div>
<div id='logs' className='components'>
<ClusterInfo clusterInfo={clusterInfo} />
Expand Down