コード例 #1
0
    def rotate(self, _id=None, name=None):
        t = time.time()
        try:
            _id = self.get_id(_id, name)
        except:
            _id = None

        if not _id:
            self.logger.info("Nothing to do")
            return

        self.logger.debug("Start rotation of %s" % _id)

        self.logger.debug(" + DCA: %s" % _id)

        points = self.get_data(_id)

        if not points:
            self.logger.debug("No points, Nothing to do")
            return

        fts = points[0][0]
        lts = points[-1][0]

        self.logger.debug("  + Compress %s -> %s" % (fts, lts))

        data = utils.compress(points)

        try:
            bin_id = "%s%s" % (_id, lts)
            self.logger.debug("   + Store in binary record")

            try:
                self.store.create_bin(_id=bin_id, data=data)
            except gridfs.errors.FileExists as fe:
                self.logger.debug(
                    'Impossible to create gridfs bin {} because it exists'.
                    format(fe))

            self.logger.debug("   + Add bin_id in meta and clean meta")
            ##ofts = dca.get('fts', fts)
            ##self.store.update(_id=_id, mset={'fts': ofts, 'd': []}, mpush={'c': (fts, lts, bin_id)})

            perfdata = self.store.get(_id=_id)
            to_push = [fts, lts, bin_id]
            if to_push not in perfdata['c']:
                self.store.update(_id=_id, mpush={'c': (fts, lts, bin_id)})

            self.store.redis.delete(_id)

        except Exception, err:
            self.logger.warning('Impossible to rotate %s: %s' % (_id, err))
            self.logger.error(traceback.format_exc())
コード例 #2
0
ファイル: manager.py プロジェクト: EzanLTD/canopsis
	def rotate(self, _id=None, name=None):
		t = time.time()
		try:
			_id = self.get_id(_id, name)
		except:
			_id = None

		if not _id:
			self.logger.info("Nothing to do")
			return

		self.logger.debug("Start rotation of %s" % _id)

		self.logger.debug(" + DCA: %s" % _id)

		points = self.get_data(_id)

		if not points:
			self.logger.debug("No points, Nothing to do")
			return

		fts = points[0][0]
		lts = points[-1][0]

		self.logger.debug("  + Compress %s -> %s" % (fts, lts))

		data = utils.compress(points)

		try:
			bin_id = "%s%s" % (_id, lts)
			self.logger.debug("   + Store in binary record")

			try:
				self.store.create_bin(_id=bin_id, data=data)
			except gridfs.errors.FileExists as fe:
				self.logger.debug('Impossible to create gridfs bin {} because it exists'.format(fe))

			self.logger.debug("   + Add bin_id in meta and clean meta")
			##ofts = dca.get('fts', fts)
			##self.store.update(_id=_id, mset={'fts': ofts, 'd': []}, mpush={'c': (fts, lts, bin_id)})

			perfdata = self.store.get(_id=_id)
			to_push = [fts, lts, bin_id]
			if to_push not in perfdata['c']:
				self.store.update(_id=_id, mpush={'c': (fts, lts, bin_id)})

			self.store.redis.delete(_id)

		except Exception,err:
			self.logger.warning('Impossible to rotate %s: %s' % (_id, err))
			self.logger.error(traceback.format_exc())
コード例 #3
0
	def rotate(self, _id=None, name=None):
		try:
			_id = self.get_id(_id, name)
		except:
			_id = None
		
		# Find yesterday DCA
		if _id:
			self.logger.debug("Rotate DCA '%s'" % _id)
			dcas = self.find(_id=_id, mfilter={ 'd' : {'$ne': []} })
		else:
			self.logger.info("Rotate All DCA")
			dcas = self.store.find(mfilter={'d' : {'$ne': []}})
		
		if not dcas.count():
			self.logger.debug(" + Nothing to do")
			return

		for dca in dcas:
			_id = dca['_id']
			self.logger.debug(" + DCA: %s" % _id)
			
			fts = dca['d'][0][0]
			lts = dca['d'][len(dca['d'])-1][0]
				
			#check if must compress or not
			if len(dca['d']) >= self.dca_min_length:				
				self.logger.debug("  + Compress %s -> %s" % (fts, lts))
				
				data = utils.compress(dca['d'])
							
				try:
					bin_id = "%s%s" % (_id, lts)
					self.logger.debug("   + Store in binary record")
					self.store.create_bin(_id=bin_id, data=data)
					
					self.logger.debug("   + Add bin_id in meta and clean meta")
					ofts = dca.get('fts', fts)
					self.store.update(_id=_id, mset={'fts': ofts, 'lts': lts, 'd': []}, mpush={'c': (fts, lts, bin_id)})
					
				except Exception,err:
					self.logger.info('Impossible to rotate %s: %s' % (_id, err))
					
			else:
				self.logger.debug("  + Not enough point in DCA")
				ofts = dca.get('fts', fts)
				self.store.update(_id=_id, mset={'fts': ofts})
コード例 #4
0
ファイル: manager.py プロジェクト: linkdd/canopsis
	def rotate(self, _id=None, name=None):
		t = time.time()
		try:
			_id = self.get_id(_id, name)
		except:
			_id = None			
	
		if not _id:
			self.logger.info("Nothing to do")
			return

		self.logger.debug("Start rotation of %s" % _id)

		self.logger.debug(" + DCA: %s" % _id)

		points = self.get_data(_id)
		
		if not points:
			self.logger.debug("No points, Nothing to do")
			return

		fts = points[0][0]
		lts = points[len(points)-1][0]
						
		self.logger.debug("  + Compress %s -> %s" % (fts, lts))
		
		data = utils.compress(points)

		try:
			bin_id = "%s%s" % (_id, lts)
			self.logger.debug("   + Store in binary record")
			self.store.create_bin(_id=bin_id, data=data)
			
			self.logger.debug("   + Add bin_id in meta and clean meta")
			##ofts = dca.get('fts', fts)
			##self.store.update(_id=_id, mset={'fts': ofts, 'd': []}, mpush={'c': (fts, lts, bin_id)})
			
			self.store.update(_id=_id, mpush={'c': (fts, lts, bin_id)})
			self.store.redis.delete(_id)
			
		except Exception,err:
			self.logger.warning('Impossible to rotate %s: %s' % (_id, err))
コード例 #5
0
ファイル: manager.py プロジェクト: moas/canopsis
    def rotate(self, _id=None, name=None):
        t = time.time()
        try:
            _id = self.get_id(_id, name)
        except:
            _id = None

        if not _id:
            self.logger.info("Nothing to do")
            return

        self.logger.debug("Start rotation of %s" % _id)

        self.logger.debug(" + DCA: %s" % _id)

        points = self.get_data(_id)

        if not points:
            self.logger.debug("No points, Nothing to do")
            return

        fts = points[0][0]
        lts = points[len(points) - 1][0]

        self.logger.debug("  + Compress %s -> %s" % (fts, lts))

        data = utils.compress(points)

        try:
            bin_id = "%s%s" % (_id, lts)
            self.logger.debug("   + Store in binary record")
            self.store.create_bin(_id=bin_id, data=data)

            self.logger.debug("   + Add bin_id in meta and clean meta")
            ##ofts = dca.get('fts', fts)
            ##self.store.update(_id=_id, mset={'fts': ofts, 'd': []}, mpush={'c': (fts, lts, bin_id)})

            self.store.update(_id=_id, mpush={'c': (fts, lts, bin_id)})
            self.store.redis.delete(_id)

        except Exception, err:
            self.logger.warning('Impossible to rotate %s: %s' % (_id, err))
コード例 #6
0
ファイル: manager.py プロジェクト: Anhmike/canopsis
	def rotate(self, _id, values):
		t = time.time()

		self.logger.warning("Start rotation of %s" % _id)

		self.logger.warning(" + DCA: %s" % _id)

		timestamps = values.keys()
		timestamps.sort()
		points = []
		for timestamp in timestamps:
			points.append(values[timestamp])

		fts = values[timestamps[0]][0]
		lts = values[timestamps[-1]][0]

		self.logger.warning("  + Compress %s -> %s" % (fts, lts))

		data = utils.compress(points)

		try:
			bin_id = "%s%s" % (_id, lts)
			self.logger.warning("   + Store in binary record")
			self.store.create_bin(_id=bin_id, data=data)
		except gridfs.errors.FileExists as fe:
			self.logger.debug('Impossible to create gridfs bin {} because it exists'.format(fe))

			self.logger.warning("   + Add bin_id in meta and clean meta")

			self.store.update(_id=_id, mpush={'c': (fts, lts, bin_id)})
			self.store.daily_collection.remove({'_id': _id})

		except Exception as err:
			self.logger.warning('Impossible to rotate %s: %s' % (_id, err))

		t = time.time() - t
		self.logger.debug(" + Rotation of '%s' done in %.3f seconds" % (_id, t))