Пример #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 sample_rate(self):
     """
     Determine how often this metric should be retrieved. If the metric didn't define a sample period, return the
     default.
     :return int: Number of seconds between collecting samples of this metric.
     """
     if self._SampleRate is None:
         return _defaultSampleRate
     else:
         return ProvUtil.IntervalToSeconds(self._SampleRate)
Пример #3
0
    def _update_metric_collection_settings(self, ladCfg):
        """
        Update mdsd_config_xml_tree for Azure Portal metric collection. The mdsdCfg performanceCounters element contains
        an array of metric definitions; this method passes each definition to its provider's AddMetric method, which is
        responsible for configuring the provider to deliver the metric to mdsd and for updating the mdsd config as
        required to expect the metric to arrive. This method also builds the necessary aggregation queries (from the
        metrics.metricAggregation array) that grind the ingested data and push it to the WADmetric table.
        :param ladCfg: ladCfg object from extension config
        :return: None
        """
        metrics = LadUtil.getPerformanceCounterCfgFromLadCfg(ladCfg)
        if not metrics:
            return

        counter_to_table = {}
        local_tables = set()

        # Add each metric
        for metric in metrics:
            if metric['type'] == 'builtin':
                local_table_name = BuiltIn.AddMetric(metric)
                if local_table_name:
                    local_tables.add(local_table_name)
                    counter_to_table[
                        metric['counterSpecifier']] = local_table_name

        # Finalize; update the mdsd config to be prepared to receive the metrics
        BuiltIn.UpdateXML(self._mdsd_config_xml_tree)

        # Aggregation is done by <LADQuery> within a <DerivedEvent>. If there are no alternate sinks, the DerivedQuery
        # can send output directly to the WAD metrics table. If there *are* alternate sinks, have the LADQuery send
        # output to a new local table, then arrange for additional derived queries to pull from that.
        intervals = LadUtil.getAggregationPeriodsFromLadCfg(ladCfg)
        sinks = LadUtil.getFeatureWideSinksFromLadCfg(ladCfg,
                                                      'performanceCounters')
        for table_name in local_tables:
            for aggregation_interval in intervals:
                if sinks:
                    local_table_name = ProvUtil.MakeUniqueEventName(
                        'aggregationLocal')
                    self._add_derived_event(aggregation_interval,
                                            table_name,
                                            local_table_name,
                                            'Local',
                                            add_lad_query=True)
                    self._handle_alternate_sinks(aggregation_interval, sinks,
                                                 local_table_name)
                else:
                    self._add_derived_event(
                        aggregation_interval,
                        table_name,
                        LadConfigAll._wad_table_name(aggregation_interval),
                        'Central',
                        add_lad_query=True)
Пример #4
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.
        "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').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')
Пример #5
0
def AddMetric(counterSpec):
    try:
        metric = BuiltinMetric(counterSpec)
    except ProvUtil.ParseException as ex:
        print "Couldn't create metric: ", ex
        return

    # (class, instanceId, sampleRate) -> [ metric ]
    # Given a class, instance within that class, and sample rate, we have a list of the requested metrics
    # matching those constraints. For that set of constraints, we also have a common eventName, the local
    # table where we store the collected metrics.

    key = (metric.Class(), metric.InstanceId(), metric.SampleRate())
    if key not in _eventNames:
        _eventNames[key] = ProvUtil.MakeUniqueEventName('builtin')
    _metrics[key].append(metric)
Пример #6
0
def AddMetric(counter_spec):
    """
    Add a metric to the list of metrics to be collected.
    :param counter_spec: The specification of a builtin metric.
    :return: the generated local-table name in mdsd into which this metric will be fetched, or None
    """
    global _metrics, _eventNames
    try:
        metric = BuiltinMetric(counter_spec)
    except ProvUtil.ParseException as ex:
        print "Couldn't create metric: ", ex
        return None

    # (class, instanceId, sampleRate) -> [ metric ]
    # Given a class, instance within that class, and sample rate, we have a list of the requested metrics
    # matching those constraints. For that set of constraints, we also have a common eventName, the local
    # table where we store the collected metrics.

    key = (metric.class_name(), metric.condition(), metric.sample_rate())
    if key not in _eventNames:
        _eventNames[key] = ProvUtil.MakeUniqueEventName('builtin')
    _metrics[key].append(metric)
    return _eventNames[key]
    def _update_metric_collection_settings(self, ladCfg, namespaces):
        """
        Update mdsd_config_xml_tree for Azure Portal metric collection. This method builds the necessary aggregation queries
        that grind the ingested data and push it to the WADmetric table.
        :param ladCfg: ladCfg object from extension config
        :param namespaces: list of telegraf plugins sources obtained after parsing lad metrics config
        :return: None
        """

        # Aggregation is done by <LADQuery> within a <DerivedEvent>. If there are no alternate sinks, the DerivedQuery
        # can send output directly to the WAD metrics table. If there *are* alternate sinks, have the LADQuery send
        # output to a new local table, then arrange for additional derived queries to pull from that.

        intervals = LadUtil.getAggregationPeriodsFromLadCfg(ladCfg)
        sinks = LadUtil.getFeatureWideSinksFromLadCfg(ladCfg,
                                                      'performanceCounters')
        for plugin in namespaces:
            lad_specific_storage_plugin = "storage-" + plugin
            for aggregation_interval in intervals:
                if sinks:
                    local_table_name = ProvUtil.MakeUniqueEventName(
                        'aggregationLocal')
                    self._add_derived_event(aggregation_interval,
                                            lad_specific_storage_plugin,
                                            local_table_name,
                                            'Local',
                                            add_lad_query=True)
                    self._handle_alternate_sinks(aggregation_interval, sinks,
                                                 local_table_name)
                else:
                    self._add_derived_event(
                        aggregation_interval,
                        lad_specific_storage_plugin,
                        LadConfigAll._wad_table_name(aggregation_interval),
                        'Central',
                        add_lad_query=True)
Пример #8
0
 def SampleRate(self):
     if self._SampleRate is None:
         return _defaultSampleRate
     else:
         return ProvUtil.IntervalToSeconds(self._SampleRate)