def summary(self, gopts):
        """
        Return summary information as a list but no graph

        @param gopts: RRD graph options
        @return: values from the graph
        """
        gopts = fixMissingRRDs(gopts)
        # Change space to _ in RRD variable names
        def fixRRDvarName(gopt):
            if gopt.startswith('DEF'):
                # file name can have spaces, just not the RRD variables
                defparts = []
                defparts = gopt.split('=',2)
                defparts[0] = defparts[0].replace(' ','_')
                gopt = '='.join(defparts)
            else:
                gopt = gopt.replace(' ','_')
            return gopt
        gopts = map(fixRRDvarName,gopts)
        gopts.insert(0, '/dev/null') #no graph generated
        log.debug("RRD summary options: %r", (gopts,))
        try:
            @rrd_daemon_retry
            def rrdtool_fn():
                return rrdtool.graph(*(gopts+list(rrd_daemon_args())))[2]
            values = rrdtool_fn()
        except Exception, ex:
            if ex.args[0].find('No such file or directory') > -1:
                return None
            log.exception("Failed while generating summary")
            log.warn(" ".join(gopts))
            raise
예제 #2
0
    def summary(self, gopts):
        """
        Return summary information as a list but no graph

        @param gopts: RRD graph options
        @return: values from the graph
        """
        gopts = fixMissingRRDs(gopts)
        gopts.insert(0, '/dev/null') #no graph generated
        log.debug("RRD summary options: %r", (gopts,))
        try:
            @rrd_daemon_retry
            def rrdtool_fn():
                return rrdtool.graph(*(gopts+list(rrd_daemon_args())))[2]
            values = rrdtool_fn()
        except Exception, ex:
            if ex.args[0].find('No such file or directory') > -1:
                return None
            log.exception("Failed while generating summary")
            log.warn(" ".join(gopts))
            raise
예제 #3
0
    def summary(self, gopts):
        """
        Return summary information as a list but no graph

        @param gopts: RRD graph options
        @return: values from the graph
        """
        gopts = fixMissingRRDs(gopts)

        # Change space to _ in RRD variable names
        def fixRRDvarName(gopt):
            if gopt.startswith('DEF'):
                # file name can have spaces, just not the RRD variables
                defparts = []
                defparts = gopt.split('=', 2)
                defparts[0] = defparts[0].replace(' ', '_')
                gopt = '='.join(defparts)
            else:
                gopt = gopt.replace(' ', '_')
            return gopt

        gopts = map(fixRRDvarName, gopts)
        gopts.insert(0, '/dev/null')  #no graph generated
        log.debug("RRD summary options: %r", (gopts, ))
        try:

            @rrd_daemon_retry
            def rrdtool_fn():
                return rrdtool.graph(*(gopts + list(rrd_daemon_args())))[2]

            values = rrdtool_fn()
        except Exception, ex:
            if ex.args[0].find('No such file or directory') > -1:
                return None
            log.exception("Failed while generating summary")
            log.warn(" ".join(gopts))
            raise
예제 #4
0
    def render(self, gopts=None, start=None, end=None, drange=None,
               remoteUrl=None, width=None, ftype='PNG', getImage=True,
               graphid='', comment=None, ms=None, remoteHost=None, REQUEST=None, zenrenderRequest=None):
        """
        Render a graph and return it

        @param gopts: RRD graph creation options
        @param start: requested start of data to graph
        @param end: requested start of data to graph
        @param drange: min/max values of the graph
        @param remoteUrl: if the RRD is not here, where it lives -DEPRECATED use remoteHost instead
        @param width: size of graphic to create
        @param ftype: file type of graphic (eg PNG)
        @param getImage: return the graph or a script location
        @param graphid: (hopefully) unique identifier of a graph
        @param comment: RRD graph comment
        @param ms: a timestamp used to force IE to reload images
        @param remoteHost: Forward current RRD request to renderserver at remoteHost. eg http://remotezenrender:8091/
        @param REQUEST: URL-marshalled object containg URL options
        @return: graph or script location
        """
        # gopts may have repeated url quoting, possibly from multiple hops thru remote zenhubs
        # extra quoting will create invalid zlib padding characters ('%3D' instead of '=')
        for tries in range(3):
            try:
                gopts = zlib.decompress(urlsafe_b64decode(gopts))
            except Exception:
                gopts = urllib.unquote(gopts)
            else:
                break

        comment = urllib.unquote(comment) if comment is not None else ''

        gopts = gopts.split('|')
        gopts = fixMissingRRDs(gopts)
        gopts.append('HRULE:INF#00000000')
        gopts.append('--width=%s' % width)
        if start:
            gopts.append('--start=%s' % start)
        if end:
            gopts.append('--end=%s' % end)
        drange = int(drange)
        id = self.graphId(gopts, drange, ftype)
        graph = self.getGraph(id, ftype, REQUEST)
        if not graph:
            if not os.path.exists(self.tmpdir):
                os.makedirs(self.tmpdir, 0750)
            fd, filename = tempfile.mkstemp(dir=self.tmpdir, suffix=id)
            if remoteHost or remoteUrl:
                if remoteHost:
                    encodedOpts = urlsafe_b64encode(
                        zlib.compress('|'.join(gopts), 9))
                    params = {
                        'gopts': encodedOpts,
                        'drange': drange,
                        'width': width,
                    }
                    remote = "%s/render?%s" %(remoteHost, urlencode(params))
                else:
                    remote = remoteUrl
                f = open(filename, "w")
                response = urllib.urlopen(remote).read()
                f.write(response)
                f.close()
            else:
                if ftype.lower()=='html':
                    imgtype = 'PNG'
                else:
                    imgtype = ftype
                gopts.insert(0, "--imgformat=%s" % imgtype)
                #gopts.insert(0, "--lazy")
                end = int(time.time())-300
                start = end - drange
                if comment is not None:
                    gopts.insert(0, 'COMMENT:%s\\c' % comment)
                gopts.insert(0, '--end=%d' % end)
                gopts.insert(0, '--start=%d' % start)
                gopts.insert(0, filename)
                log.debug("RRD graphing options: %r", (gopts,))
                try:
                    @rrd_daemon_retry
                    def rrdtool_fn():
                        rrdtool.graph(*(gopts + list(rrd_daemon_args())))
                    rrdtool_fn()

                except Exception, ex:
                    if ex.args[0].find('No such file or directory') > -1:
                        return None
                    log.exception("Failed to generate a graph")
                    log.warn(" ".join(gopts))
                    return None

            self.addGraph(id, filename, fd)
            graph = self.getGraph(id, ftype, REQUEST)