Skip to content

Commit

Permalink
Replace CPUTime by CPU usage in Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilPeponnet committed Jan 27, 2013
1 parent 21e42e6 commit 5e514b9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ArchipelAgent/archipel-agent/archipel/archipelVirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import xmpp
import tempfile
import base64
from time import sleep
from threading import Timer

from archipelcore.archipelAvatarControllableEntity import TNAvatarControllableEntity
Expand Down Expand Up @@ -674,6 +675,16 @@ def screenshot(self, thumbnail=True):
return (data, size)
return (None, (0, 0))

def __compute_cpu_usage(self,interval):
"""
Return the vm CPU usage in percent within interval
"""
nrCore = self.hypervisor.get_nodeinfo()['nrCoreperSocket']
t0 = self.domain.info()[4]
sleep(interval)
t1 = self.domain.info()[4]
return 100*(t1-t0)/(interval*nrCore*1000000000)

def info(self):
"""
Return info of a domain.
Expand All @@ -692,7 +703,7 @@ def info(self):
"maxMem": dominfo[1],
"memory": dominfo[2],
"nrVirtCpu": dominfo[3],
"cpuTime": dominfo[4],
"cpuPrct": self.__compute_cpu_usage(1),
"hypervisor": self.hypervisor.jid,
"autostart": str(autostart)}

Expand Down

0 comments on commit 5e514b9

Please sign in to comment.