Exemple #1
0
def hd():
    i = 0; 
    endtimet = datetime.datetime.now()
    starttimet =  endtimet - datetime.timedelta(days=1)

    endtime = epoch(endtimet)
    starttime = epoch(starttimet)

    print starttime
    Loop = True

    while(Loop==True):
        if starttime < endtime:
            namerrd = "hd.rrd"
            #pathfile =  os.path.join(folder,namerrd)
            a = random.randint(0,100)
            b = random.randint(0,100)

            if not os.path.exists(namerrd):
                print create(namerrd,[swapusage,hdusage],starttime,'hardware')
            else:
                starttime = starttime + 5
                print starttime
                print update(namerrd,[a,b],starttime)
        else:
            Loop = False
Exemple #2
0
def ram():
    i = 0; 
    endtimet = datetime.datetime.now()
    starttimet =  endtimet - datetime.timedelta(hours=1)

    endtime = epoch(endtimet)
    starttime = epoch(starttimet)
    
    print starttime
    Loop = True
    count = 0 
    
    while(Loop==True):
        count = count +1
        if starttime < endtime:
            namerrd = "ram.rrd"
            #pathfile =  os.path.join(folder,namerrd)
            a = random.randint(0,100)
            if not os.path.exists(namerrd):
                print create(namerrd,[usedram],starttime,'hardware')
            else:
                starttime = starttime + 5
                print a
                update(namerrd,[a],starttime)
        else:
            Loop = False
        
        if count == 120:
            Loop = False 
            
    print starttime
Exemple #3
0
 def __init__(self, filename=None, start=None, step=300, ds=None, rra=None,
              mode="w", backend=external):
     super(RRD, self).__init__()
     if filename == None:
         raise ValueError("You must provide a filename.")
     self.filename = filename
     if not start or isinstance(start, datetime):
         self.start = util.epoch(start)
     else:
         self.start = start
     if not ds:
         ds = []
     if not rra:
         rra = []
     self.ds = ds
     self.rra = rra
     self.values = []
     self.step = step
     self.lastupdate = None
     self.mode = mode
     # the backend attribute needs to be defined before the load call, since
     # the load method (super class) expects the backend attribute
     self.backend = backend
     if self.mode == "r":
         self.load()
Exemple #4
0
 def __init__(self, filename=None, start=None, step=300, ds=None, rra=None,
              mode="w", backend=external):
     super(RRD, self).__init__()
     if filename == None:
         raise ValueError, "You must provide a filename."
     self.filename = filename
     if not start or isinstance(start, datetime):
         self.start = util.epoch(start)
     else:
         self.start = start
     if not ds:
         ds = []
     if not rra:
         rra = []
     self.ds = ds
     self.rra = rra
     self.values = []
     self.step = step
     self.lastupdate = None
     self.mode = mode
     # the backend attribute needs to be defined before the load call, since
     # the load method (super class) expects the backend attribute
     self.backend = backend
     if self.mode == "r":
         self.load()
Exemple #5
0
def created_or_update(namerrd, fieldname, vals, typeofinfo):
    
    try: 
        namerrd = '%s.rrd' %namerrd 
        
        filename = os.path.join(REPORT_PATH_DATA,namerrd)
        
        starttime = epoch(datetime.datetime.now())
    
        if (os.path.exists(filename)):
            return update(filename,vals,starttime)
    
        else:
            # Note we can't update the time when we try created
            (result,error) = create(filename, fieldname, starttime,typeofinfo)
            return (result,error)
        
    except Exception,ex: 
        print "Error Info :reportrrd at method created_or_update : %s " %(ex)
        return (False,str(ex))
Exemple #6
0
def create_graph(types,typetime):
    
    try:
        typofinfo = "hardware"
        #_months
        #types = ['cpu*cpu','ram']
        #typetime = 'weeks'
        ''' list of path of image '''
        lst = []
        
        ca = set_color()
        # For Testing i disable end time and us
        end = datetime.datetime.now()
        start = get_starttime(typetime,end)
         
        '''
        
        '''
        xaxis = get_x_axis(typetime)
        starttime = epoch(start)
        endtime = epoch(end)
        
        print "type time %s" %str(typetime)        
        print "start time %s " %(starttime)
        print "end time %s " %(endtime)
        print "types %s" %(types) 
        
        # end temp here
        for kind in types:
            lstinfo =  kind.split('|') 
            
            # file name of rrd.
            filename = rrd_info.get_filename(lstinfo[0])
            
            print "File name rrd %s " %(filename)
             
            ''' 
            Get resolution for daily,month,year,week
            '''
            dict = {}
            if rrd_info.config_info.has_key(lstinfo[2]):
                dict = rrd_info.config_info[lstinfo[2]]
        
            steps = dict[typetime] 

            # Check the file rrd is existed or not.
            if os.path.exists(filename) :
                
                if  func.has_key(lstinfo[2]):
                    s = func[lstinfo[2]]
                    funcProfile = globals()[s]
                    
                    header = get_header(lstinfo[0], typetime,start,end)
                    
                    namepic = funcProfile(lstinfo[0],starttime,endtime,steps,xaxis,header,ca,lstinfo[1].split('*'))
                    
                    if namepic != "" :
                        if namepic.startswith(url_pic): 
                            lst.append(namepic)
            else :
                print "File %s is not existed." %(filename) 
                
        return lst
    
    except utils.UIException,e:
        print "Error Info : At method create_graph %s " %str(e)
        return "Error Info : %s" %e