599 |
599 |
*/
|
600 |
600 |
struct SBRecord {
|
601 |
601 |
|
602 |
|
SBRecord(float c, float m, float h): cpu_cost(c), mem_cost(m), hours(h){};
|
603 |
|
SBRecord(): cpu_cost(0), mem_cost(0), hours(0){};
|
|
602 |
SBRecord(float c, float m, float h, float extra): cpu_cost(c), mem_cost(m), hours(h), extra_cost(extra){};
|
|
603 |
SBRecord(): cpu_cost(0), mem_cost(0), hours(0), extra_cost(0){};
|
604 |
604 |
|
605 |
605 |
ostringstream& to_xml(ostringstream &oss)
|
606 |
606 |
{
|
607 |
607 |
string cpuc_s = one_util::float_to_str(cpu_cost);
|
608 |
608 |
string memc_s = one_util::float_to_str(mem_cost);
|
609 |
609 |
string hour_s = one_util::float_to_str(hours);
|
610 |
|
string cost_s = one_util::float_to_str(cpu_cost + mem_cost);
|
|
610 |
string cost_s = one_util::float_to_str(cpu_cost + mem_cost + extra_cost);
|
611 |
611 |
|
612 |
612 |
oss << "<CPU_COST>" << cpuc_s << "</CPU_COST>"
|
613 |
613 |
<< "<MEMORY_COST>"<< memc_s << "</MEMORY_COST>"
|
... | ... | |
621 |
621 |
{
|
622 |
622 |
cpu_cost = 0;
|
623 |
623 |
mem_cost = 0;
|
|
624 |
extra_cost = 0;
|
624 |
625 |
hours = 0;
|
625 |
626 |
};
|
626 |
627 |
|
627 |
628 |
float cpu_cost;
|
628 |
629 |
float mem_cost;
|
629 |
630 |
float hours;
|
|
631 |
float extra_cost;
|
630 |
632 |
};
|
631 |
633 |
|
632 |
634 |
int VirtualMachinePool::calculate_showback(
|
... | ... | |
664 |
666 |
int h_etime;
|
665 |
667 |
float cpu_cost;
|
666 |
668 |
float mem_cost;
|
|
669 |
float extra_cost;
|
667 |
670 |
float cpu;
|
668 |
671 |
int mem;
|
669 |
672 |
|
... | ... | |
803 |
806 |
history.xpath(cpu_cost, "/HISTORY/VM/TEMPLATE/CPU_COST", _default_cpu_cost);
|
804 |
807 |
history.xpath(mem_cost, "/HISTORY/VM/TEMPLATE/MEMORY_COST", _default_mem_cost);
|
805 |
808 |
|
|
809 |
extra_cost = 0;
|
|
810 |
{
|
|
811 |
FILE *fp;
|
|
812 |
ostringstream cmd;
|
|
813 |
ostringstream history_string;
|
|
814 |
char extra_cost_str[128];
|
|
815 |
|
|
816 |
history_string << history;
|
|
817 |
|
|
818 |
cmd << "aurae-calculate-showback-extra " << vid << " " << cpu << " " << mem << " '" << *(one_util::base64_encode(history_string.str())) << "' 2>/dev/null";
|
|
819 |
|
|
820 |
fp = popen(cmd.str().c_str(), "r");
|
|
821 |
|
|
822 |
if (fp != NULL) {
|
|
823 |
extra_cost_str[0] = '\0';
|
|
824 |
fgets(extra_cost_str, sizeof(extra_cost_str), fp);
|
|
825 |
|
|
826 |
pclose(fp);
|
|
827 |
|
|
828 |
if (extra_cost_str[0] != '\0') {
|
|
829 |
extra_cost = atof(extra_cost_str);
|
|
830 |
}
|
|
831 |
}
|
|
832 |
}
|
|
833 |
|
806 |
834 |
#ifdef SBDDEBUG
|
807 |
835 |
int seq;
|
808 |
836 |
history.xpath(seq, "/HISTORY/SEQ", -1);
|
... | ... | |
813 |
841 |
<< "h_etime " << h_etime << endl
|
814 |
842 |
<< "cpu_cost " << cpu_cost << endl
|
815 |
843 |
<< "mem_cost " << mem_cost << endl
|
|
844 |
<< "extra_cost " << extra_cost << endl
|
816 |
845 |
<< "cpu " << cpu << endl
|
817 |
846 |
<< "mem " << mem;
|
818 |
847 |
|
... | ... | |
849 |
878 |
|
850 |
879 |
totals[t].cpu_cost += cpu_cost * cpu * n_hours;
|
851 |
880 |
totals[t].mem_cost += mem_cost * mem * n_hours;
|
|
881 |
totals[t].extra_cost += extra_cost * n_hours;
|
852 |
882 |
totals[t].hours += n_hours;
|
853 |
883 |
}
|
854 |
884 |
}
|
... | ... | |
993 |
1023 |
<< " M " << tmp_tm.tm_mon + 1
|
994 |
1024 |
<< " COST " << one_util::float_to_str(
|
995 |
1025 |
vm_month_it->second.cpu_cost +
|
996 |
|
vm_month_it->second.mem_cost) << " €"
|
|
1026 |
vm_month_it->second.mem_cost +
|
|
1027 |
vm_month_it->second.extra_cost) << " €"
|
997 |
1028 |
<< " HOURS " << vm_month_it->second.hours;
|
998 |
1029 |
|
999 |
1030 |
NebulaLog::log("SHOWBACK", Log::DEBUG, debug);
|