def getDiskSpace(self): """Obtains the disk space used. """ result = S_OK() diskSpace = getDiskSpace() if diskSpace == -1: result = S_ERROR('Could not obtain disk usage') self.log.warn('Could not obtain disk usage') result['Value'] = -1 result['Value'] = float(diskSpace) return result
def getDiskSpace(self, exclude=None): """Obtains the disk space used. """ result = S_OK() diskSpace = getDiskSpace(exclude=exclude) if diskSpace == -1: result = S_ERROR('Could not obtain disk usage') self.log.warn(' Could not obtain disk usage') else: result['Value'] = float(diskSpace) return result
def export_getAdminInfo(): """ Send the storage element administration information """ storageDict = {} storageDict['BasePath'] = BASE_PATH storageDict['MaxCapacity'] = MAX_STORAGE_SIZE used_space = getDirectorySize(BASE_PATH) available_space = getDiskSpace(BASE_PATH) allowed_space = MAX_STORAGE_SIZE - used_space actual_space = min(available_space, allowed_space) storageDict['AvailableSpace'] = actual_space storageDict['UsedSpace'] = used_space return S_OK(storageDict)
def export_getAdminInfo(): """ Send the storage element administration information """ storageDict = {} storageDict['BasePath'] = BASE_PATH storageDict['MaxCapacity'] = MAX_STORAGE_SIZE used_space = getDirectorySize( BASE_PATH ) available_space = getDiskSpace( BASE_PATH ) allowed_space = MAX_STORAGE_SIZE - used_space actual_space = min( available_space, allowed_space ) storageDict['AvailableSpace'] = actual_space storageDict['UsedSpace'] = used_space return S_OK( storageDict )
def getDiskSpace(self): """Obtains the disk space used. """ result = S_OK() diskSpace = getDiskSpace() if diskSpace == -1: result = S_ERROR('Could not obtain disk usage') self.log.warn(' Could not obtain disk usage') result['Value'] = -1 result['Value'] = float(diskSpace) return result
def getDiskSpace(self, exclude=None): """Obtains the available disk space.""" result = S_OK() diskSpace = getDiskSpace(exclude=exclude) if diskSpace == -1: result = S_ERROR("Could not obtain disk usage") self.log.warn(" Could not obtain disk usage") result["Value"] = float(-1) return result result["Value"] = float(diskSpace) return result
def export_getAdminInfo(self): """ Send the storage element administration information """ storageDict = {} storageDict['BasePath'] = base_path storageDict['MaxCapacity'] = max_storage_size used_space = getDirectorySize(base_path) available_space = getDiskSpace(base_path) allowed_space = max_storage_size - used_space actual_space = min(available_space, allowed_space) storageDict['AvailableSpace'] = actual_space storageDict['UsedSpace'] = used_space return S_OK(storageDict)
def export_getAdminInfo( self ): """ Send the storage element administration information """ storageDict = {} storageDict['BasePath'] = base_path storageDict['MaxCapacity'] = max_storage_size used_space = getDirectorySize( base_path ) available_space = getDiskSpace( base_path ) allowed_space = max_storage_size - used_space actual_space = min( available_space, allowed_space ) storageDict['AvailableSpace'] = actual_space storageDict['UsedSpace'] = used_space return S_OK( storageDict )
def __checkDiskSpace( self, totalSize ): """Compare available disk space to the file size reported from the catalog result. """ diskSpace = getDiskSpace() #MB availableBytes = diskSpace * 1024 * 1024 #bytes #below can be a configuration option sent via the job wrapper in the future data = 3 * 1024 * 1024 * 1024 # 3GB in bytes if ( data + totalSize ) < availableBytes: msg = 'Enough disk space available (%s bytes)' % ( availableBytes ) self.log.verbose( msg ) return S_OK( msg ) else: msg = 'Not enough disk space available for download %s (including 3GB buffer) > %s bytes' \ % ( ( buffer + totalSize ), availableBytes ) self.log.warn( msg ) return S_ERROR( msg )
def __checkDiskSpace( self, totalSize ): """Compare available disk space to the file size reported from the catalog result. """ diskSpace = getDiskSpace() #MB availableBytes = diskSpace * 1024 * 1024 #bytes #below can be a configuration option sent via the job wrapper in the future data = 3 * 1024 * 1024 * 1024 # 3GB in bytes if ( data + totalSize ) < availableBytes: msg = 'Enough disk space available (%s bytes)' % ( availableBytes ) self.log.verbose( msg ) return S_OK( msg ) else: msg = 'Not enough disk space available for download %s (including 3GB buffer) > %s bytes' \ % ( ( data + totalSize ), availableBytes ) self.log.warn( msg ) return S_ERROR( msg )
def __checkDiskSpace( self, totalSize ): """Compare available disk space to the file size reported from the catalog result. """ diskSpace = getDiskSpace( self.__getDownloadDir( False ) ) # MB availableBytes = diskSpace * 1024 * 1024 # bytes # below can be a configuration option sent via the job wrapper in the future # Moved from 3 to 5 GB (PhC 130822) for standard output file bufferGBs = 5.0 data = bufferGBs * 1024 * 1024 * 1024 # bufferGBs in bytes if ( data + totalSize ) < availableBytes: msg = 'Enough disk space available (%s bytes)' % ( availableBytes ) self.log.verbose( msg ) return S_OK( msg ) else: msg = 'Not enough disk space available for download %s (including %dGB buffer) > %s bytes' \ % ( ( data + totalSize ), bufferGBs, availableBytes ) self.log.warn( msg ) return S_ERROR( msg )
def __checkDiskSpace(self, totalSize): """Compare available disk space to the file size reported from the catalog result. """ diskSpace = getDiskSpace(self.__getDownloadDir(False)) # MB availableBytes = diskSpace * 1024 * 1024 # bytes # below can be a configuration option sent via the job wrapper in the future # Moved from 3 to 5 GB (PhC 130822) for standard output file bufferGBs = 5.0 data = bufferGBs * 1024 * 1024 * 1024 # bufferGBs in bytes if (data + totalSize) < availableBytes: msg = 'Enough disk space available (%s bytes)' % (availableBytes) self.log.verbose(msg) return S_OK(msg) else: msg = 'Not enough disk space available for download %s (including %dGB buffer) > %s bytes' \ % ( ( data + totalSize ), bufferGBs, availableBytes ) self.log.warn(msg) return S_ERROR(msg)
def __checkDiskSpace( self, totalSize ): """Compare available disk space to the file size reported from the catalog result. """ diskSpace = getDiskSpace( self.__getDownloadDir( False ) ) # MB availableBytes = diskSpace * 1024 * 1024 # bytes # below can be a configuration option sent via the job wrapper in the future # Moved from 3 to 5 GB (PhC 130822) for standard output file # data = 5 * 1024 * 1024 * 1024 # 5GB in bytes # in non-LHCb context de output is lower than input in magnitude terms, so the 5GB is a very PhC stuff data = 1 * 1024 * 1024 * 1024 # 5GB in bytes if ( data + totalSize ) < availableBytes: msg = 'Enough disk space available (%s bytes)' % ( availableBytes ) self.log.verbose( msg ) return S_OK( msg ) else: msg = 'Not enough disk space available for download %s (including 1GB buffer) > %s bytes' \ % ( ( data + totalSize ), availableBytes ) self.log.warn( msg ) return S_ERROR( msg )
def execute(self): """ Run the module """ result = self.resolveInputVariables() if not result['OK']: LOG.error("Failed to get the input parameters:", result['Message']) return result if not self.applicationLog: LOG.warn("Log file name missing, reverting to default") self.applicationLog = "AnalyseWN.log" info = [] try: info.append("Host is %s" % socket.gethostname()) except EnvironmentError: info.append("Could not determine host") size = getDiskSpace() if size>0: info.append("Local disk is %s MB"% size) fileName = '/proc/cpuinfo' if os.path.exists( fileName ): with open( fileName, 'r' ) as cpuInfoFile: cpu = cpuInfoFile.readlines() nCPU = 0 for line in cpu: if line.find( 'cpu MHz' ) == 0: nCPU += 1 freq = line.split()[3] elif line.find( 'model name' ) == 0: cpuModel = line.split( ': ' )[1].strip() info.append('CPU (model) = %s' % cpuModel) info.append('CPU (MHz) = %s x %s' % ( nCPU, freq )) fileName = '/proc/meminfo' if os.path.exists( fileName ): with open( fileName, 'r' ) as memInfoFile: mem = memInfoFile.readlines() freeMem = 0 for line in mem: if line.find( 'MemTotal:' ) == 0: totalMem = int( line.split()[1] ) if line.find( 'MemFree:' ) == 0: freeMem += int( line.split()[1] ) if line.find( 'Cached:' ) == 0: freeMem += int( line.split()[1] ) info.append( 'Memory (kB) = %s' % totalMem ) info.append( 'FreeMem. (kB) = %s' % freeMem ) fs = os.statvfs( "." ) # bsize; /* file system block size */ # frsize; /* fragment size */ # blocks; /* size of fs in f_frsize units */ # bfree; /* # free blocks */ # bavail; /* # free blocks for non-root */ # files; /* # inodes */ # ffree; /* # free inodes */ # favail; /* # free inodes for non-root */ # flag; /* mount flags */ # namemax; /* maximum filename length */ diskSpace = fs[4] * fs[0] / 1024 / 1024 info.append( 'DiskSpace (MB) = %s' % diskSpace ) sha = getSharedAreaLocation() if not sha: info.append("No shared Area found here") else: info.append("Shared Area found: %s" % sha) info.append("Content:") sha_list = os.listdir(sha) for item in sha_list: info.append(" %s"% item) sha_size = getDirectorySize(sha) if sha_size: info.append("It uses %s MB of disk"% sha_size) if os.path.isdir("/cvmfs/ilc.cern.ch"): info.append("Has CVMFS") try: of = open(self.applicationLog, "w") of.write("\n".join(info)) of.close() except OSError: LOG.error("Could not create the log file") return S_ERROR("Failed saving the site info") return S_OK()
def execute(self): """ Run the module """ result = self.resolveInputVariables() if not result['OK']: self.log.error("Failed to get the input parameters:", result['Message']) return result if not self.applicationLog: self.log.warn("Log file name missing, reverting to default") self.applicationLog = "AnalyseWN.log" info = [] try: info.append("Host is %s" % socket.gethostname()) except EnvironmentError: info.append("Could not determine host") size = getDiskSpace() if size > 0: info.append("Local disk is %s MB" % size) fileName = '/proc/cpuinfo' if os.path.exists(fileName): with open(fileName, 'r') as cpuInfoFile: cpu = cpuInfoFile.readlines() nCPU = 0 for line in cpu: if line.find('cpu MHz') == 0: nCPU += 1 freq = line.split()[3] elif line.find('model name') == 0: cpuModel = line.split(': ')[1].strip() info.append('CPU (model) = %s' % cpuModel) info.append('CPU (MHz) = %s x %s' % (nCPU, freq)) fileName = '/proc/meminfo' if os.path.exists(fileName): with open(fileName, 'r') as memInfoFile: mem = memInfoFile.readlines() freeMem = 0 for line in mem: if line.find('MemTotal:') == 0: totalMem = int(line.split()[1]) if line.find('MemFree:') == 0: freeMem += int(line.split()[1]) if line.find('Cached:') == 0: freeMem += int(line.split()[1]) info.append('Memory (kB) = %s' % totalMem) info.append('FreeMem. (kB) = %s' % freeMem) fs = os.statvfs(".") # bsize; /* file system block size */ # frsize; /* fragment size */ # blocks; /* size of fs in f_frsize units */ # bfree; /* # free blocks */ # bavail; /* # free blocks for non-root */ # files; /* # inodes */ # ffree; /* # free inodes */ # favail; /* # free inodes for non-root */ # flag; /* mount flags */ # namemax; /* maximum filename length */ diskSpace = fs[4] * fs[0] / 1024 / 1024 info.append('DiskSpace (MB) = %s' % diskSpace) sha = getSharedAreaLocation() if not sha: info.append("No shared Area found here") else: info.append("Shared Area found: %s" % sha) info.append("Content:") sha_list = os.listdir(sha) for item in sha_list: info.append(" %s" % item) sha_size = getDirectorySize(sha) if sha_size: info.append("It uses %s MB of disk" % sha_size) if os.path.isdir("/cvmfs/ilc.cern.ch"): info.append("Has CVMFS") try: of = open(self.applicationLog, "w") of.write("\n".join(info)) of.close() except OSError: self.log.error("Could not create the log file") return S_ERROR("Failed saving the site info") return S_OK()
def __checkForDiskSpace( dpath, size ): """ Check if the directory dpath can accomodate 'size' volume of data """ dsize = (getDiskSpace(dpath)-1)*1024*1024 maxStorageSizeBytes = 1024*1024*1024 return ( min(dsize, maxStorageSizeBytes) > size )
def __checkForDiskSpace(dpath, size): """ Check if the directory dpath can accomodate 'size' volume of data """ dsize = (getDiskSpace(dpath) - 1) * 1024 * 1024 maxStorageSizeBytes = 1024 * 1024 * 1024 return (min(dsize, maxStorageSizeBytes) > size)