Skip to content

Commit

Permalink
Merge pull request #22606 from kbrock/vim_performance_state_time_inte…
Browse files Browse the repository at this point in the history
…rval

Vim performance state time interval
  • Loading branch information
Fryguy authored Aug 1, 2023
2 parents f71fa63 + cd86162 commit c6bfffb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
9 changes: 0 additions & 9 deletions app/models/metric/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,6 @@ def self.time_range_from_offset(interval_name, start_offset, end_offset, tz = ni
start_time..end_time
end

def self.get_time_interval(obj, timestamp)
timestamp = Time.parse(timestamp).utc if timestamp.kind_of?(String)

state = obj.vim_performance_state_for_ts(timestamp)
start_time = timestamp - state[:capture_interval]

start_time..timestamp
end

def self.latest_metrics(resource_type, since_timestamp, resource_ids = nil)
metrics = Metric.where(:resource_type => resource_type)
metrics = metrics.where(:resource_id => resource_ids) if resource_ids
Expand Down
9 changes: 5 additions & 4 deletions app/models/metric/statistic.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module Metric::Statistic
# @param timestamp [String|Time] hourly timestamp used for hourly_rollups (prefer Time)
def self.calculate_stat_columns(obj, timestamp)
capture_interval = Metric::Helper.get_time_interval(obj, timestamp)
date_range = VimPerformanceState.get_time_interval(timestamp)
stats = {}

if obj.respond_to?(:all_container_groups)
container_groups = obj.all_container_groups # Get disconnected entities as well
stats[:stat_container_group_create_rate] = container_groups.where(:ems_created_on => capture_interval).count
stats[:stat_container_group_delete_rate] = container_groups.where(:deleted_on => capture_interval).count
stats[:stat_container_group_create_rate] = container_groups.where(:ems_created_on => date_range).count
stats[:stat_container_group_delete_rate] = container_groups.where(:deleted_on => date_range).count
end

if obj.respond_to?(:all_container_images)
stats[:stat_container_image_registration_rate] = obj.all_container_images.where(:registered_on => capture_interval).count
stats[:stat_container_image_registration_rate] = obj.all_container_images.where(:registered_on => date_range).count
end

stats
Expand Down
9 changes: 8 additions & 1 deletion app/models/vim_performance_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def self.capture(objs)

def capture
self.state_data ||= {}
self.capture_interval = 3600
self.capture_interval = 1.hour.to_i
capture_assoc_ids
capture_parent_host
capture_parent_storage
Expand Down Expand Up @@ -162,6 +162,13 @@ def get_assoc(relat, mode = nil)
ids.nil? ? [] : ids.uniq.sort
end

# @param timestamp [Time|String] hourly timestamp, prefer Time
# @returns [Range] time range
def self.get_time_interval(timestamp)
timestamp = Time.parse(timestamp).utc if timestamp.kind_of?(String)
(timestamp - 1.hour)..timestamp
end

private

def capture_disk_types
Expand Down

0 comments on commit c6bfffb

Please sign in to comment.