Skip to content

Commit dd67cef

Browse files
Eisha KaushalEisha Kaushal
authored andcommitted
frontend docker metric processing
1 parent c96e682 commit dd67cef

File tree

4 files changed

+55
-86
lines changed

4 files changed

+55
-86
lines changed

app/context/helpers.ts

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,49 @@ interface HealthDataObject {
3636
[key: string]: MetricObject[]
3737
}
3838

39-
// Transforms health data into a nested object based on service name
4039
export function healthTransformer(healthData: HealthDataObject[]) {
4140
// make an object for storing different services' metrics data
42-
const serviceMetricsObject = {}; //books:..., customers:..., orders:..., frontend:...
41+
const serviceMetricsObject = {};
4342
// loop through the services in the healthData array
44-
healthData.forEach(serviceObj => { //books
43+
healthData.forEach(serviceObj => {
4544
// grab the key string from the current service object
46-
const serviceName = Object.keys(serviceObj)[0]; //books-containerinfos
47-
// add the serviceName as a key on the serviceMetricsObject and assign it an empty object
48-
serviceMetricsObject[serviceName] = {}; //add key service Name to object
49-
const serviceElements = serviceObj[serviceName]; //array of metric objects IN heatlhdataObj @ serviceName
45+
const serviceName = Object.keys(serviceObj)[0];
46+
const serviceElements = serviceObj[serviceName];
5047
console.log('serviceElements: ', serviceElements);
48+
// add the serviceName as a key on the serviceMetricsObject and assign it an empty object
49+
serviceMetricsObject[serviceName] = {};
5150
// loop through the elements of the current service
52-
serviceElements.forEach((dataObject: any) => { //--v12 --make it an object typscript?
53-
console.log('raw dataOBJ LN 53', dataObject);
54-
// !containerName exist, generate a key for that object that matches the category value of the current dataObject
55-
let containerName = dataObject.containername;
56-
if (!serviceMetricsObject[serviceName][containerName]) {
57-
serviceMetricsObject[serviceName][containerName] = {};
58-
console.log('line 58 if category ', [containerName])
51+
serviceElements.forEach(dataObject => {
52+
// if it doesn't exist, generate a key for that object that matches the category value of the current dataObject
53+
if (!serviceMetricsObject[serviceName][dataObject.category]) {
54+
serviceMetricsObject[serviceName][dataObject.category] = {};
5955
}
60-
61-
for (let metric in dataObject) { //loop the data object for metric names and values
62-
// in containerName nested object, assign a key using the current dataObject's metric value and assign its value an empty object
63-
if (!serviceMetricsObject[serviceName][containerName][metric]) {
64-
serviceMetricsObject[serviceName][containerName][metric] = {};
65-
console.log('line 60 if metric ', metric)
66-
}
67-
// if the 'value' key doesn't exist in the previous object assign a key of 'value' with the value of an array that includes the value of value
68-
if (!serviceMetricsObject[serviceName][containerName][metric].value) {
69-
serviceMetricsObject[serviceName][containerName][metric].value = [dataObject[metric]];
70-
console.log('line 65 if value ', dataObject[metric])
71-
} else { // if it does exist, push the value of the current dataObject's time key onto the array
72-
serviceMetricsObject[serviceName][containerName][metric].value.push(
73-
dataObject[metric]
74-
);
75-
console.log('line 68 else value ', dataObject[metric])
76-
}
77-
// in that same object, if the key 'time' doesn't exist yet, assign a key of 'time' with the value as an array that includes the time value
78-
if (!serviceMetricsObject[serviceName][containerName][metric].time) {
79-
serviceMetricsObject[serviceName][containerName][metric].time = [dataObject.time];
80-
console.log('line 75 if time ', [dataObject.time])
81-
} else { // if it does exist aready, push the current time value into the time array
82-
serviceMetricsObject[serviceName][containerName][metric].time.push(
83-
dataObject.time
84-
);
85-
console.log('line 78 else time ', [dataObject.time])
86-
}
87-
console.log('serviceMetricsOBJ LN83: ', serviceMetricsObject)
56+
// in that nested object, assign a key using the current dataObject's metric value and assign its value an empty object
57+
if (!serviceMetricsObject[serviceName][dataObject.category][dataObject.metric]) {
58+
serviceMetricsObject[serviceName][dataObject.category][dataObject.metric] = {};
59+
}
60+
// if the 'value' key doesn't exist in the previous object assign a key of 'value' with the value of an array that includes the value of value
61+
if (!serviceMetricsObject[serviceName][dataObject.category][dataObject.metric].value) {
62+
serviceMetricsObject[serviceName][dataObject.category][dataObject.metric].value = [dataObject.value];
63+
} else { // if it does exist, push the value of the current dataObject's time key onto the array
64+
serviceMetricsObject[serviceName][dataObject.category][dataObject.metric].value.push(
65+
dataObject.value
66+
);
67+
}
68+
// in that same object, if the key 'time' doesn't exist yet, assign a key of 'time' with the value as an array that includes the time value
69+
if (!serviceMetricsObject[serviceName][dataObject.category][dataObject.metric].time) {
70+
serviceMetricsObject[serviceName][dataObject.category][dataObject.metric].time = [dataObject.time];
71+
} else { // if it does exist aready, push the current time value into the time array
72+
serviceMetricsObject[serviceName][dataObject.category][dataObject.metric].time.push(
73+
dataObject.time
74+
);
8875
}
8976
});
9077
})
9178
return serviceMetricsObject;
9279
};
9380

81+
9482
export function eventTransformer(eventData: MetricObject[]) {
9583
// make an object for storing the metrics data
9684
const eventMetricsObject = {};

app/modals/EnvModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const EnvModal: React.FC<EnvModalProps> = React.memo(
2727
<Typography>Cloud-Based</Typography>
2828
</button>
2929
<button
30-
className="env-button"
30+
className="env-button2"
3131
onClick={() => {
3232
setOpen(false);
3333
setAddModalOpen(true);

app/stylesheets/EnvModal.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
}
2020
}
2121

22+
.env-button2 {
23+
background-color: transparent;
24+
border: 0;
25+
outline: none;
26+
white-space: nowrap;
27+
margin: 10px;
28+
// padding: 0px;
29+
color: $gblue !important;
30+
box-shadow: $boxshadow;
31+
padding: 2rem;
32+
&:hover {
33+
background-color: $lightpurple;
34+
}
35+
}
36+
2237
p {
2338
padding: 0 !important;
2439
}

electron/models/DockerModel.ts

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,23 @@ import mongoose from 'mongoose';
33
const { Schema } = mongoose;
44

55
const DockerSchema = new Schema({
6-
containername: {
7-
type: String,
8-
required: true,
9-
},
10-
containerid: {
11-
type: String,
12-
required: true,
13-
},
14-
platform: {
15-
type: String,
16-
required: true,
6+
time: {
7+
type: Date,
8+
default: Date.now(),
179
},
18-
starttime: {
10+
metric: {
1911
type: String,
20-
required: true,
2112
},
22-
memoryusage: {
13+
value: {
2314
type: Number,
24-
required: true,
2515
},
26-
memorylimit: {
27-
type: Number,
28-
required: true,
29-
},
30-
memorypercent: {
31-
type: Number,
32-
required: true,
33-
},
34-
cpupercent: {
35-
type: Number,
36-
required: true,
37-
},
38-
networkreceived: {
39-
type: Number,
40-
required: true,
41-
},
42-
networksent: {
43-
type: Number,
44-
required: true,
45-
},
46-
processcount: {
47-
type: Number,
48-
required: true,
49-
},
50-
restartcount: {
51-
type: Number,
52-
required: true,
16+
category: {
17+
type: String,
18+
default: '',
5319
},
5420
});
5521

5622
const DockerModelFunc = (serviceName: any) =>
5723
mongoose.model<any>(`${serviceName}`, DockerSchema);
5824

59-
export default DockerModelFunc;
25+
export default DockerModelFunc;

0 commit comments

Comments
 (0)