def get_system_data_after(server_id=None, timestamp=None, check=None, enddate=None, timezone='UTC', device_id=None): server = server_model.get_by_id(server_id) data = [] now = datetime.utcnow() active_checks = [ 'memory', 'loadavg', 'cpu', 'disk', 'network.inbound', 'network.outbound' ] if check in active_checks and timestamp: if check in ['network.inbound', 'network.outbound']: key = 'i' if check == 'network.inbound' else 'o' filtered_servers = [server] data = system_model.get_global_device_data_after( timestamp=timestamp, enddate=enddate, filtered_servers=filtered_servers, key=key, timezone=timezone, check='network') elif check == 'disk': data = system_model.get_device_data_after(timestamp=timestamp, enddate=enddate, server=server, timezone=timezone, check=check, device_id=device_id) else: data = system_model.get_data_after(timestamp=timestamp, enddate=enddate, server=server, check=check, timezone=timezone) try: now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone) except: now_local = False response = { 'data': data, 'last_update': datetime_to_unixtime(now), 'now_local': now_local, 'chart_type': 'line' } return response
def get_global_system_data_after(timestamp=None, check=None, key=None, enddate=None, timezone='UTC', filtered_servers=None): data = [] now = datetime.utcnow() active_checks = ['memory', 'loadavg', 'cpu', 'disk', 'network'] if check in active_checks and timestamp: if check in ['disk', 'network']: data = system_model.get_global_device_data_after( timestamp=timestamp, enddate=enddate, timezone=timezone, check=check, key=key, filtered_servers=filtered_servers) else: data = system_model.get_global_data_after( timestamp=timestamp, enddate=enddate, check=check, key=key, timezone=timezone, filtered_servers=filtered_servers) try: now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone) except: now_local = False response = { 'data': data, 'last_update': datetime_to_unixtime(now), 'now_local': now_local, 'chart_type': 'line', } return response
def get_system_data_after(server_id=None, timestamp=None, check=None, enddate=None, timezone='UTC', device_id=None): server = server_model.get_by_id(server_id) data = [] now = datetime.utcnow() active_checks = ['memory', 'loadavg', 'cpu', 'disk', 'network.inbound', 'network.outbound'] if check in active_checks and timestamp: if check in ['network.inbound', 'network.outbound']: key = 'i' if check == 'network.inbound' else 'o' filtered_servers = [server] data = system_model.get_global_device_data_after(timestamp=timestamp, enddate=enddate, filtered_servers=filtered_servers, key=key, timezone=timezone, check='network' ) elif check == 'disk': data = system_model.get_device_data_after(timestamp=timestamp, enddate=enddate, server=server, timezone=timezone, check=check, device_id=device_id) else: data = system_model.get_data_after(timestamp=timestamp, enddate=enddate, server=server, check=check, timezone=timezone) try: now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone) except: now_local = False response = { 'data': data, 'last_update': datetime_to_unixtime(now), 'now_local': now_local, 'chart_type': 'line' } return response
def get_global_system_data_after(timestamp=None, check=None, key=None, enddate=None, timezone='UTC', filtered_servers=None): data = [] now = datetime.utcnow() active_checks = ['memory', 'loadavg', 'cpu', 'disk', 'network'] if check in active_checks and timestamp: if check in ['disk', 'network']: data = system_model.get_global_device_data_after(timestamp=timestamp, enddate=enddate, timezone=timezone, check=check, key=key, filtered_servers=filtered_servers ) else: data = system_model.get_global_data_after(timestamp=timestamp, enddate=enddate, check=check, key=key, timezone=timezone, filtered_servers=filtered_servers ) try: now_local = dateformatcharts_local(datetime_to_unixtime(now), tz=timezone) except: now_local = False response = { 'data': data, 'last_update': datetime_to_unixtime(now), 'now_local': now_local, 'chart_type': 'line', } return response
def get_disk_data_test(self): self._cleanup() volume = volumes_model.get_or_create(server_id=self.server['_id'], name='test_volume') collection = volumes_model.get_data_collection() for i in range(0, 30): collection.insert({ 'server_id': self.server_id, 'device_id': volume['_id'], 't': i, 'total': 12, 'used': 2, 'percent': 60.0 }) result = system_model.get_device_data_after(timestamp=10, enddate=20, server=self.server, check='disk', device_id=volume['_id']) total = result[1]['data'] eq_(len(total), 11) for entry in total: assert entry['x'] >= 10 assert entry['x'] <= 20 assert entry['y'] == 12 assert type(entry['y']) is float used = result[0]['data'] eq_(len(used), 11) for entry in used: assert entry['x'] >= 10 assert entry['x'] <= 20 assert entry['y'] == 2 # Test global data - used in the dashboards all_servers = server_model.get_all() result = system_model.get_global_device_data_after( timestamp=10, enddate=20, filtered_servers=all_servers, check='disk', key='percent') used_percent = result[0]['data'] eq_(len(used_percent), 11) assert result[0]['name'] == "{0}.test_volume".format( self.server['name']) for entry in used_percent: assert entry['x'] >= 10 assert entry['x'] <= 20 assert entry['y'] == 60.0 assert type(entry['y']) is float self._cleanup()
def get_network_data_test(self): self._cleanup() interface = interfaces_model.get_or_create( server_id=self.server['_id'], name='test_interface') collection = interfaces_model.get_data_collection() for i in range(0, 30): collection.insert({ 'server_id': self.server_id, 'device_id': interface['_id'], 't': i, 'i': 1, 'o': 2 }) result = system_model.get_device_data_after(timestamp=10, enddate=20, server=self.server, check='network', device_id=interface['_id']) inbound = result[0]['data'] eq_(len(inbound), 11) for entry in inbound: assert entry['x'] >= 10 assert entry['x'] <= 20 assert entry['y'] == 1 assert type(entry['y']) is float outbound = result[1]['data'] eq_(len(outbound), 11) for entry in outbound: assert entry['x'] >= 10 assert entry['x'] <= 20 assert entry['y'] == 2 # Test global data - used in the dashboards all_servers = server_model.get_all() result = system_model.get_global_device_data_after( timestamp=10, enddate=20, filtered_servers=all_servers, check='network', key='i') used_percent = result[0]['data'] eq_(len(used_percent), 11) assert result[0]['name'] == "{0}.test_interface".format( self.server['name']) for entry in used_percent: assert entry['x'] >= 10 assert entry['x'] <= 20 assert entry['y'] == 1.0 assert type(entry['y']) is float self._cleanup()