本文整理汇总了Python中pxStats.lib.StatsDateLib.StatsDateLib.getIsoFromEpoch方法的典型用法代码示例。如果您正苦于以下问题:Python StatsDateLib.getIsoFromEpoch方法的具体用法?Python StatsDateLib.getIsoFromEpoch怎么用?Python StatsDateLib.getIsoFromEpoch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pxStats.lib.StatsDateLib.StatsDateLib
的用法示例。
在下文中一共展示了StatsDateLib.getIsoFromEpoch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getSeperatorsForHourlyTreatments
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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
示例2: printPickledTimes
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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 "######################################################################"
示例3: addOptions
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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." ) )
示例4: main
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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 )
示例5: getStartEndOfWebPage
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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
示例6: setMonths
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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
示例7: getStartAndEndTimeForPickleRecollection
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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
示例8: setMonths
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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
示例9: getLastUpdate
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
def getLastUpdate( machine, client, fileType, currentDate, paths, collectUpToNow = False ):
"""
@summary : Reads and returns the client's or source's last update.
@return : The client's or sources last update.
"""
times = {}
lastUpdate = {}
fileName = "%s%s_%s_%s" %( paths.STATSPICKLESTIMEOFUPDATES, fileType, client, machine )
if os.path.isfile( fileName ):
try :
fileHandle = open( fileName, "r" )
lastUpdate = pickle.load( fileHandle )
fileHandle.close()
except:
print _("problematic file in loading : %s") %fileName
lastUpdate = StatsDateLib.getIsoWithRoundedHours( StatsDateLib.getIsoFromEpoch( StatsDateLib.getSecondsSinceEpoch(currentDate ) - StatsDateLib.HOUR) )
pass
fileHandle.close()
else:#create a new pickle file.Set start of the pickle as last update.
if not os.path.isdir( os.path.dirname( fileName ) ) :
os.makedirs( os.path.dirname( fileName ) )
fileHandle = open( fileName, "w" )
lastUpdate = StatsDateLib.getIsoWithRoundedHours( StatsDateLib.getIsoFromEpoch( StatsDateLib.getSecondsSinceEpoch(currentDate ) - StatsDateLib.HOUR) )
pickle.dump( lastUpdate, fileHandle )
fileHandle.close()
return lastUpdate
示例10: main
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
def main():
"""
@summary: Small test case to see if everything works fine
"""
statsConfig = StatsConfigParameters()
statsConfig.getAllParameters()
machineconfig = MachineConfigParameters()
machineconfig.getParametersFromMachineConfigurationFile()
currentTimeEpochFormat = time.time() -(120*60)
endTime = StatsDateLib.getIsoWithRoundedHours( StatsDateLib.getIsoFromEpoch( currentTimeEpochFormat ) )
startTime = StatsDateLib.getIsoWithRoundedHours( StatsDateLib.getIsoFromEpoch( currentTimeEpochFormat -( StatsDateLib.DAY*7 ) ) )
print startTime, endTime
groupName = statsConfig.groupParameters.groups[0]
clients = statsConfig.groupParameters.groupsMembers[ groupName ]
machines = statsConfig.groupParameters.groupsMachines[ groupName ]
fileType = statsConfig.groupParameters.groupFileTypes[ groupName ]
seperators = [startTime]
seperators.extend( StatsDateLib.getSeparatorsWithStartTime( startTime = startTime , width=StatsDateLib.DAY*7, interval=StatsDateLib.HOUR )[:-1])
listOfFiles = PickleMerging.createMergedPicklesList( startTime, endTime, clients, groupName, fileType, machines, seperators )
listOfFileSizes = MemoryManagement.getListOfFileSizes(listOfFiles)
currentFreeMemory = MemoryManagement.getCurrentFreeMemory(0.55555)
if MemoryManagement.getTotalSizeListOfFiles( listOfFiles ) > currentFreeMemory:
seperators = MemoryManagement.getSeperatorsForHourlyTreatments( startTime, endTime, currentFreeMemory, listOfFileSizes )
print seperators
else:
print "We have %s bytes free and the pickles require %s bytes" %( currentFreeMemory, getTotalSizeListOfFiles( listOfFiles ) )
print "we have enough memory to merge all these pickles."
示例11: getStartEndOfWebPage
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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 both in ISO format.
"""
currentTime = StatsDateLib.getIsoFromEpoch( time.time() )
start = StatsDateLib.rewindXDays( currentTime, NB_DAYS_DISPLAYED - 1 )
start = StatsDateLib.getIsoTodaysMidnight( start )
end = StatsDateLib.getIsoTodaysMidnight( currentTime )
return start, end
示例12: getDirListToKeep
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
def getDirListToKeep( daysToKeep = 21 ):
"""
@summary : Gets the list of directories to keep. Based on daysToKeep parameter.
@param : Number of past days to keep. Specified in daysToKeep.
@return : List of directories to keep.
"""
dirlist = []
secondsSinceEpoch = time.time()
for i in range( daysToKeep ):
dirlist.append( StatsDateLib.getIsoFromEpoch( secondsSinceEpoch - ( i*60*60*24) ).split()[0].replace( '-','') )
return dirlist
示例13: getStartEndOfWebPage
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
def getStartEndOfWebPage():
"""
Returns the time of the first
graphics to be shown on the web
page and the time of the last
graphic to be displayed.
"""
currentTime = StatsDateLib.getIsoFromEpoch(time.time())
start = StatsDateLib.rewindXDays(currentTime, (NB_YEARS_DISPLAYED - 1) * 365)
start = StatsDateLib.getIsoTodaysMidnight(start)
end = StatsDateLib.getIsoTodaysMidnight(currentTime)
return start, end
示例14: main
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
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()
timeToRestore = "2006-10-23 09:00:00"
currentTime = time.time()
currentTime = StatsDateLib.getIsoFromEpoch( currentTime )
currentTime = StatsDateLib.getIsoWithRoundedSeconds( currentTime )
currentTime = currentTime.replace(" ", "_")
generalParameters = StatsConfigParameters()
generalParameters.getAllParameters()
if len( sys.argv ) == 2:
print sys.argv
#try:
timeToRestore = sys.argv[1]
t = time.strptime( timeToRestore, '%Y-%m-%d %H:%M:%S' )#will raise exception if format is wrong.
split = timeToRestore.split()
timeToRestore = "%s_%s" %( split[0], split[1] )
# except:
# print 'Date must be of the following format "YYYY-MM-DD HH:MM:SS"'
# print "Program terminated."
# sys.exit()
restoreDatabaseUpdateTimes( timeToRestore, currentTime, generalParameters.nbDbBackupsToKeep )
restoreDatabases( timeToRestore, currentTime, generalParameters.nbDbBackupsToKeep )
else:
print _( "You must specify a date." )
print _( "Date must be of the folowing format YYYY-MM-DD HH:MM:SS" )
print _( "Program terminated." )
示例15: getParametersFromMonitoringConfigurationFile
# 需要导入模块: from pxStats.lib.StatsDateLib import StatsDateLib [as 别名]
# 或者: from pxStats.lib.StatsDateLib.StatsDateLib import getIsoFromEpoch [as 别名]
def getParametersFromMonitoringConfigurationFile( self ):
"""
@summary : Gather all the parameters from the StatsPaths.STATSETC/config file.
@return : All collected values in this order emails, machines,
files, folders, maxUsages, errorsLogFile, maxSettingsFile.
"""
statsPaths = StatsPaths()
statsPaths.setPaths()
CONFIG = statsPaths.STATSETC +"monitoringConf"
config = ConfigParser()
if os.path.isfile( CONFIG ):
file = open( CONFIG )
config.readfp( file )
self.emails = config.get( 'statsMonitoring', 'emails' ).split( ";" )
self.sender = config.get( 'statsMonitoring', 'sender' )
self.smtpServer = config.get( 'statsMonitoring', 'smtpServer' )
self.machines = config.get( 'statsMonitoring', 'machines' ).split( ";" )
self.files = config.get( 'statsMonitoring', 'files' ).split( ";" )
self.folders = config.get( 'statsMonitoring', 'folders' ).split( ";" )
self.maxUsages = config.get( 'statsMonitoring', 'maxUsages' ).split( ";" )
self.errorsLogFile = config.get( 'statsMonitoring', 'errorsLogFile' )
self.maxSettingsFile=config.get( 'statsMonitoring', 'maxSettingsFile' )
self.endTime = StatsDateLib.getIsoWithRoundedHours( StatsDateLib.getIsoFromEpoch( time.time() ) )
self.startTime = self.getPreviousMonitoringJob(self.endTime)
self.maximumGaps = self.getMaximumGaps( )
self.updateMachineNamesBasedOnExistingMachineTags()
try:
file.close()
except:
pass
else:
#print "%s configuration file not present. Please restore file prior to running" %CONFIG
raise Exception( "%s configuration file not present. Please restore file prior to running" %CONFIG )