import TelemetryLogMonitor
def __init__(self, casa):
self.logdir = casa['dirs']['rc']
if len(casa['variant'])>1:
self.variantSuffix = "-" + casa['variant']
self.logpattern = 'casastats-' + self.casaver + '-' + self.hostid + '*' + self.variantSuffix + '.log'
self.sendlogpattern = 'casastats-*'+ self.hostid + '*.log'
self.stampfile = self.logdir + '/telemetry-' + self.hostid + '.stamp'
casa_util = __casac__.utils.utils()
if (casa_util.getrc("TelemetryLogDirectory") != 'Unknown value'):
self.logdir = casa_util.getrc("TelemetryLogDirectory")
for file in os.listdir(self.logdir):
if fnmatch.fnmatch(file, self.logpattern):
logfiles.sort(reverse=True)
if (logfiles and logfiles[0] != None):
print "Found an existing telemetry logfile: " + self.logdir + "/" + logfiles[0]
casa['files']['telemetry-logfile'] = self.logdir + "/" + logfiles[0]
for i in range(1, len(logfiles)):
inactiveTLogSize = inactiveTLogSize + os.path.getsize(self.logdir + "/" + logfiles[i])/1024
print "Creating a new telemetry file"
self.setNewTelemetryFile()
tLogSizeLimit = int(casa_util.getrc("TelemetryLogLimit"))
tLogSizeInterval = int(casa_util.getrc("TelemetryLogSizeInterval"))
tLogSizeLimit = tLogSizeLimit - inactiveTLogSize
print "Telemetry log size limit exceeded. Disabling telemetry."
casa['state']['telemetry-enabled'] = False
tLogMonitor = TelemetryLogMonitor.TelemetryLogMonitor()
tLogMonitor.start(casa['files']['telemetry-logfile'],tLogSizeLimit, tLogSizeInterval, casa)
print "Telemetry initialized. Telemetry will send anonymized usage statistics to NRAO."
print 'You can disable telemetry by adding the following line to your ~/.casarc file:'
print 'EnableTelemetry: False'
def setNewTelemetryFile(self):
self.casa['files']['telemetry-logfile'] = self.logdir + '/casastats-' + self.casaver +'-' + self.hostid + "-" + time.strftime("%Y%m%d-%H%M%S", time.gmtime()) + self.variantSuffix + '.log'
if hasattr(self, 'logger'):
self.logger.setstatslogfile(self.casa['files']['telemetry-logfile'])
def setCasaVersion(self):
self.casaver = str(ver[0])+ str(ver[1]) + str(ver[2])+ "-" + str(ver[3])
telemetryhelper = casac.telemetryhelper()
self.hostid = telemetryhelper.getUniqueId()