1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F #5561: Showback computes running hours (#1527)

(cherry picked from commit af9ea24ec4)
This commit is contained in:
Pavel Czerný 2021-10-15 17:40:17 +02:00 committed by Ruben S. Montero
parent f10f73ce33
commit 38d06a92aa
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
3 changed files with 19 additions and 6 deletions

View File

@ -20,6 +20,7 @@
<xs:element name="DISK_COST" type="xs:float"/>
<xs:element name="TOTAL_COST" type="xs:float"/>
<xs:element name="HOURS" type="xs:float"/>
<xs:element name="RHOURS" type="xs:float" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>

View File

@ -216,11 +216,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)

View File

@ -527,13 +527,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 << "<CPU_COST>" << cpuc_s << "</CPU_COST>"
<< "<MEMORY_COST>"<< memc_s << "</MEMORY_COST>"
<< "<DISK_COST>" << diskc_s<< "</DISK_COST>"
<< "<TOTAL_COST>" << cost_s << "</TOTAL_COST>"
<< "<HOURS>" << hour_s << "</HOURS>";
<< "<HOURS>" << hour_s << "</HOURS>"
<< "<RHOURS>" << rhour_s << "</RHOURS>";
return oss;
};
@ -542,6 +544,7 @@ struct SBRecord {
float mem_cost = 0;
float disk_cost = 0;
float hours = 0;
float rhours = 0;
};
struct VMCost {
@ -766,7 +769,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) ) {
@ -796,17 +799,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);
}
}
}