diff --git a/share/doc/xsd/showback.xsd b/share/doc/xsd/showback.xsd
index 6a0944e545..bb100fcc51 100644
--- a/share/doc/xsd/showback.xsd
+++ b/share/doc/xsd/showback.xsd
@@ -20,6 +20,7 @@
+
diff --git a/src/cli/one_helper/oneacct_helper.rb b/src/cli/one_helper/oneacct_helper.rb
index 3304047dc1..45d86f883d 100644
--- a/src/cli/one_helper/oneacct_helper.rb
+++ b/src/cli/one_helper/oneacct_helper.rb
@@ -227,11 +227,15 @@ class AcctHelper < OpenNebulaHelper::OneHelper
d["HOURS"]
end
+ column :RUNNING_HOURS, "Running hours", :size=>7 do |d|
+ d["RHOURS"] || '-'
+ end
+
column :COST, "Cost", :size=>15 do |d|
d["TOTAL_COST"]
end
- default :USER_NAME, :GROUP_NAME, :VM_ID, :VM_NAME, :MONTH, :YEAR, :HOURS, :COST
+ default :USER_NAME, :GROUP_NAME, :VM_ID, :VM_NAME, :MONTH, :YEAR, :HOURS, :RUNNING_HOURS, :COST
end
def self.print_start_end_time_header(start_time, end_time)
diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc
index 3a4a4cb1f4..3fa9ce555b 100644
--- a/src/vm/VirtualMachinePool.cc
+++ b/src/vm/VirtualMachinePool.cc
@@ -534,13 +534,15 @@ struct SBRecord {
string memc_s = one_util::float_to_str(mem_cost);
string diskc_s= one_util::float_to_str(disk_cost);
string hour_s = one_util::float_to_str(hours);
+ string rhour_s= one_util::float_to_str(rhours);
string cost_s = one_util::float_to_str(cpu_cost + mem_cost + disk_cost);
oss << "" << cpuc_s << ""
<< ""<< memc_s << ""
<< "" << diskc_s<< ""
<< "" << cost_s << ""
- << "" << hour_s << "";
+ << "" << hour_s << ""
+ << "" << rhour_s << "";
return oss;
};
@@ -549,6 +551,7 @@ struct SBRecord {
float mem_cost = 0;
float disk_cost = 0;
float hours = 0;
+ float rhours = 0;
};
struct VMCost {
@@ -773,7 +776,7 @@ int VirtualMachinePool::calculate_showback(
time_t t = *slot_it;
time_t t_next = *(slot_it+1);
- auto count_sb_record = [&](time_t st, time_t et, bool cpu_mem, bool disk_total)
+ auto count_sb_record = [&](time_t st, time_t et, bool cpu_mem, bool disk_total, bool running_hours)
{
if( (et > t || et == 0) &&
(st != 0 && st <= t_next) ) {
@@ -803,17 +806,22 @@ int VirtualMachinePool::calculate_showback(
totals.disk_cost+= disk_cost* disk* n_hours;
totals.hours += n_hours;
}
+ if (running_hours)
+ {
+ totals.rhours += n_hours;
+ }
}
};
if (_showback_only_running)
{
- count_sb_record(h_stime, h_etime, false, true);
- count_sb_record(h_rstime, h_retime, true, false);
+ count_sb_record(h_stime, h_etime, false, true, false);
+ count_sb_record(h_rstime, h_retime, true, false, true);
}
else
{
- count_sb_record(h_stime, h_etime, true, true);
+ count_sb_record(h_stime, h_etime, true, true, false);
+ count_sb_record(h_rstime, h_retime, false, false, true);
}
}
}