Commit 6ac9301d by Szeberényi Imre

ps fix

parents 4395d49b 54443046
...@@ -10,7 +10,11 @@ import psutil ...@@ -10,7 +10,11 @@ import psutil
import time import time
import re import re
logging.basicConfig()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
level = os.environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
class Client: class Client:
...@@ -153,8 +157,8 @@ class Client: ...@@ -153,8 +157,8 @@ class Client:
now = time.time() now = time.time()
running_vms = [] running_vms = []
for entry in psutil.get_process_list():
try: try:
for entry in psutil.get_process_list():
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')
...@@ -162,6 +166,7 @@ class Client: ...@@ -162,6 +166,7 @@ class Client:
args, unknown = parser.parse_known_args( args, unknown = parser.parse_known_args(
entry.cmdline()[1:]) entry.cmdline()[1:])
# for Red Hat style parametering of kvm # for Red Hat style parametering of kvm
if isinstance(args.name, basestring):
args.name = re.sub(r"^guest=", "", args.name) args.name = re.sub(r"^guest=", "", args.name)
args.name = re.sub(r",debug-threads=.*$", "", args.name) args.name = re.sub(r",debug-threads=.*$", "", args.name)
...@@ -183,6 +188,9 @@ class Client: ...@@ -183,6 +188,9 @@ class Client:
'value': cpu_perc, 'value': cpu_perc,
'time': now}) 'time': now})
running_vms.append(args.name) running_vms.append(args.name)
else:
logger.warning('Pid: %d args.name is empty?: %s %s', entry.pid, entry.name(), entry.cmdline())
except psutil.NoSuchProcess: except psutil.NoSuchProcess:
logger.warning('Process %d lost.', entry.pid) logger.warning('Process %d lost.', entry.pid)
except TypeError: except TypeError:
......
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