Пример #1
0
    def __init__(self, counterSpec):
        t = ProvUtil.GetCounterSetting(counterSpec, 'type')
        if t is None:
            self._Type = 'builtin'
        else:
            self._Type = t.lower()
            if t != 'builtin':
                raise ProvUtil.UnexpectedCounterType(
                    'Expected type "builtin" but saw type "{0}"'.format(
                        self._Type))

        self._CounterClass = ProvUtil.GetCounterSetting(counterSpec,
                                                        'class').lower()
        if self._CounterClass not in _builtIns:
            raise ProvUtil.InvalidCounterSpecification(
                'Unknown Builtin class {0}'.format(self._CounterClass))
        self._Counter = ProvUtil.GetCounterSetting(counterSpec,
                                                   'counter').lower()
        if self._Counter not in _builtIns[self._CounterClass]:
            raise ProvUtil.InvalidCounterSpecification(
                'Counter {0} not in builtin class {1}'.format(
                    self._Counter, self._CounterClass))
        self._InstanceId = ProvUtil.GetCounterSetting(counterSpec,
                                                      'instanceId')
        self._Label = ProvUtil.GetCounterSetting(counterSpec,
                                                 'counterSpecifier')
        self._SampleRate = ProvUtil.GetCounterSetting(counterSpec,
                                                      'sampleRate')
Пример #2
0
    def __init__(self, counterSpec):
        """
        Construct an instance of the BuiltinMetric class. Values are case-insensitive unless otherwise noted.

        "type": the provider type. If present, must have value "builtin". If absent, assumed to be "builtin".
        "class": the name of the class within which this metric is scoped. Must be a key in the _builtIns dict.
        "counter": the name of the metric, within the class. Must appear in the list of metric names for this class
                found in the _builtIns dict. In this implementation, the builtin counter name is mapped to the OMI
                counter name
        "instanceId": the identifier for the specific instance of the metric, if any. Must be "None" for uninstanced
                metrics.
        "counterSpecifier": the name under which this retrieved metric will be stored
        "sampleRate": a string containing an ISO8601-compliant duration.

        :param counterSpec: A dict containing the key/value settings that define the metric to be collected.
        """
        t = ProvUtil.GetCounterSetting(counterSpec, 'type')
        if t is None:
            self._Type = 'builtin'
        else:
            self._Type = t.lower()
            if t != 'builtin':
                raise ProvUtil.UnexpectedCounterType(
                    'Expected type "builtin" but saw type "{0}"'.format(
                        self._Type))

        self._CounterClass = ProvUtil.GetCounterSetting(counterSpec, 'class')
        if self._CounterClass is None:
            raise ProvUtil.InvalidCounterSpecification(
                'Builtin metric spec missing "class"')
        self._CounterClass = self._CounterClass.lower()
        if self._CounterClass not in _builtIns:
            raise ProvUtil.InvalidCounterSpecification(
                'Unknown Builtin class {0}'.format(self._CounterClass))
        builtin_raw_counter_name = ProvUtil.GetCounterSetting(
            counterSpec, 'counter')
        if builtin_raw_counter_name is None:
            raise ProvUtil.InvalidCounterSpecification(
                'Builtin metric spec missing "counter"')
        builtin_counter_name = builtin_raw_counter_name.lower()
        if builtin_counter_name not in _builtIns[self._CounterClass]:
            raise ProvUtil.InvalidCounterSpecification(
                'Counter {0} not in builtin class {1}'.format(
                    builtin_raw_counter_name, self._CounterClass))
        self._Counter = _builtIns[self._CounterClass][builtin_counter_name]
        self._Condition = ProvUtil.GetCounterSetting(counterSpec, 'condition')
        self._Label = ProvUtil.GetCounterSetting(counterSpec,
                                                 'counterSpecifier')
        if self._Label is None:
            raise ProvUtil.InvalidCounterSpecification(
                'No counterSpecifier set for builtin {1} {0}'.format(
                    self._Counter, self._CounterClass))
        self._SampleRate = ProvUtil.GetCounterSetting(counterSpec,
                                                      'sampleRate')