# Volodymyr Mytnyk <volodymyrx.mytnyk@intel.com>
#
-import yaml
+from . import yaml
import logging
import datetime
import time
# import YAML loader
try:
- from yaml import CLoader as Loader
+ from .yaml import CLoader as Loader
except ImportError:
- from yaml import Loader
+ from .yaml import Loader
# import synchronized queue
-try:
- # python 2.x
- import Queue as queue
-except ImportError:
- # python 3.x
- import queue
+import queue
class Config(object):
self._collector = collector
self._index = 0
- def next(self):
+ def __next__(self):
"""Returns next item from the list"""
if self._index == len(self._items):
raise StopIteration
def _check_aging(self):
"""Check aging time for all items"""
self.lock()
- for data_hash, data in self._metrics.items():
+ for data_hash, data in list(self._metrics.items()):
age, item = data
if ((time.time() - age) >= self._age_timeout):
# aging time has expired, remove the item from the collector
"""Returns locked (safe) item iterator"""
metrics = []
self.lock()
- for k, item in self._metrics.items():
+ for k, item in list(self._metrics.items()):
_, value = item
for select in select_list:
if value.match(**select):
def match(self, **kargs):
# compare the metric
- for key, value in kargs.items():
+ for key, value in list(kargs.items()):
if self.is_regular_expression(value):
if re.match(value[1:-1], getattr(self, key)) is None:
return False
class ValueItem(Item):
"""Class to process VlaueItem tag"""
- yaml_tag = u'!ValueItem'
+ yaml_tag = '!ValueItem'
@classmethod
def from_yaml(cls, loader, node):
# if VALUE key isn't given, use default VALUE key
# format: `VALUE: !Number '{vl.value}'`
if value_desc is None:
- value_desc = yaml.ScalarNode(tag=u'!Number', value=u'{vl.value}')
+ value_desc = yaml.ScalarNode(tag='!Number', value='{vl.value}')
# select collectd metric based on SELECT condition
metrics = loader.collector.items(select)
assert len(metrics) < 2, \
class ArrayItem(Item):
"""Class to process ArrayItem tag"""
- yaml_tag = u'!ArrayItem'
+ yaml_tag = '!ArrayItem'
@classmethod
def from_yaml(cls, loader, node):
class Measurements(ArrayItem):
"""Class to process Measurements tag"""
- yaml_tag = u'!Measurements'
+ yaml_tag = '!Measurements'
class Events(Item):
"""Class to process Events tag"""
- yaml_tag = u'!Events'
+ yaml_tag = '!Events'
@classmethod
def from_yaml(cls, loader, node):
class Bytes2Kibibytes(yaml.YAMLObject):
"""Class to process Bytes2Kibibytes tag"""
- yaml_tag = u'!Bytes2Kibibytes'
+ yaml_tag = '!Bytes2Kibibytes'
@classmethod
def from_yaml(cls, loader, node):
class Number(yaml.YAMLObject):
"""Class to process Number tag"""
- yaml_tag = u'!Number'
+ yaml_tag = '!Number'
@classmethod
def from_yaml(cls, loader, node):
class StripExtraDash(yaml.YAMLObject):
"""Class to process StripExtraDash tag"""
- yaml_tag = u'!StripExtraDash'
+ yaml_tag = '!StripExtraDash'
@classmethod
def from_yaml(cls, loader, node):
class MapValue(yaml.YAMLObject):
"""Class to process MapValue tag"""
- yaml_tag = u'!MapValue'
+ yaml_tag = '!MapValue'
@classmethod
def from_yaml(cls, loader, node):
assert val is not None, "Mandatory VALUE key isn't set"
assert val in mapping, \
'Value "{}" cannot be mapped to any of {} values'.format(
- val, mapping.keys())
+ val, list(mapping.keys()))
return mapping[val]
measurements.append((key, value))
if value.tag == Events.yaml_tag:
events.append((key, value))
- measurements_yaml = yaml.MappingNode(u'tag:yaml.org,2002:map',
+ measurements_yaml = yaml.MappingNode('tag:yaml.org,2002:map',
measurements)
measurements_stream = yaml.serialize(measurements_yaml)
- events_yaml = yaml.MappingNode(u'tag:yaml.org,2002:map', events)
+ events_yaml = yaml.MappingNode('tag:yaml.org,2002:map', events)
events_stream = yaml.serialize(events_yaml)
# return event & measurements definition
return events_stream, measurements_stream