23 using namespace boost::uuids;
24 using namespace boost::asio;
47 std::string cpu_stat_str, state_str, cpu_count_str;
49 while (
data_ >> tmp) {
50 if (tmp ==
"State:") {
53 if (tmp ==
"CPU(s):") {
54 data_ >> cpu_count_str;
57 data_ >> cpu_stat_str;
65 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_UNKNOWN;
66 if (state_str.size()) {
67 if (state_str ==
"running") {
68 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_ACTIVE;
69 }
else if (state_str ==
"paused") {
70 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_PAUSED;
71 }
else if (state_str ==
"shut") {
72 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_SHUTDOWN;
76 if (cpu_count_str.size()) {
80 if (cpu_stat_str.size() >= 2) {
81 cpu_stat_str.erase(cpu_stat_str.size() - 1);
83 std::stringstream ss(cpu_stat_str);
109 std::vector<double> vcpu_usage;
111 while(
data_ >> tmp) {
112 if (tmp ==
"VCPU:") {
117 if (tmp ==
"time:") {
120 vcpu_usage.push_back(usage);
134 for (uint32_t i = 0; i < vcpu_usage.size(); i++) {
153 std::ostringstream proc_file;
154 proc_file <<
"/proc/"<<
pid_<<
"/status";
155 std::ifstream file(proc_file.str().c_str());
161 while (std::getline(file, line)) {
162 if (line.find(
"VmSize") != std::string::npos) {
163 std::stringstream vm(line);
167 if (line.find(
"VmRSS") != std::string::npos) {
168 std::stringstream vm(line);
174 if (line.find(
"VmPeak") != std::string::npos) {
175 std::stringstream vm(line);
179 if (rss && vmsize && peak)
190 std::ostringstream cmd;
196 std::ostringstream cmd;
206 std::ostringstream cmd;
214 if (!disk_name_.empty()) {
223 std::ostringstream cmd;
230 bool disk_size_found =
false, virtual_size_found =
false;
232 std::string virtual_size_str, disk_size_str;
233 while (
data_ >> tmp) {
234 if (tmp ==
"Capacity:") {
235 data_ >> virtual_size_str;
236 virtual_size_found =
true;
237 }
else if (tmp ==
"Allocation:") {
238 data_ >> disk_size_str;
239 disk_size_found =
true;
241 if (virtual_size_found && disk_size_found) {
245 if (virtual_size_str.size() >= 2) {
247 std::stringstream ss(virtual_size_str);
251 if (disk_size_str.size() >= 2) {
253 std::stringstream ss(disk_size_str);
263 while (
data_ >> tmp) {
264 if (tmp ==
"actual") {
272 std::ostringstream cmd;
294 if (tmp.find(
"qemu") != std::string::npos ||
295 tmp.find(
"kvm") != std::string::npos) {
301 data_.ignore(512,
'\n');
319 std::ostringstream cmd;
321 <<
" | grep instance-";
std::vector< double > vcpu_usage_percent_
time_t prev_cpu_snapshot_time_
void ExecCmd(std::string cmd, DoneCb cb)
bool stringToInteger(const std::string &str, NumberType &num)
VrouterAgentVmState::type vm_state_
static const uint32_t kRetryCount
uint32_t virt_memory_peak_
std::vector< double > prev_vcpu_usage_
uint32_t vm_memory_quota_
static const uint16_t kInvalidCpuCount
std::string GetUuidStr(boost::uuids::uuid uuid_val) const
const boost::uuids::uuid vm_uuid_
time_t prev_vcpu_snapshot_time_
VmStatKvm(Agent *agent, const boost::uuids::uuid &vm_uuid)