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,7 +164,7 @@ 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)
......@@ -194,8 +192,8 @@ class Client:
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:
......@@ -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