hopefully fix server metrics refresh bug

This commit is contained in:
Matt Hill
2021-06-15 11:09:48 -06:00
committed by Aiden McClelland
parent decc17fce5
commit f364202ae9
3 changed files with 82 additions and 35 deletions

View File

@@ -43,16 +43,19 @@ export class ServerMetricsPage {
async getMetrics (): Promise<void> {
try {
const metrics = await this.apiService.getServerMetrics({ })
Object.keys(metrics).forEach(outerKey => {
if (!this.metrics[outerKey]) {
this.metrics[outerKey] = metrics[outerKey]
} else {
Object.entries(metrics[outerKey]).forEach(([key, value]) => {
this.metrics[outerKey][key] = value
})
}
})
this.metrics = await this.apiService.getServerMetrics({ })
// @TODO keeping code in case naive approach (above) has issues
// Object.keys(metrics).forEach(outerKey => {
// if (!this.metrics[outerKey]) {
// console.log('outer keys')
// this.metrics[outerKey] = metrics[outerKey]
// } else {
// Object.entries(metrics[outerKey]).forEach(([key, value]) => {
// this.metrics[outerKey][key] = value
// })
// }
// })
} catch (e) {
console.error(e)
this.error = e.message

View File

@@ -93,7 +93,7 @@ export class MockApiService extends ApiService {
async getServerMetrics (params: RR.GetServerMetricsReq): Promise<RR.GetServerMetricsRes> {
await pauseFor(2000)
return Mock.ServerMetrics
return Mock.getServerMetrics()
}
async updateServerRaw (params: RR.UpdateServerReq): Promise<RR.UpdateServerRes> {

View File

@@ -783,35 +783,79 @@ export module Mock {
},
]
export const ServerMetrics: RR.GetServerMetricsRes = {
'Group1': {
'Metric1': {
value: 22.2,
unit: 'mi/b',
export function getServerMetrics () {
return {
'Group1': {
'Metric1': {
value: Math.random(),
unit: 'mi/b',
},
'Metric2': {
value: Math.random(),
unit: '%',
},
'Metric3': {
value: 10.1,
unit: '%',
},
},
'Metric2': {
value: 50,
unit: '%',
'Group2': {
'Hmmmm1': {
value: 22.2,
unit: 'mi/b',
},
'Hmmmm2': {
value: 50,
unit: '%',
},
'Hmmmm3': {
value: 10.1,
unit: '%',
},
},
'Metric3': {
value: 10.1,
unit: '%',
'Group3': {
'Hmmmm1': {
value: Math.random(),
unit: 'mi/b',
},
'Hmmmm2': {
value: 50,
unit: '%',
},
'Hmmmm3': {
value: 10.1,
unit: '%',
},
},
},
'Group2': {
'Hmmmm1': {
value: 22.2,
unit: 'mi/b',
'Group4': {
'Hmmmm1': {
value: Math.random(),
unit: 'mi/b',
},
'Hmmmm2': {
value: 50,
unit: '%',
},
'Hmmmm3': {
value: 10.1,
unit: '%',
},
},
'Hmmmm2': {
value: 50,
unit: '%',
'Group5': {
'Hmmmm1': {
value: Math.random(),
unit: 'mi/b',
},
'Hmmmm2': {
value: 50,
unit: '%',
},
'Hmmmm3': {
value: 10.1,
unit: '%',
},
},
'Hmmmm3': {
value: 10.1,
unit: '%',
},
},
}
}
export const ServerLogs: RR.GetServerLogsRes = [