Commit 4ca4b68e authored by Lutra Conseil's avatar Lutra Conseil Committed by Rafael Monnerat

[slapos.collect] fix collection of cpu_times for the processes.

  It is required to update the cpu_percent after a while to have more
  accurate values.
parent 315ca2dc
...@@ -59,6 +59,7 @@ class User(object): ...@@ -59,6 +59,7 @@ class User(object):
""" Insert collected data on user collector """ """ Insert collected data on user collector """
database.connect() database.connect()
for snapshot_item in self.snapshot_list: for snapshot_item in self.snapshot_list:
snapshot_item.update_cpu_percent()
database.insertUserSnapshot(self.name, database.insertUserSnapshot(self.name,
pid=snapshot_item.get("pid"), pid=snapshot_item.get("pid"),
process=snapshot_item.get("process"), process=snapshot_item.get("process"),
......
...@@ -41,11 +41,12 @@ class ProcessSnapshot(_Snapshot): ...@@ -41,11 +41,12 @@ class ProcessSnapshot(_Snapshot):
assert type(process) is psutil.Process assert type(process) is psutil.Process
ui_counter_list = process.get_io_counters() ui_counter_list = process.get_io_counters()
self.username = process.username() self.username = process.username()
self.process_object = process
self.pid = process.pid self.pid = process.pid
# Save full command line from the process. # Save full command line from the process.
self.name = "%s-%s" % (process.pid, process.create_time()) self.process = "%s-%s" % (process.pid, process.create_time())
# CPU percentage, we will have to get actual absolute value # CPU percentage, we will have to get actual absolute value
self.cpu_percent = process.get_cpu_percent(None) self.cpu_percent = self.process_object.get_cpu_percent(None)
# CPU Time # CPU Time
self.cpu_time = sum(process.get_cpu_times()) self.cpu_time = sum(process.get_cpu_times())
# Thread number, might not be really relevant # Thread number, might not be really relevant
...@@ -59,6 +60,10 @@ class ProcessSnapshot(_Snapshot): ...@@ -59,6 +60,10 @@ class ProcessSnapshot(_Snapshot):
# Read + write IO cycles # Read + write IO cycles
self.io_cycles_counter = ui_counter_list[0] + ui_counter_list[1] self.io_cycles_counter = ui_counter_list[0] + ui_counter_list[1]
def update_cpu_percent(self):
# CPU percentage, we will have to get actual absolute value
self.cpu_percent = self.process_object.get_cpu_percent()
class SystemSnapshot(_Snapshot): class SystemSnapshot(_Snapshot):
""" Take a snapshot from current system usage """ Take a snapshot from current system usage
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment