Commit f615daec by Kohl Krisztofer

First 3.6 version

parent 5978a646
......@@ -16,9 +16,7 @@ level = os.environ.get('LOGLEVEL', 'INFO')
logger.setLevel(level)
class Client:
env_config = {
"server_address": "GRAPHITE_HOST",
"server_port": "GRAPHITE_PORT",
......@@ -43,7 +41,7 @@ class Client:
Missing only one of these variables will cause the client not to work.
"""
self.name = 'circle.%s' % gethostname().split(".")[0]
for var, env_var in self.env_config.items():
for var, env_var in list(self.env_config.items()):
value = os.getenv(env_var, "")
if value:
setattr(self, var, value)
......@@ -85,7 +83,7 @@ class Client:
self.connection.close()
except RuntimeError as e:
logger.error('An error has occured while disconnecting. %s',
unicode(e))
str(e))
raise
def send(self, message):
......@@ -124,13 +122,13 @@ class Client:
}
try:
for k, v in psutil.disk_io_counters().__dict__.items():
for k, v in list(psutil.disk_io_counters().__dict__.items()):
metrics['disk.%s' % k] = v
except:
pass
interfaces = psutil.network_io_counters(pernic=True)
for interface, data in interfaces.iteritems():
interfaces = psutil.net_io_counters(pernic=True)
for interface, data in interfaces.items():
if not (interface.startswith('cloud') or
interface.endswith('-EXT') or
interface.startswith('net') or
......@@ -145,7 +143,7 @@ class Client:
'name': name,
'val': value,
'time': now}
for name, value in metrics.iteritems()]
for name, value in metrics.items()]
def collect_vms(self):
"""
......@@ -158,7 +156,7 @@ class Client:
running_vms = []
try:
for entry in psutil.get_process_list():
for entry in psutil.process_iter():
if entry.name() in ('kvm', 'qemu-system-x86_64'):
parser = argparse.ArgumentParser()
parser.add_argument('-name')
......@@ -166,36 +164,36 @@ class Client:
args, unknown = parser.parse_known_args(
entry.cmdline()[1:])
# for Red Hat style parametering of kvm
if isinstance(args.name, basestring):
if isinstance(args.name, str):
args.name = re.sub(r"^guest=", "", args.name)
args.name = re.sub(r",debug-threads=.*$", "", args.name)
process = self.processes.get(entry.pid, None)
if not process or process.cmdline() != entry.cmdline():
process = psutil.Process(entry.pid)
logger.info('New process: %s', process)
self.processes[entry.pid] = process
mem_perc = (float(process.get_memory_info().rss)
/ (args.memory_size * 1024 ** 2) * 90)
metrics.append('vm.%(name)s.memory.usage %(value)f '
'%(time)d' % {'name': args.name,
'value': mem_perc,
'time': now})
cpu_perc = process.get_cpu_percent()
metrics.append('vm.%(name)s.cpu.percent %(value)f '
'%(time)d' % {'name': args.name,
'value': cpu_perc,
'time': now})
running_vms.append(args.name)
else:
if not process or process.cmdline() != entry.cmdline():
process = psutil.Process(entry.pid)
logger.info('New process: %s', process)
self.processes[entry.pid] = process
mem_perc = (float(process.get_memory_info().rss)
/ (args.memory_size * 1024 ** 2) * 90)
metrics.append('vm.%(name)s.memory.usage %(value)f '
'%(time)d' % {'name': args.name,
'value': mem_perc,
'time': now})
cpu_perc = process.get_cpu_percent()
metrics.append('vm.%(name)s.cpu.percent %(value)f '
'%(time)d' % {'name': args.name,
'value': cpu_perc,
'time': now})
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, TypeError):
logger.warning('Process %d lost. Entry: %s', entry.pid, entry.cmdline()[0:])
interfaces = psutil.network_io_counters(pernic=True)
for interface, data in interfaces.iteritems():
interfaces = psutil.net_io_counters(pernic=True)
for interface, data in interfaces.items():
try:
vm, vlan = interface.rsplit('-', 1)
except ValueError:
......@@ -207,10 +205,10 @@ class Client:
'vm.%(name)s.network.%(metric)s-'
'%(interface)s %(data)f %(time)d' %
{'name': vm,
'interface': vlan,
'metric': metric,
'time': now,
'data': getattr(data, metric)})
'interface': vlan,
'metric': metric,
'time': now,
'data': getattr(data, metric)})
metrics.append(
'%(host)s.vmcount %(data)d %(time)d' % {
......@@ -224,7 +222,7 @@ class Client:
def _chunker(seq, size):
"""Yield seq in size-long chunks.
"""
for pos in xrange(0, len(seq), size):
for pos in range(0, len(seq), size):
yield islice(seq, pos, pos + size)
def run(self):
......
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