24 using namespace boost::uuids;
25 using namespace boost::asio;
28 :
VmStat(agent, vm_uuid), container_id_() {
43 std::string cpu_stat_str;
44 data_ >> cpu_stat_str;
46 if (!cpu_stat_str.empty()) {
48 std::stringstream ss(cpu_stat_str);
75 std::ostringstream proc_file;
76 proc_file <<
"/proc/"<<
pid_<<
"/status";
77 std::ifstream file(proc_file.str().c_str());
83 while (std::getline(file, line)) {
84 if (line.find(
"VmSize") != std::string::npos) {
85 std::stringstream vm(line);
89 if (line.find(
"VmRSS") != std::string::npos) {
90 std::stringstream vm(line);
96 if (line.find(
"VmPeak") != std::string::npos) {
97 std::stringstream vm(line);
101 if (rss && vmsize && peak)
114 std::ostringstream cmd;
121 std::ostringstream cmd;
132 std::ostringstream cmd;
133 cmd <<
"docker inspect " <<
container_id_ <<
"| grep -A3 \\\"Paused\\\":";
144 string tmp, paused_str, pid_str, running_str;
145 while (
data_ >> tmp) {
146 if (tmp.find(
"Paused") != std::string::npos) {
149 if (tmp.find(
"Pid") != std::string::npos) {
152 if (tmp.find(
"Running") != std::string::npos) {
153 data_ >> running_str;
159 if (pid_str.size() >= 2) {
160 pid_str.erase(pid_str.size() - 1);
162 std::stringstream ss(pid_str);
166 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_UNKNOWN;
167 if (paused_str ==
"true,") {
168 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_PAUSED;
169 }
else if (running_str ==
"false,") {
170 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_SHUTDOWN;
171 }
else if (running_str ==
"true,") {
172 vm_state_ = VrouterAgentVmState::VROUTER_AGENT_VM_ACTIVE;
181 while (
data_ >> tmp) {
182 if (tmp ==
"hierarchical_memory_limit") {
225 std::ostringstream cmd;
227 <<
" | awk '{ print $1 }'";
std::string GetUuidStr(boost::uuids::uuid uuid_val) const
static const long kOneSecInNanoSecs
std::string container_id_
VmStatDocker(Agent *agent, const boost::uuids::uuid &vm_uuid)
VrouterAgentVmState::type vm_state_
static const uint32_t kRetryCount
void ExecCmd(std::string cmd, DoneCb cb)
const boost::uuids::uuid vm_uuid_
time_t prev_cpu_snapshot_time_
uint32_t vm_memory_quota_
uint32_t virt_memory_peak_