本文整理汇总了Python中pxStats.lib.StatsDateLib.StatsDateLib类的典型用法代码示例。如果您正苦于以下问题:Python StatsDateLib类的具体用法?Python StatsDateLib怎么用?Python StatsDateLib使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StatsDateLib类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getStartEndOfWebPage
def getStartEndOfWebPage():
"""
@summary : Returns the time of the first
graphics to be shown on the web
page and the time of the last
graphic to be displayed.
@return : start, end tuple in iso format.
"""
currentTime = StatsDateLib.getIsoFromEpoch( time.time() )
currentDate = datetime.date( int(currentTime[0:4]), int(currentTime[5:7]), 1 )
nbMonthsToRevwind = NB_MONTHS_DISPLAYED - 1
if currentDate.month - (nbMonthsToRevwind%12) < 1 :
month = currentDate.month - (nbMonthsToRevwind%12)+12
if currentDate.month -nbMonthsToRevwind < 1:
year = currentDate.year - int( abs(math.floor( float( ( currentDate.month - nbMonthsToRevwind ) / 12 ) ) ) )
else :
month = currentDate.month - nbMonthsToRevwind
year = currentDate.year
start = "%s-%s-%s 00:00:00" %( year,month,"01" )
end = StatsDateLib.getIsoTodaysMidnight( currentTime )
return start, end
示例2: main
def main():
"""
@summary : This program is to be used to backup
rrd databases and their corresponding
time of update files. Backing up rrd
databases at various point in time is a
recommended paractice in case newly
entered data is not valid.
"""
setGlobalLanguageParameters()
currentTime = time.time()
currentTime = StatsDateLib.getIsoFromEpoch( currentTime )
currentTime = StatsDateLib.getIsoWithRoundedSeconds( currentTime )
currentTime = currentTime.replace(" ", "_")
backupsToKeep = 20
if len( sys.argv ) == 2:
try:
backupsToKeep = int( sys.argv[1] )
except:
print _( "Days to keep value must be an integer. For default 20 backups value, type nothing." )
sys.exit()
backupDatabaseUpdateTimes( currentTime, backupsToKeep )
backupDatabases( currentTime, backupsToKeep )
示例3: setMonths
def setMonths( self ):
"""
@Summary : Sets the months value to an array containing
the last X months in "since epoch" numbers
based on the globally set NB_MONTHS_DISPLAYED
value.
"""
currentTime = time.time()
currentTime = StatsDateLib.getIsoFromEpoch( currentTime )
currentDate = datetime.date( int(currentTime[0:4]), int(currentTime[5:7]), 1 ) # day always = 1 in case currentDate.day > 28
months = []
for i in range(0,NB_MONTHS_DISPLAYED):
if currentDate.month - (i%12) < 1 :
month = currentDate.month - (i%12)+12
if currentDate.month -i < 1:
year = currentDate.year - int( abs(math.floor( float( ( currentDate.month - i ) / 12 ) ) ) )
else :
month = currentDate.month - i
year = currentDate.year
months.append( StatsDateLib.getSecondsSinceEpoch( "%s-%s-%s 00:00:00" %(year,month,"01") ) )
months.reverse()
self.months = months
print months
示例4: getThreeClosestDatabasesBackups
def getThreeClosestDatabasesBackups( infos ):
"""
@summary : Returns the three databases backups
that are the closest to the startTime
asked for the database recollection.
@param infos :
@return: the three databases backups
that are the closest to the startTime
asked for the database recollection.
"""
closestFiles = []
differenceFileTuples = []
files = os.listdir( StatsPaths.STATSDB + 'databasesTimeOfUpdatesBackups/' )
startTimeInEpochformat = StatsDateLib.getSecondsSinceEpoch( infos.databasesRecollectionStartTime )
for file in files:
#try:
fileDateInIsoFormat = "%s %s" %(str(file).split("_")[0], str(file).split("_")[1] )
tupleToAdd = ( abs( StatsDateLib.getSecondsSinceEpoch(fileDateInIsoFormat) - startTimeInEpochformat ), file )
differenceFileTuples.append( tupleToAdd )
for tuple in differenceFileTuples [:3] :
closestFiles.append( tuple[1] )
return closestFiles
示例5: getStartAndEndTimeForPickleRecollection
def getStartAndEndTimeForPickleRecollection():
"""
@summary : Gets the start time and the endTime
of the pickle recollection from the
user's input.
@return : Returns the startTime and endTime.
"""
startTime = raw_input( "Enter the startTime of the pickle recollection ( yyyy-mm-dd hh:mm:ss) : ")
while not StatsDateLib.isValidIsoDate( startTime ):
print "Error. The entered date must be of the iso format."
startTime = raw_input( "Enter the startTime of the pickle recollection ( yyyy-mm-dd hh:mm:ss) : ")
endTime= raw_input( "Enter the endTime of the pickle recollection ( yyyy-mm-dd hh:mm:ss or 'now' for current time ) : ")
while( str(endTime).lower() != "now" and not StatsDateLib.isValidIsoDate( endTime ) and ( StatsDateLib.isValidIsoDate( endTime ) and endTime<= startTime ) ) :
if StatsDateLib.isValidIsoDate( endTime ) and endTime<= startTime :
print "Error. End time must be after startTime( %s ). "
elif StatsDateLib.isValidIsoDate( endTime ):
print "Error. The entered date must be of the iso format."
endTime= raw_input( "Enter the endTime of the pickle recollection ( yyyy-mm-dd hh:mm:ss or 'now' for current time ) : ")
if endTime == "now" :
endTime = StatsDateLib.getIsoFromEpoch( time.time() )
return startTime, endTime
示例6: getTimeOfLastUpdateInLogs
def getTimeOfLastUpdateInLogs(self):
"""
@summary : Returns the time of the last update in iso format.
@return : None if no update as found, EPCH is returned in iso format,
as to make sure an update is made since no prior updates exist.
"""
timeOfLastUpdate = StatsDateLib.getIsoTodaysMidnight( StatsDateLib.getCurrentTimeInIsoformat() )
paths = StatsPaths()
paths.setPaths()
updatesDirectory = paths.STATSTEMPAUTUPDTLOGS + self.updateType + "/"
if not os.path.isdir( updatesDirectory ):
os.makedirs(updatesDirectory)
allEntries = os.listdir(updatesDirectory)
if allEntries !=[] :
allEntries.sort()
allEntries.reverse()
timeOfLastUpdate = os.path.basename( allEntries[0] ).replace( "_"," " )
return timeOfLastUpdate
示例7: setMonths
def setMonths( self ):
"""
Returns the 3 months including current month.
"""
currentTime = time.time()
currentTime = StatsDateLib.getIsoFromEpoch( currentTime )
currentDate = datetime.date( int(currentTime[0:4]), int(currentTime[5:7]), 1 )
months = []
for i in range(0,5):
if currentDate.month -i < 1 :
month = currentDate.month -i + 12
year = currentDate.year -i
else :
month = currentDate.month -i
year = currentDate.year
newdate = StatsDateLib.getSecondsSinceEpoch( "%s-%s-01 00:00:00" %( year,month ) )
months.append( newdate )
#print year,month,day
months.reverse()
self.months = months
示例8: __init__
def __init__( self, displayedLanguage = 'en', filesLanguage='en', days = None, \
weeks = None, months = None, years = None, \
pathsTowardsGraphics = None, pathsTowardsOutputFiles = None ):
"""
@summary : Constructor
@param displayedLanguage: Languages in which to display
the different captions found within
the generated web page.
@param fileLanguages: Language in which the files that
will be referenced within this page
have been generated.
@param days : List of days that the web page covers.
@note : Will set two global translators to be used throughout this module
_ which translates every caption that is to be printed.
_F which translates every filename that is to be linked.
"""
configParameters = StatsConfigParameters()
configParameters.getGeneralParametersFromStatsConfigurationFile()
global _
_ = self.getTranslatorForModule( CURRENT_MODULE_ABS_PATH, displayedLanguage )
if days == None:
self.setDays()
else:
self.days = days
if weeks == None:
self.setWeeks()
else:
self.weeks = weeks
if months == None:
self.setMonths()
else:
self.months = months
if years == None:
self.setYears()
else:
self.years = years
self.displayedLanguage = displayedLanguage
self.filesLanguage = filesLanguage
self.pathsTowardsGraphics = StatsPaths()
self.pathsTowardsGraphics.setPaths( filesLanguage )
self.pathsTowardsOutputFiles = StatsPaths()
self.pathsTowardsOutputFiles.setPaths( self.displayedLanguage )
StatsDateLib.setLanguage(filesLanguage)
示例9: mergePicklesFromDifferentHours
def mergePicklesFromDifferentHours( logger = None , startTime = "2006-07-31 13:00:00",\
endTime = "2006-07-31 19:00:00", client = "satnet",\
machine = "pdsPM", fileType = "tx" ):
"""
@summary : This method merges entire hourly pickles files together.
@None : This does not support merging part of the data of pickles.
"""
if logger != None :
logger.debug( _("Call to mergeHourlyPickles received.") )
logging = True
else:
logging = False
pickles = []
entries = {}
width = StatsDateLib.getSecondsSinceEpoch( endTime ) - StatsDateLib.getSecondsSinceEpoch( startTime )
startTime = StatsDateLib.getIsoWithRoundedHours( startTime )
seperators = [startTime]
seperators.extend( StatsDateLib.getSeparatorsWithStartTime( startTime = startTime , width=width, interval=60*StatsDateLib.MINUTE )[:-1])
for seperator in seperators :
pickles.append( StatsPickler.buildThisHoursFileName( client = client, offset = 0, currentTime = seperator, machine = machine, fileType = fileType ) )
startingNumberOfEntries = 0
#print "prior to loading and merging pickles : %s " %( StatsDateLib.getIsoFromEpoch( time.time() ) )
for pickle in pickles :
if os.path.isfile( pickle ) :
tempCollection = CpickleWrapper.load( pickle )
if tempCollection != None :
for i in xrange( len( tempCollection.fileEntries ) ):
entries[startingNumberOfEntries + i] = tempCollection.fileEntries[i]
startingNumberOfEntries = startingNumberOfEntries + len( tempCollection.fileEntries )
else:
sys.exit()
else:
emptyEntries = PickleMerging.fillWithEmptyEntries( nbEmptyEntries = 60, entries = {} )
for i in xrange( 60 ):
entries[i + startingNumberOfEntries ] = emptyEntries [i]
startingNumberOfEntries = startingNumberOfEntries + 60
#print "after the loading and merging og pickles : %s " %( StatsDateLib.getIsoFromEpoch( time.time() ) )
statsCollection = FileStatsCollector( startTime = startTime , endTime = endTime, interval = StatsDateLib.MINUTE, totalWidth = width, fileEntries = entries,fileType= fileType, logger = logger, logging = logging )
return statsCollection
示例10: askUserAboutUpdatingLogs
def askUserAboutUpdatingLogs( infos ):
"""
@Summary : Asks user about whether or not
he wants to update the log files
on his machine.
@returns True or False
"""
updateLofFiles = False
os.system( "clear" )
showPresentation()
print ""
print ""
print "***************** Important note *****************"
print "Collection or recollection of pickle files "
print "is closely linked to the log files found on this machine."
if StatsDateLib.getIsoWithRoundedHours( infos.picklesRecollectionStartTime ) != StatsDateLib.getIsoWithRoundedHours( StatsDateLib.getIsoFromEpoch( time.time() )) :
print "Data recollection is set to take place up to the current hour."
print "For the end of the recollection it is recommended that log file be updated."
print "However, if the recollection spans over a long while and that the log file currently "
print "on this machine are 'old' and cover the start of the recollection,"
print "updating log files might cause you to loose some or all of those old files."
else :
print "Data recollection is set to end PRIOR to the current hour."
print "In this case, log file updates are usually useless."
print "In the case where the span between the start of the recollection "
print "is longer than the span covered by the currently accessible log files, "
print "usefull log files will be lsot by updating them."
print "However the opposite could also be true. If problems occured and "
print "databases are seriously outdated, updating them will be the only solution "
print "capable of making some or all the needed log file data accessible for pickling."
print ""
print "***Please review log files prior to specifying whether or not you want to update them or not.***"
print ""
input = raw_input( "Do you want to update log files ? ( y or n ) : " )
while ( str( input ).lower() != 'n' and str( input ).lower() != 'y' ):
print "Please enter one of the following choices : y/Y or n/N."
input = raw_input( "Do you want to update log files ? ( y or n ) : " )
if str( input ).lower() == 'y' :
print "Log files will be updated."
updateLofFiles = True
else:
print "Log files will not be updated."
return updateLofFiles
示例11: getSeperatorsForHourlyTreatments
def getSeperatorsForHourlyTreatments( startTime, endTime, currentFreeMemory, fileSizesPerHour, usage= "rrd" ):
"""
@summary : returns a list of time seperators based on a list of file and
the current amount of free memory. Each seperator represents the time
associated with a certain hourly file. Each seperator will represent
the maximum amount of files that can be treated at the same time
without busting the current memory.
@attention: List fo files MUST refer to hourly files.
@param startTime: Startime in iso format of the interval to work with.
@param endTime: End time in iso format of the interval to work with.
@param currentFreeMemory: Maximum amout of memory to use per seperation.
@param fileSizesPerHour: size of the file(s) to be treated at every hour.
@return: Returns the time seperators.
"""
currentTotalFileSizes = 0
currentTime = StatsDateLib.getSecondsSinceEpoch(startTime)
seperators = [startTime]
if fileSizesPerHour[0] < currentFreeMemory:
for fileSizePerHour in fileSizesPerHour :
currentTotalFileSizes = currentTotalFileSizes + fileSizePerHour
if currentFreeMemory < currentTotalFileSizes:
seperators.append( StatsDateLib.getIsoFromEpoch(currentTime))
currentTotalFileSizes = 0
currentTime = currentTime + StatsDateLib.HOUR
else:
raise Exception( "Cannot build seperators. First file will not even fit within current available memory." )
if seperators[len(seperators) -1 ] != endTime :
seperators.append( endTime )
if len(seperators) > 2 : #If any "in between seperators were added"
i = 1
currentLength = len(seperators) -1
while i < currentLength: #add 1 minute
if usage == "rrd":
seperators.insert(i+1, StatsDateLib.getIsoFromEpoch( (StatsDateLib.getSecondsSinceEpoch(seperators[i]) + StatsDateLib.MINUTE)))
else:
seperators.insert( i+1, StatsDateLib.getSecondsSinceEpoch(seperators[i]) )
currentLength = currentLength + 1
i = i + 2
return seperators
示例12: printPickledTimes
def printPickledTimes(pickledTimes):
"""
@summary: Prints out all the pickled times found.
@param pickledTimes: Dictionary containing containing the
name -> timeOfUpdate relationships.
"""
currentTime = time.time()
currentTime = StatsDateLib.getIsoFromEpoch(currentTime)
keys = pickledTimes.keys()
keys.sort()
os.system("clear")
print "######################################################################"
print "# List of current times of updates. #"
print "# Times were found at : %-43s #" % currentTime
print "# On the machine named : %-43s #" % LOCAL_MACHINE
for key in keys:
print ("#%32s : %33s#") % (key, pickledTimes[key])
print "# #"
print "######################################################################"
示例13: getPreviousMonitoringJob
def getPreviousMonitoringJob( self, currentTime ):
"""
@summary : Gets the previous crontab from the pickle file.
@return : Time of the previous monitoring job.
@warning : Returns "" if file does not exist.
"""
statsPaths = StatsPaths()
statsPaths.setPaths()
file = "%spreviousMonitoringJob" %statsPaths.STATSMONITORING
previousMonitoringJob = ""
if os.path.isfile( file ):
fileHandle = open( file, "r" )
previousMonitoringJob = pickle.load( fileHandle )
fileHandle.close()
#print previousMonitoringJob
else:
previousMonitoringJob = StatsDateLib.getIsoTodaysMidnight( currentTime )
#print previousMonitoringJob
return previousMonitoringJob
示例14: isFirstUpdateOfTheYear
def isFirstUpdateOfTheYear( self, timeOfUpdateInIsoFormat = "" ):
"""
@summary : Returns whether or not an update executed at
timeOfUpdateInIsoFormat would be the first update
of the year.
@timeOfUpdateInIsoFormat : Time at which the update would be executed.
@return : True or False.
"""
isFirstUpdateOfTheYear = False
lastUpdateISO = self.getTimeOfLastUpdateInLogs()
if timeOfUpdateInIsoFormat == "" :
timeOfUpdateInIsoFormat = StatsDateLib.getCurrentTimeInIsoformat()
if timeOfUpdateInIsoFormat > lastUpdateISO :
yearNumberOfLastUpdate = lastUpdateISO.split("-")[0]
yearNumberOfCurrentUpdate = timeOfUpdateInIsoFormat.split("-")[0]
if yearNumberOfLastUpdate != yearNumberOfCurrentUpdate:
isFirstUpdateOfTheYear = True
return isFirstUpdateOfTheYear
示例15: addOptions
def addOptions( parser ):
"""
@summary: This method is used to add all available options to the option parser.
"""
parser.add_option("-c", "--clients", action="store", type="string", dest="clients", default="ALL",
help=_("Clients' names"))
parser.add_option("-d", "--daily", action="store_true", dest = "daily", default=False, help=_("Create csv file containing daily data.") )
parser.add_option( "--date", action="store", type="string", dest="date", default=StatsDateLib.getIsoFromEpoch( time.time() ), help=_("Decide end time of graphics. Usefull for testing.") )
parser.add_option("-f", "--fileType", action="store", type="string", dest="fileType", default='tx', help=_("Type of log files wanted.") )
parser.add_option( "--fixedPrevious", action="store_true", dest="fixedPrevious", default=False, help=_("Do not use floating weeks|days|months|years. Use previous fixed interval found.") )
parser.add_option( "--fixedCurrent", action="store_true", dest="fixedCurrent", default=False, help=_("Do not use floating weeks|days|months|years. Use current fixed interval found.") )
parser.add_option( "--includeGroups", action="store_true", dest="includeGroups", default=False, help=_("Include groups of all the specified machines or clusters." ) )
parser.add_option( "-l", "--language", action="store", type="string", dest="outputLanguage", default="", help = _("Language in which you want the casv file to be created in." ) )
parser.add_option( "--machines", action="store", type="string", dest="machines", default=LOCAL_MACHINE, help =_("Machines for wich you want to collect data." ) )
parser.add_option("--machinesAreClusters", action="store_true", dest = "machinesAreClusters", default=False, help=_("Specified machines are clusters.") )
parser.add_option("-m", "--monthly", action="store_true", dest = "monthly", default=False, help=_("Create csv file containing monthly data." ) )
parser.add_option("--turnOffLogging", action="store_true", dest = "turnOffLogging", default=False, help=_("Turn off the logger") )
parser.add_option("-w", "--weekly", action="store_true", dest = "weekly", default=False, help=_("Create csv file containing weekly data." ) )
parser.add_option("-y", "--yearly", action="store_true", dest = "yearly", default=False, help=_("Create csv file containing yearly data." ) )