def _create_latency_stats(self): created = time.time() with session_scope() as _session: self._repositery.create_latency_stats(_session, self._latency_sum, self._samples, created) self._latency_sum = 0 self._samples = 0
def record_traffic(self, record): self._queue.put(record) try: with session_scope() as _session: self._repositery.create_record(_session, **record.as_dict()) except Exception as e: self.log.exception( "Exception %s happened during recording traffic" % e)
def get_successes(self, start_time=None, end_time=None, destination=None, port=None, source=None): start_time, end_time, filters = self._set_scope(start_time, end_time, destination, port, source) with session_scope() as session: return self._repository.record.get_records( session, start_time, end_time, **filters)
def get_failure_count(self, start_time=None, end_time=None, destination=None, port=None, source=None): start_time, end_time, filters = self._set_scope(start_time, end_time, destination, port, source) with session_scope() as session: return self._repository.fault.get_record_count( session, start_time, end_time, **filters)
def _create_record_count(self): created = time.time() for proto in list(self._proto_record_count.keys()): success_count = self._proto_record_count[proto]['success'] failure_count = self._proto_record_count[proto]['failure'] if success_count > 0 or failure_count > 0: with session_scope() as _session: self._repositery.create_record_count( _session, proto, success_count, failure_count, created) self._proto_record_count[proto]['success'] = 0 self._proto_record_count[proto]['failure'] = 0
def get_avg_latency(self, start_time=None, end_time=None): start_time, end_time = self._set_time_range(start_time, end_time) with session_scope() as session: return self._repository.latency.get_latency_stats( session, start_time, end_time)
def get_traffic_stats(self, start_time=None, end_time=None): start_time, end_time = self._set_time_range(start_time, end_time) with session_scope() as session: return self._repository.request_count.get_request_count( session, start_time, end_time)