Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Add decimal-cpu-percentage for CC stat usage.
Browse files Browse the repository at this point in the history
[Finishes #120740573]

Signed-off-by: Sandy Cash <scarlet.tanager@gmail.com>
  • Loading branch information
jberkhahn authored and ScarletTanager committed Jun 14, 2016
1 parent 87acf5f commit 329d8ae
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dea/protocol.rb
Expand Up @@ -56,7 +56,7 @@ def self.generate(bootstrap, instance, request)
"fds_quota" => instance.file_descriptor_limit,
"usage" => {
"time" => Time.now.to_s,
"cpu" => instance.stat_collector.computed_pcpu,
"cpu" => instance.stat_collector.computed_dcpu,
"mem" => instance.stat_collector.used_memory_in_bytes,
"disk" => instance.stat_collector.used_disk_in_bytes,
},
Expand Down
3 changes: 3 additions & 0 deletions lib/dea/stat_collector.rb
Expand Up @@ -7,13 +7,15 @@ class StatCollector
attr_reader :used_memory_in_bytes
attr_reader :used_disk_in_bytes
attr_reader :computed_pcpu
attr_reader :computed_dcpu

def initialize(container, application_id, instance_index)
@container = container
@application_id = application_id
@instance_index = instance_index
@cpu_samples = []
@computed_pcpu = 0
@computed_dcpu = 0
@used_memory_in_bytes = 0
@used_disk_in_bytes = 0
end
Expand Down Expand Up @@ -48,6 +50,7 @@ def compute_cpu_usage(usage, now)
elapsed = @cpu_samples[1][:timestamp_ns] - @cpu_samples[0][:timestamp_ns]

if elapsed > 0
@computed_dcpu = used.to_f / elapsed
@computed_pcpu = (used * 100).to_f / elapsed
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/stat_collector_spec.rb
Expand Up @@ -49,6 +49,7 @@

it 'initializes the statistic variables to 0' do
expect(collector.computed_pcpu).to eq(0)
expect(collector.computed_dcpu).to eq(0)
expect(collector.used_memory_in_bytes).to eq(0)
expect(collector.used_disk_in_bytes).to eq(0)
end
Expand Down Expand Up @@ -92,6 +93,7 @@
collector.emit_metrics(Time.now())

expect(collector.computed_pcpu).to eq(0)
expect(collector.computed_dcpu).to eq(0)
expect(collector.used_memory_in_bytes).to eq(expected_memory_usage)
expect(collector.used_disk_in_bytes).to eq(expected_disk_usage)
end
Expand Down Expand Up @@ -164,8 +166,10 @@

time_between_stats = (Dea::StatCollector::INTERVAL * NANOSECONDS_PER_SECOND)
expected_pcpu = (10_000_000_000 - 5_000_000) * 100 / time_between_stats
expected_dcpu = expected_pcpu / 100.0

expect(collector.computed_pcpu).to eq(expected_pcpu)
expect(collector.computed_dcpu).to eq(expected_dcpu)
expect(collector.used_memory_in_bytes).to eq(1000)
expect(collector.used_disk_in_bytes).to eq(78)
end
Expand Down

0 comments on commit 329d8ae

Please sign in to comment.