Ejemplo n.º 1
0
    def afterSetUp(self):
        super(TestRRDImpl, self).afterSetUp()

        # Make a valid test device
        testdev = str(self.__class__.__name__)
        self.name = testdev
        self.createFakeDevice( testdev )

        self.zem = self.dmd.ZenEventManager

        # We're not connected to zenhub so the following
        # always will be None
        perfServer = self.dev.getPerformanceServer()
        if perfServer:
            self.defrrdcmd= perfServer.getDefaultRRDCreateCommand()
        else:
            # We will always use this :(
            self.defrrdcmd= 'RRA:AVERAGE:0.5:1:600\nRRA:AVERAGE:0.5:6:600\nRRA:AVERAGE:0.5:24:600\nRRA:AVERAGE:0.5:288:600\nRRA:MAX:0.5:6:600\nRRA:MAX:0.5:24:600\nRRA:MAX:0.5:288:600'

        # default RRD create command, cycle interval
        rrd= RRDUtil( self.defrrdcmd, 60 )

        # Save the following info for our tearDown() script
        self.perfpath= rrd.performancePath( "tests" )
        self.dev.rrdPath= lambda: "tests"
Ejemplo n.º 2
0
def run(args, processId):
  try:
    perfPath = "/".join([args.perf_path, str(processId)])
    
    create_cmd = 'RRA:AVERAGE:0.5:1:600\nRRA:AVERAGE:0.5:6:600\nRRA:AVERAGE:0.5:24:600\nRRA:AVERAGE:0.5:288:600\nRRA:MAX:0.5:6:600\nRRA:MAX:0.5:24:600\nRRA:MAX:0.5:288:600'
    rrd = RRDUtil(create_cmd, args.cycle_time)
    
    
    cycle_begin = time()
    dp_count = 0
    for device in map(str, range(args.device_count)):
        begin = time()
        for device_dp in map(str, range(args.device_datapoints)):
            dp_count += 1
            rrd.save(os.path.join(perfPath, device, device_dp), 42, 'GAUGE')

        for interface in map(str, range(args.component_count)):
            for interface_dp in map(str, range(args.component_datapoints)):
                dp_count += 1
                path = os.path.join(perfPath, device, 'os', 'interfaces', interface,
                    interface_dp)
                rrd.save(path, 42, 'DERIVE')
                rrdtool.fetch(rrd.performancePath(path) + '.rrd',
                    'AVERAGE', '-s', 'now-%d' % (args.cycle_time*2), '-e', 'now')

    cycle_duration = time() - cycle_begin
    return (cycle_duration, dp_count)
  except KeyboardInterrupt:
    return (0, 0)
Ejemplo n.º 3
0
    def afterSetUp(self):
        super(TestRRDImpl, self).afterSetUp()

        # Make a valid test device
        testdev = str(self.__class__.__name__)
        self.name = testdev
        self.createFakeDevice(testdev)

        self.zem = self.dmd.ZenEventManager

        # We're not connected to zenhub so the following
        # always will be None
        perfServer = self.dev.getPerformanceServer()
        if perfServer:
            self.defrrdcmd = perfServer.getDefaultRRDCreateCommand()
        else:
            # We will always use this :(
            self.defrrdcmd = 'RRA:AVERAGE:0.5:1:600\nRRA:AVERAGE:0.5:6:600\nRRA:AVERAGE:0.5:24:600\nRRA:AVERAGE:0.5:288:600\nRRA:MAX:0.5:6:600\nRRA:MAX:0.5:24:600\nRRA:MAX:0.5:288:600'

        # default RRD create command, cycle interval
        rrd = RRDUtil(self.defrrdcmd, 60)

        # Save the following info for our tearDown() script
        self.perfpath = rrd.performancePath("tests")
        self.dev.rrdPath = lambda: "tests"
Ejemplo n.º 4
0
    def testNotWritableRRD(self):
        """
        Can't write to a file
        """
        # Verify that we're not root first...
        if os.geteuid() == 0:
            print "Can't run testNotWritableRRD check if running as root"
            return

        rrd = RRDUtil(self.createcmd, 60)

        rrd.performancePath = lambda (x): "/"
        self.assertRaises(Exception, rrd.save, "/", 666.0, 'COUNTER')
Ejemplo n.º 5
0
    def testNotWritableRRD(self):
        """
        Can't write to a file
        """
        # Verify that we're not root first...
        if os.geteuid() == 0:
            print "Can't run testNotWritableRRD check if running as root"
            return

        rrd= RRDUtil( self.createcmd, 60 )

        rrd.performancePath= lambda(x): "/"
        self.assertRaises( Exception, rrd.save, "/", 666.0, 'COUNTER' )
Ejemplo n.º 6
0
    def afterSetUp(self):
        super(TestRRDUtil, self).afterSetUp()

        # Make a valid test device
        testdev = str(self.__class__.__name__)

        self.name = testdev

        # name, path, dataStorageType, rrdCreateCommand, minmax
        self.path = os.path.join("tests", testdev)

        self.dev = self.dmd.Devices.createInstance(testdev)

        #createcmd= self.dmd.Devices.findDevice(testdev).getPerformanceServer().getDefaultRRDCreateCommand()
        self.createcmd = 'RRA:AVERAGE:0.5:1:600\nRRA:AVERAGE:0.5:6:600\nRRA:AVERAGE:0.5:24:600\nRRA:AVERAGE:0.5:288:600\nRRA:MAX:0.5:6:600\nRRA:MAX:0.5:24:600\nRRA:MAX:0.5:288:600'

        rrd = RRDUtil('', 60)
        self.perfpath = rrd.performancePath("tests")
