Skip to content

Commit

Permalink
Merge pull request #1237 from AllenBW/BZ/MASTER/#1512721-util-chart-r…
Browse files Browse the repository at this point in the history
…efresh

BZ#1512721-Use correct storage attribute, use metrics from last hour (not present)
  • Loading branch information
chriskacerguis authored Nov 14, 2017
2 parents 92c59af + 4fc9a01 commit ea753f3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
24 changes: 12 additions & 12 deletions client/app/services/resource-details/resource-details.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function ComponentController ($state, $stateParams, VmsService, lodash, EventNot
capture_interval: 'hourly'
}).then((response) => {
vm.metrics = response
const lastHour = response.resources[0]
const lastHour = response.resources[1]

vm.cpuUtil = UsageGraphsService.getChartConfig({
'units': __('%'),
Expand All @@ -216,7 +216,7 @@ function ComponentController ($state, $stateParams, VmsService, lodash, EventNot
'units': __('GB'),
'chartId': 'storageChart',
'label': __('used')
}, UsageGraphsService.convertBytestoGb(lastHour.derived_vm_allocated_disk_storage), UsageGraphsService.convertBytestoGb(lastHour.derived_vm_allocated_disk_storage))
}, UsageGraphsService.convertBytestoGb(lastHour.derived_vm_used_disk_storage), UsageGraphsService.convertBytestoGb(lastHour.derived_vm_allocated_disk_storage))
})

vm.diskUsage = response.disks.map((item) => {
Expand Down Expand Up @@ -449,13 +449,13 @@ function ComponentController ($state, $stateParams, VmsService, lodash, EventNot
const fontSize = 12 // in pixels
const tooltipWidth = 9 // in rem
const tooltip = d3
.select('body')
.append('div')
.attr('class', 'popover fade bottom in')
.attr('role', 'tooltip')
.on('mouseleave', () => {
d3.select('body').selectAll('.popover').remove()
})
.select('body')
.append('div')
.attr('class', 'popover fade bottom in')
.attr('role', 'tooltip')
.on('mouseleave', () => {
d3.select('body').selectAll('.popover').remove()
})
const rightOrLeftLimit = fontSize * tooltipWidth
const direction = d3.event.pageX > rightOrLeftLimit ? 'right' : 'left'
const left = direction === 'right' ? d3.event.pageX - rightOrLeftLimit : d3.event.pageX
Expand Down Expand Up @@ -487,8 +487,8 @@ function ComponentController ($state, $stateParams, VmsService, lodash, EventNot
`
)
tooltip
.style('left', `${left}px`)
.style('top', `${d3.event.pageY + 8}px`)
.style('display', 'block')
.style('left', `${left}px`)
.style('top', `${d3.event.pageY + 8}px`)
.style('display', 'block')
}
}
33 changes: 16 additions & 17 deletions client/app/services/usage-graphs/usage-graphs.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,30 @@ export const UsageGraphsComponent = {
/** @ngInject */
function ComponentController () {
const vm = this
vm.$onChanges = activate

function activate () {
vm.$onChanges = () => {
angular.extend(vm, {
cpuChart: vm.cpuChart || {data: {total: 0}},
memoryChart: vm.memoryChart || {data: {total: 0}},
storageChart: vm.storageChart || {data: {total: 0}},
cpuDataExists: true,
memoryDataExists: true,
storageDataExists: true,
emptyState: {icon: 'pficon pficon-help', title: 'No Information Available'}

cpuDataExists: false,
memoryDataExists: false,
storageDataExists: false,
emptyState: {icon: 'pficon pficon-help', title: __('No Information Available')}
})

if (vm.cpuChart.data.total === 0) {
vm.cpuDataExists = false
if (vm.cpuChart.data.total > 0) {
vm.cpuDataExists = true
vm.availableCPU = vm.cpuChart.data.total - vm.cpuChart.data.used
}
if (vm.memoryChart.data.total === 0) {
vm.memoryDataExists = false

if (vm.memoryChart.data.total > 0) {
vm.memoryDataExists = true
vm.availableMemory = vm.memoryChart.data.total - vm.memoryChart.data.used
}
if (vm.storageChart.data.total === 0) {
vm.storageDataExists = false

if (vm.storageChart.data.total > 0) {
vm.storageDataExists = true
vm.availableStorage = vm.storageChart.data.total - vm.storageChart.data.used
}
vm.availableCPU = vm.cpuChart.data.total - vm.cpuChart.data.used
vm.availableMemory = vm.memoryChart.data.total - vm.memoryChart.data.used
vm.availableStorage = vm.storageChart.data.total - vm.storageChart.data.used
}
}
2 changes: 1 addition & 1 deletion client/app/services/usage-graphs/usage-graphs.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function UsageGraphsFactory () {
}

function convertBytestoGb (bytes) {
return (bytes / 1073741824).toFixed(2)
return Number((bytes / 1073741824).toFixed(2))
}

return service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ describe('Service: UsageGraphsFactory', () => {
})
it('should convert bytes to gb', () => {
const gb = service.convertBytestoGb(1073741824)
expect(gb).to.eq('1.00')
expect(gb).to.eq(1.00)
})
})

0 comments on commit ea753f3

Please sign in to comment.