Commit c992fbfb by Bach Dániel

Merge branch 'fix-graphs' into 'master'

Fix Graphs
parents beee6ccb 08fc87fc
...@@ -107,13 +107,15 @@ class Client: ...@@ -107,13 +107,15 @@ class Client:
""" """
now = time.time() now = time.time()
vmem = psutil.virtual_memory()
metrics = { metrics = {
'cpu.usage': psutil.cpu_percent(interval=0.0), 'cpu.percent': psutil.cpu_percent(),
'cpu.times': psutil.cpu_times().user + psutil.cpu_times().system, 'cpu.times': psutil.cpu_times().user + psutil.cpu_times().system,
'memory.usage': psutil.virtual_memory().percent, 'memory.usage': vmem.percent,
'memory.used_bytes': (vmem.total - vmem.available),
'swap.usage': psutil.swap_memory().percent, 'swap.usage': psutil.swap_memory().percent,
'user.count': len(psutil.get_users()), 'user.count': len(psutil.users()),
'system.boot_time': psutil.get_boot_time() 'system.boot_time': psutil.boot_time()
} }
for k, v in psutil.disk_io_counters().__dict__.items(): for k, v in psutil.disk_io_counters().__dict__.items():
...@@ -121,7 +123,11 @@ class Client: ...@@ -121,7 +123,11 @@ class Client:
interfaces = psutil.network_io_counters(pernic=True) interfaces = psutil.network_io_counters(pernic=True)
for interface, data in interfaces.iteritems(): for interface, data in interfaces.iteritems():
if not interface.startswith('cloud-'): if not (interface.startswith('cloud') or
interface.endswith('-EXT') or
interface.startswith('net') or
interface.startswith('link') or
interface in ('lo', 'firewall', 'virbr0', 'ovs-system')):
for metric in ('packets_sent', 'packets_recv', for metric in ('packets_sent', 'packets_recv',
'bytes_sent', 'bytes_recv'): 'bytes_sent', 'bytes_recv'):
metrics['network.%s-%s' % metrics['network.%s-%s' %
...@@ -145,14 +151,18 @@ class Client: ...@@ -145,14 +151,18 @@ class Client:
for entry in psutil.get_process_list(): for entry in psutil.get_process_list():
try: try:
if entry.name in ('kvm', 'qemu-system-x86_64'): if entry.name() in ('kvm', 'qemu-system-x86_64'):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-name') parser.add_argument('-name')
parser.add_argument('--memory-size', '-m ', type=int) parser.add_argument('--memory-size', '-m ', type=int)
args, unknown = parser.parse_known_args( args, unknown = parser.parse_known_args(
entry.cmdline[1:]) entry.cmdline()[1:])
process = self.processes.get(entry.pid, None)
if not process or process.cmdline() != entry.cmdline():
process = psutil.Process(entry.pid) process = psutil.Process(entry.pid)
logger.info('New process: %s', process)
self.processes[entry.pid] = process
mem_perc = (process.get_memory_percent() mem_perc = (process.get_memory_percent()
/ 100 * args.memory_size) / 100 * args.memory_size)
...@@ -160,11 +170,10 @@ class Client: ...@@ -160,11 +170,10 @@ class Client:
'%(time)d' % {'name': args.name, '%(time)d' % {'name': args.name,
'value': mem_perc, 'value': mem_perc,
'time': now}) 'time': now})
user_time, system_time = process.get_cpu_times() cpu_perc = process.get_cpu_percent()
sum_time = system_time + user_time metrics.append('vm.%(name)s.cpu.percent %(value)f '
metrics.append('vm.%(name)s.cpu.usage %(value)f '
'%(time)d' % {'name': args.name, '%(time)d' % {'name': args.name,
'value': sum_time, 'value': cpu_perc,
'time': now}) 'time': now})
running_vms.append(args.name) running_vms.append(args.name)
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
...@@ -210,6 +219,7 @@ class Client: ...@@ -210,6 +219,7 @@ class Client:
modul to work properly. modul to work properly.
""" """
self.connect() self.connect()
self.processes = {}
try: try:
while True: while True:
metrics = self.collect_node() + self.collect_vms() metrics = self.collect_node() + self.collect_vms()
......
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 sign in to comment