Ejemplo n.º 7
0
    def afterSetUp(self):
        super(TestRRDUtil, self).afterSetUp()

        # Make a valid test device
        testdev = str(self.__class__.__name__)

        self.name = testdev

        # name, path, dataStorageType, rrdCreateCommand, minmax
        self.path= os.path.join( "tests", testdev )

        self.dev = self.dmd.Devices.createInstance(testdev)

        #createcmd= self.dmd.Devices.findDevice(testdev).getPerformanceServer().getDefaultRRDCreateCommand()
        self.createcmd= 'RRA:AVERAGE:0.5:1:600\nRRA:AVERAGE:0.5:6:600\nRRA:AVERAGE:0.5:24:600\nRRA:AVERAGE:0.5:288:600\nRRA:MAX:0.5:6:600\nRRA:MAX:0.5:24:600\nRRA:MAX:0.5:288:600'

        rrd= RRDUtil( '', 60 )
        self.perfpath= rrd.performancePath( "tests" )
Ejemplo n.º 8
0
    def testLowLevelFuncs(self):
        """
        Verify info function succeeds.
        """
        rrd = RRDUtil(self.createcmd, 60)
        path = os.path.join(self.path, "%f" % random())

        # setup RRD file, add values to it
        startTime = time.time() - 10 * 60
        for i in range(0, 10):
            rrd.save(path,
                     i * 100,
                     'COUNTER',
                     useRRDDaemon=False,
                     timestamp=int(startTime + i * 60),
                     start=startTime)

        # check info function
        import rrdtool
        filename = rrd.performancePath(path) + '.rrd'
        info = rrdtool.info(filename)

        self.assertEquals(info['ds[ds0].index'], 0L)
        # self.assertEquals(info['ds[ds0].last_ds'], '90.0')
        self.assertEquals(info['ds[ds0].max'], None)
        self.assertEquals(info['ds[ds0].min'], None)
        self.assertEquals(info['ds[ds0].minimal_heartbeat'], 180L)
        self.assertEquals(info['ds[ds0].type'], 'COUNTER')

        # test fetch
        data = rrdtool.fetch(filename, 'AVERAGE', '--start', "%d" % startTime)

        # check the middle of the fetch for 1.7/s rate
        self.failUnlessAlmostEqual(data[2][2][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][3][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][4][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][5][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][6][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][7][0], 1.7, places=1)

        # test fetch, with daemon pointing to bad socket file
        self.assertRaises(rrdtool.error, rrdtool.fetch, filename, 'AVERAGE',
                          '--start', "%d" % startTime, '--daemon'
                          '/tmp/blah')

        # test graph
        imFile = rrd.performancePath(path) + ".png"
        rrdtool.graph(
            imFile,
            "-w",
            "400",
            "-h",
            "100",
            "--full-size-mode",
            "DEF:ds0a=%s:ds0:AVERAGE" % filename,
            "LINE1:ds0a#0000FF:'default'",
        )

        def readPNGsize(fname):
            """
            PNG spec defines 16-byte header, followed by width and height as
            unsigned 4-byte integers.
            """
            import struct
            with open(fname, "rb") as pngfile:
                first24 = pngfile.read(24)
                sizebytes = first24[-8:]
                width, height = struct.unpack_from(">II", sizebytes)
                return width, height

        self.assertEquals(readPNGsize(imFile), (400, 100))
Ejemplo n.º 9
0
    def testLowLevelFuncs(self):
        """
        Verify info function succeeds.
        """
        rrd= RRDUtil( self.createcmd, 60 )
        path= os.path.join( self.path, "%f" % random() )

        # setup RRD file, add values to it
        startTime = time.time() - 10 * 60
        for i in range (0, 10):
            rrd.save( path, i * 100, 'COUNTER', useRRDDaemon=False, timestamp=int(startTime+i*60), start=startTime)

        # check info function
        import rrdtool
        filename = rrd.performancePath(path) + '.rrd'
        info = rrdtool.info(filename)

        self.assertEquals(info['ds[ds0].index'], 0L)
        # self.assertEquals(info['ds[ds0].last_ds'], '90.0')
        self.assertEquals(info['ds[ds0].max'], None)
        self.assertEquals(info['ds[ds0].min'], None)
        self.assertEquals(info['ds[ds0].minimal_heartbeat'], 180L)
        self.assertEquals(info['ds[ds0].type'], 'COUNTER')

        # test fetch
        data = rrdtool.fetch(filename, 'AVERAGE', '--start', "%d" % startTime)

        # check the middle of the fetch for 1.7/s rate
        self.failUnlessAlmostEqual(data[2][2][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][3][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][4][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][5][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][6][0], 1.7, places=1)
        self.failUnlessAlmostEqual(data[2][7][0], 1.7, places=1)

        # test fetch, with daemon pointing to bad socket file
        self.assertRaises(rrdtool.error, rrdtool.fetch, filename, 'AVERAGE', '--start', "%d" % startTime, '--daemon' '/tmp/blah')

        # test graph
        imFile = rrd.performancePath(path) + ".png"
        rrdtool.graph(imFile,
            "-w", "400",
            "-h", "100",
            "--full-size-mode",
            "DEF:ds0a=%s:ds0:AVERAGE" % filename,
            "LINE1:ds0a#0000FF:'default'",
        )

        def readPNGsize(fname):
            """
            PNG spec defines 16-byte header, followed by width and height as
            unsigned 4-byte integers.
            """
            import struct
            with open(fname, "rb") as pngfile:
                first24 = pngfile.read(24)
                sizebytes = first24[-8:]
                width,height = struct.unpack_from(">II",sizebytes)
                return width,height

        self.assertEquals(readPNGsize(imFile), (400, 100))