コード例 #1
0
    def params(cls, datasource, context):
        targetInfos = []
        # add an id->contents map for each component/device
        for member in dotTraverse(context, datasource.targetMethod or '') or []:
            targetInfos.append(targetInfo(member))

        targetArgValues = []
        for datapoint in datasource.datapoints():
            if isinstance(datapoint, AggregatingDataPoint):
                for att in getVarNames(datapoint.arguments.strip()):
                    targetArgValues.append(dotTraverse(context, att))
            else:
                log.error("datasource %s has a datapoint of the wrong type %s" % (datasource, datapoint))

            # should be only datapoint, so ...
            break

        zDebug = context.getZ('zDatasourceDebugLogging')
        return dict(
            targetDatapoints = [(datasource.targetDataSource, datasource.targetDataPoint,
                                 datasource.targetRRA or 'AVERAGE')],
            targetArgValues=[tuple(targetArgValues)],
            targets=targetInfos,
            debug=datasource.debug or zDebug
        )
    def getTargetCycleTime(self, context):
        """Return cycletime of basis datasources."""
        for member in dotTraverse(context, self.targetMethod or '') or []:
            for template in member.getRRDTemplates():
                datasource = template.datasources._getOb(
                    self.targetDataSource, None)

                if datasource:
                    if datasource.aqBaseHasAttr("getCycleTime"):
                        return int(datasource.getCycleTime(member))
                    elif datasource.aqBaseHasAttr("cycletime"):
                        return int(datasource.cycletime)
コード例 #3
0
    def params(cls, datasource, context):
        zDebug = context.getZ('zDatasourceDebugLogging')
        config = {
            'targets': [targetInfo(context)],
            'expression': datasource.expression,
            'debug': datasource.debug or zDebug,
            'template': datasource.rrdTemplate().getPrimaryId()
        }

        attrs = {}
        targetDataPoints = []

        allDatapointsByVarName = {}
        for dp in context.getRRDDataPoints():
            allDatapointsByVarName[dp.id] = dp
            allDatapointsByVarName[dp.name()] = dp

        for att in getVarNames(datasource.expression):

            if att in allDatapointsByVarName:
                datapoint = allDatapointsByVarName[att]
                targetDataPoints.append((datapoint.datasource().id, datapoint.id, 'AVERAGE'))
            else:
                value = dotTraverse(context, att)
                if not CalculatedDataSourcePlugin.isPicklable(value):
                    log.error("Calculated Performance expression %s references "
                        "invalid attribute (unpicklable value) %s" %(datasource.expression, att))
                    return config
                attrs[att] = value
                if value is None:
                    log.warn(
                        "Calculated Performance expression %s references "
                        "the variable %s which is not in %s" % (
                            datasource.expression, att, allDatapointsByVarName.keys()))

        config['obj_attrs'] = attrs
        config['targetDatapoints'] = targetDataPoints
        return config
コード例 #4
0
    def params(cls, datasource, context):
        zDebug = context.getZ('zDatasourceDebugLogging')
        config = {
            'expression': datasource.expression,
            'debug': datasource.debug or zDebug,
            'template': datasource.rrdTemplate().getPrimaryId()}

        attrs = {}
        targetDatapoints = {}

        # Keep track of all datapoints from all targets so we can avoid
        # looking for an attribute when we have found a datapoint by name on
        # an earlier target already.
        combinedDatapoints = {}

        # extraContents can contain paths to other objects that could have
        # metrics or attributes.
        allTargets = getExtraTargets(datasource.extraContexts, context)
        allTargets.append(context)

        # count down to the last target
        hasMore = len(allTargets)

        for target in allTargets:
            hasMore -= 1

            allDatapointsByVarName = {}
            for dp in target.getRRDDataPoints():
                allDatapointsByVarName[dp.id] = dp
                allDatapointsByVarName[dp.name()] = dp
            combinedDatapoints.update(allDatapointsByVarName)

            for att in getVarNames(datasource.expression):

                if att in allDatapointsByVarName:
                    datapoint = allDatapointsByVarName[att]
                    fqdpn = '%s_%s' % (datapoint.datasource().id, datapoint.id)
                    targetDatapoints[fqdpn] = (
                        datapoint.datasource().id,
                        datapoint.id,
                        'AVERAGE',
                        datasource.targetAsRate,
                        [targetInfo(target)])

                elif att not in combinedDatapoints:
                    value = dotTraverse(target, att)
                    if not CalculatedDataSourcePlugin.isPicklable(value):
                        LOG.error(
                            "Calculated Performance expression %s references "
                            "invalid attribute (unpicklable value) %s",
                            datasource.expression, att)
                        return config

                    # Only store None if we finished and never found
                    # a more interesting value.
                    if value is not None:
                        attrs[att] = value
                    elif att not in attrs and not hasMore:
                        attrs[att] = value
                        LOG.warn(
                            "Calculated Performance expression %s references "
                            "the variable %s which is not in %s on the targets %s",
                            datasource.expression, att,
                            combinedDatapoints.keys(), allTargets)

        config['obj_attrs'] = attrs
        config['targetDatapoints'] = targetDatapoints.values()

        return config