Created
December 2, 2015 09:32
-
-
Save sustr4/013138de4ea6c9dbb05b to your computer and use it in GitHub Desktop.
Generate temporal sequence from clouditor exports. Totals are recalculated for each second whence at least one change occurred.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
data = YAML.load_file("vm_records_export.yml") | |
cpu_timeline = Hash.new | |
mem_timeline = Hash.new | |
now = Time.now.to_i | |
data.each { |rec| | |
rec["runtime"].each { |runtime| | |
# The VM is still running. Count as if it stopped now | |
runtime["end_time"] = now if runtime["end_time"] == 0 | |
# Set zero for timestampts not yet seen | |
cpu_timeline[runtime["start_time"]] = 0 if cpu_timeline[runtime["start_time"]].nil? | |
cpu_timeline[runtime["end_time"]] = 0 if cpu_timeline[runtime["end_time"]].nil? | |
mem_timeline[runtime["start_time"]] = 0 if mem_timeline[runtime["start_time"]].nil? | |
mem_timeline[runtime["end_time"]] = 0 if mem_timeline[runtime["end_time"]].nil? | |
# Add data on start, subtract on end | |
cpu_timeline[runtime["start_time"]] = cpu_timeline[runtime["start_time"]] + rec["cpu"] | |
cpu_timeline[runtime["end_time"]] = cpu_timeline[runtime["end_time"]] - rec["cpu"] | |
mem_timeline[runtime["start_time"]] = mem_timeline[runtime["start_time"]] + rec["memory"] | |
mem_timeline[runtime["end_time"]] = mem_timeline[runtime["end_time"]] - rec["memory"] | |
} | |
} | |
runcpu = 0 | |
runmem = 0 | |
#Go sequentially and count | |
cpu_timeline.sort.to_h.each { |point,cpu| | |
runcpu = runcpu + cpu | |
runmem = runmem + mem_timeline[point] | |
print "#{point/86400.0+25569}, #{runcpu}, #{runmem}\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment