Exemple #1
0
                def rrdtool_fn():
                    try:
                        values.append(rrdtool.fetch(
                            path, cf, "-r %d" % resolution,
                            "-s %s" % start, "-e %s" % end,
                            *rrd_daemon_args()))

                    except rrdtool.error, ex:
                        if 'No such file or directory' in ex.message:
                            values.append(None)
                        else:
                            raise
def basicArgs(env):
    args = ['--imgformat=PNG',
            '--start=%(start)s' % env,
            '--end=%(end)s' % env,
            '--title=%(title)s' % env,
            '--height=%(height)s' % env,
            '--width=%(width)s' % env,
            '--vertical-label=%(label)s' % env]
    daemon_args = rrd_daemon_args()
    if daemon_args:
        args.append('='.join(daemon_args))
    return args
def basicArgs(env):
    args = [
        '--imgformat=PNG',
        '--start=%(start)s' % env,
        '--end=%(end)s' % env,
        '--title=%(title)s' % env,
        '--height=%(height)s' % env,
        '--width=%(width)s' % env,
        '--vertical-label=%(label)s' % env
    ]
    daemon_args = rrd_daemon_args()
    if daemon_args:
        args.append('='.join(daemon_args))
    return args
 def rrdtool_fn():
     daemon_args = rrd_daemon_args() if useRRDDaemon else tuple()
     return rrdtool.fetch(filename, 'AVERAGE',
                         '-s', 'now-%d' % (cycleTime*2),
                         '-e', 'now', *daemon_args)
    def put(self, path, value, rrdType, rrdCommand=None, cycleTime=None,
             min='U', max='U', useRRDDaemon=True, timestamp='N', start=None,
             allowStaleDatapoint=True):
        """
        Save the value provided in the command to the RRD file specified in path.

        If the RRD file does not exist, use the rrdType, rrdCommand, min and
        max parameters to create the file.

        @param path: name for a datapoint in a path (eg device/component/datasource_datapoint)
        @type path: string
        @param value: value to store into the RRD file
        @type value: number
        @param rrdType: RRD data type (eg ABSOLUTE, DERIVE, COUNTER)
        @type rrdType: string
        @param rrdCommand: RRD file creation command
        @type rrdCommand: string
        @param cycleTime: length of a cycle
        @type cycleTime: number
        @param min: minimum value acceptable for this metric
        @type min: number
        @param max: maximum value acceptable for this metric
        @type max: number
        @param allowStaleDatapoint: attempt to write datapoint even if a newer datapoint has already been written
        @type allowStaleDatapoint: boolean
        @return: the parameter value converted to a number
        @rtype: number or None
        """
        if value is None: return None

        self.dataPoints += 1
        self.cycleDataPoints += 1

        if cycleTime is None:
            cycleTime = self.defaultCycleTime

        filename = self.performancePath(path) + '.rrd'
        if not rrdCommand:
            rrdCommand = self.defaultRrdCreateCommand
        if not os.path.exists(filename):
            log.debug("Creating new RRD file %s", filename)
            dirname = os.path.dirname(filename)
            if not os.path.exists(dirname):
                os.makedirs(dirname, 0750)

            min, max = map(_checkUndefined, (min, max))
            dataSource = 'DS:%s:%s:%d:%s:%s' % (
                'ds0', rrdType, self.getHeartbeat(cycleTime), min, max)
            args = [str(filename), "--step",
                str(self.getStep(cycleTime)),]
            if start is not None:
                args.extend(["--start", "%d" % start])
            elif timestamp != 'N':
                args.extend(["--start", str(int(timestamp) - 10)])

            args.append(str(dataSource))
            args.extend(rrdCommand.split())
            rrdtool.create(*args),

        daemon_args = rrd_daemon_args() if useRRDDaemon else tuple()

        # remove unwanted chars (this is actually pretty quick)
        value = str(value).translate(None, _UNWANTED_CHARS)

        if rrdType in ('COUNTER', 'DERIVE'):
            try:
                # cast to float first because long('100.0') will fail with a
                # ValueError
                value = long(float(value))
            except (TypeError, ValueError):
                return None
        else:
            try:
                value = float(value)
            except (TypeError, ValueError):
                return None
        try:
            @rrd_daemon_retry
            def rrdtool_fn():
                return rrdtool.update(str(filename), *(daemon_args + ('%s:%s' % (timestamp, value),)))
            if timestamp == 'N' or allowStaleDatapoint:
                rrdtool_fn()
            else:
                # try to detect when the last datasample was collected
                lastTs = _LAST_RRDFILE_WRITE.get(filename, None)
                if lastTs is None:
                    try:
                        lastTs = _LAST_RRDFILE_WRITE[filename] = rrdtool.last(
                            *(daemon_args + (str(filename),)))
                    except Exception as ex:
                         lastTs = 0
                         log.exception("Could not determine last update to %r", filename)
                # if the current datapoint is newer than the last datapoint, then write
                if lastTs < timestamp:
                    _LAST_RRDFILE_WRITE[filename] = timestamp
                    if log.getEffectiveLevel() < logging.DEBUG:
                        log.debug('%s: %r, currentTs = %s, lastTs = %s', filename, value, timestamp, lastTs)
                    rrdtool_fn()
                else:
                    if log.getEffectiveLevel() < logging.DEBUG:
                        log.debug("ignoring write %s:%s", filename, timestamp)
                    return None

            log.debug('%s: %r, @ %s', str(filename), value, timestamp)
        except rrdtool.error, err:
            # may get update errors when updating too quickly
            log.error('rrdtool reported error %s %s', err, path)
 def rrdtool_fn():
     return rrdtool.fetch(path, consolidationFunction, start, end, *rrd_daemon_args())
 def rrdtool_fn():
     return rrdtool.fetch(self.context().path(dp),
         'AVERAGE', '-s', 'now-%d' % (cycleTime*2), '-e', 'now',
         *rrd_daemon_args())
 def rrdtool_fn():
     return rrdtool.info(self.context().path(dp), *rrd_daemon_args())
Exemple #9
0
 def rrdtool_fn():
     return rrdtool.graph(*(gopts+list(rrd_daemon_args())))
Exemple #10
0
 def rrdtool_fn():
     return rrdtool.info(p, *rrd_daemon_args())
Exemple #11
0
 def rrdtool_fn():
     return rrdtool.fetch(self.context().path(dp), 'AVERAGE', '-s',
                          'now-%d' % (cycleTime * 2), '-e', 'now',
                          *rrd_daemon_args())
Exemple #12
0
 def rrdtool_fn():
     return rrdtool.info(self.context().path(dp), *rrd_daemon_args())