def list(self, request): path = request.query_params.get('path') if path is None: free = get_free_space() else: free = get_free_space(path) return Response({"freespace": free})
def list(self, request): path = request.query_params.get('path') if path is None: free = get_free_space() else: free = get_free_space(path) return Response({"freespace": free})
def list(self, request): path = request.query_params.get("path") if path is None: free = get_free_space() elif path == "Content": free = get_free_space(OPTIONS["Paths"]["CONTENT_DIR"]) else: free = get_free_space(path) return Response({"freespace": free})
def get(self, request, format=None): info = {} info['version'] = kolibri.__version__ status, urls = get_urls() if not urls: # Will not return anything when running the debug server, so at least return the current URL urls = [request.build_absolute_uri('/')] filtered_urls = [url for url in urls if '127.0.0.1' not in url and 'localhost' not in url] if filtered_urls: urls = filtered_urls info['urls'] = urls if settings.DATABASES['default']['ENGINE'].endswith('sqlite3'): # If any other database backend, will not be file backed, so no database path to return info['database_path'] = settings.DATABASES['default']['NAME'] instance_model = InstanceIDModel.get_or_create_current_instance()[0] info['device_name'] = instance_model.hostname info['device_id'] = instance_model.id info['os'] = instance_model.platform info['content_storage_free_space'] = get_free_space() # This returns the localized time for the server info['server_time'] = local_now() # Returns the named timezone for the server (the time above only includes the offset) info['server_timezone'] = settings.TIME_ZONE return Response(info)
def get(self, request, format=None): info = {} info["version"] = kolibri.__version__ status, urls = get_urls() if not urls: # Will not return anything when running the debug server, so at least return the current URL urls = [ request.build_absolute_uri(OPTIONS["Deployment"]["URL_PATH_PREFIX"]) ] filtered_urls = [ url for url in urls if "127.0.0.1" not in url and "localhost" not in url ] if filtered_urls: urls = filtered_urls info["urls"] = urls db_engine = settings.DATABASES["default"]["ENGINE"] if db_engine.endswith("sqlite3"): # Return path to .sqlite file (usually in KOLIBRI_HOME folder) info["database_path"] = settings.DATABASES["default"]["NAME"] elif db_engine.endswith("postgresql"): info["database_path"] = "postgresql" else: info["database_path"] = "unknown" instance_model = InstanceIDModel.get_or_create_current_instance()[0] info["device_id"] = instance_model.id info["os"] = instance_model.platform info["content_storage_free_space"] = get_free_space( OPTIONS["Paths"]["CONTENT_DIR"] ) # This returns the localized time for the server info["server_time"] = local_now() # Returns the named timezone for the server (the time above only includes the offset) info["server_timezone"] = settings.TIME_ZONE info["installer"] = installation_type() info["python_version"] = "{major}.{minor}.{micro}".format( major=version_info.major, minor=version_info.minor, micro=version_info.micro ) return Response(info)
def get(self, request, format=None): info = {} info["version"] = kolibri.__version__ status, urls = get_urls() if not urls: # Will not return anything when running the debug server, so at least return the current URL urls = [ request.build_absolute_uri( OPTIONS["Deployment"]["URL_PATH_PREFIX"]) ] filtered_urls = [ url for url in urls if "127.0.0.1" not in url and "localhost" not in url ] if filtered_urls: urls = filtered_urls info["urls"] = urls if settings.DATABASES["default"]["ENGINE"].endswith("sqlite3"): # If any other database backend, will not be file backed, so no database path to return info["database_path"] = settings.DATABASES["default"]["NAME"] instance_model = InstanceIDModel.get_or_create_current_instance()[0] info["device_name"] = instance_model.hostname info["device_id"] = instance_model.id info["os"] = instance_model.platform info["content_storage_free_space"] = get_free_space( OPTIONS["Paths"]["CONTENT_DIR"]) # This returns the localized time for the server info["server_time"] = local_now() # Returns the named timezone for the server (the time above only includes the offset) info["server_timezone"] = settings.TIME_ZONE info["installer"] = installation_type() return Response(info)
def get(self, request, format=None): info = {} info['version'] = kolibri.__version__ status, urls = get_urls() if not urls: # Will not return anything when running the debug server, so at least return the current URL urls = [request.build_absolute_uri('/')] filtered_urls = [ url for url in urls if '127.0.0.1' not in url and 'localhost' not in url ] if filtered_urls: urls = filtered_urls info['urls'] = urls if settings.DATABASES['default']['ENGINE'].endswith('sqlite3'): # If any other database backend, will not be file backed, so no database path to return info['database_path'] = settings.DATABASES['default']['NAME'] instance_model = InstanceIDModel.get_or_create_current_instance()[0] info['device_name'] = instance_model.hostname info['device_id'] = instance_model.id info['os'] = instance_model.platform info['content_storage_free_space'] = get_free_space() # This returns the localized time for the server info['server_time'] = local_now() # Returns the named timezone for the server (the time above only includes the offset) info['server_timezone'] = settings.TIME_ZONE return Response(info)
def handle(self, *args, **options): if not SUPPORTED_OS: print("This OS is not yet supported") sys.exit(1) try: get_kolibri_use() except NotRunning: sys.exit("Profile command executed while Kolibri server was not running") get_requests_info() self.messages = [] self.add_header("Sessions") session_parameters = ( "Active sessions (guests incl)", "Active users in (10 min)", "Active users in (1 min)", ) session_info = get_db_info() self.add_section(session_parameters, session_info) self.add_header("CPU") kolibri_cpu, kolibri_mem = get_kolibri_use() used_cpu, used_memory, total_memory, total_processes = get_machine_info() cpu_parameters = ("Total processes", "Used CPU", "Kolibri CPU usage") cpu_values = ( total_processes, "{} %".format(used_cpu), "{} %".format(kolibri_cpu), ) self.add_section(cpu_parameters, cpu_values) self.add_header("Memory") memory_parameters = ("Used memory", "Total memory", "Kolibri memory usage") memory_values = ( "{} Mb".format(used_memory), "{} Mb".format(total_memory), "{} Mb".format(kolibri_mem), ) self.add_section(memory_parameters, memory_values) self.add_header("Channels") channels_stats = get_channels_usage_info() self.messages.append(format_line("Total Channels", str(len(channels_stats)))) for channel in channels_stats: self.messages.append("\033[95m* {}\033[0m".format(channel.name)) self.messages.append(format_line("Accesses", channel.accesses, True)) self.messages.append(format_line("Time spent", channel.time_spent, True)) self.add_header("Requests timing") requests_stats = get_requests_info() requests_parameters = ("Homepage", "Recommended channels", "Channels") self.add_section(requests_parameters, requests_stats) self.add_header("Device info") instance_model = InstanceIDModel.get_or_create_current_instance()[0] self.messages.append(format_line("Version", kolibri.__version__)) self.messages.append(format_line("OS", instance_model.platform)) self.messages.append( format_line("Installer", installation_type(get_kolibri_process_cmd())) ) self.messages.append( format_line("Database", settings.DATABASES["default"]["NAME"]) ) self.messages.append(format_line("Device name", instance_model.hostname)) self.messages.append( format_line( "Free disk space", "{} Mb".format(get_free_space() / pow(2, 20)) ) ) self.messages.append(format_line("Server time", local_now())) self.messages.append(format_line("Server timezone", settings.TIME_ZONE)) self.messages.append("") print("\n".join(self.messages))