Skip to content

Commit

Permalink
Change to 2 digit accuracy in projects dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Zellner committed Nov 19, 2017
1 parent e58e826 commit e3cbf4f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/services/container_dashboard_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ContainerDashboardService
include UiServiceMixin
include ContainerServiceMixin

DISPLAY_PRECISION = 2 # 2 decimal points

def initialize(provider_id, controller)
@provider_id = provider_id
Expand Down Expand Up @@ -185,15 +186,15 @@ def heatmaps_data(metrics)
:node => m.resource.name,
:provider => provider_name,
:total => m.derived_vm_numvcpus.present? ? m.derived_vm_numvcpus.round : nil,
:percent => m.cpu_usage_rate_average.present? ? (m.cpu_usage_rate_average / 100.0).round(CPU_USAGE_PRECISION) : nil # pf accepts fractions 90% = 0.90
:percent => m.cpu_usage_rate_average.present? ? (m.cpu_usage_rate_average / 100.0).round(GRAPH_USAGE_PRECISION) : nil # pf accepts fractions 90% = 0.90
}

node_memory_usage << {
:id => m.resource.id,
:node => m.resource.name,
:provider => m.resource.ext_management_system.name,
:total => m.derived_memory_available.present? ? m.derived_memory_available.round : nil,
:percent => m.mem_usage_absolute_average.present? ? (m.mem_usage_absolute_average / 100.0).round(CPU_USAGE_PRECISION) : nil # pf accepts fractions 90% = 0.90
:percent => m.mem_usage_absolute_average.present? ? (m.mem_usage_absolute_average / 100.0).round(GRAPH_USAGE_PRECISION) : nil # pf accepts fractions 90% = 0.90
}
end

Expand Down
3 changes: 2 additions & 1 deletion app/services/container_project_dashboard_service.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ContainerProjectDashboardService
include UiServiceMixin
include ContainerServiceMixin
CPU_USAGE_PRECISION = 2 # 2 decimal points

DISPLAY_PRECISION = 2 # 2 decimal points

def initialize(project_id, controller)
@project_id = project_id
Expand Down
13 changes: 7 additions & 6 deletions app/services/container_service_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ContainerServiceMixin
CPU_USAGE_PRECISION = 2 # 2 decimal points
GRAPH_USAGE_PRECISION = 2 # 2 decimal points
DISPLAY_PRECISION = 0 # 2 decimal points
REALTIME_TIME_RANGE = 10 # 10 minutes

def daily_pod_metrics
Expand Down Expand Up @@ -63,16 +64,16 @@ def utilization_data(used_cpu, total_cpu, used_mem, total_mem)
if used_cpu.any?
{
:cpu => {
:used => (used_cpu.values.last || 0).round,
:used => (used_cpu.values.last || 0).round(DISPLAY_PRECISION),
:total => (total_cpu.values.last || 0).round,
:xData => used_cpu.keys,
:yData => used_cpu.values.map(&:round)
:yData => used_cpu.values.map { |m| m.round(GRAPH_USAGE_PRECISION) }
},
:mem => {
:used => ((used_mem.values.last || 0) / 1024.0).round,
:total => ((total_mem.values.last || 0) / 1024.0).round,
:used => ((used_mem.values.last || 0) / 1024.0).round(DISPLAY_PRECISION),
:total => ((total_mem.values.last || 0) / 1024.0).round(DISPLAY_PRECISION),
:xData => used_mem.keys,
:yData => used_mem.values.map { |m| ((m || 0) / 1024.0).round }
:yData => used_mem.values.map { |m| ((m || 0) / 1024.0).round(GRAPH_USAGE_PRECISION) }
}
}
end
Expand Down
4 changes: 2 additions & 2 deletions spec/services/container_dashboard_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@
:used => 3,
:total => 3,
:xData => [current_date.strftime("%Y-%m-%d")],
:yData => [3]
:yData => [3.0]
},
:mem => {
:used => 2,
:total => 3,
:xData => [current_date.strftime("%Y-%m-%d")],
:yData => [2]
:yData => [1.5]
}
)
end
Expand Down

0 comments on commit e3cbf4f

Please sign in to comment.