X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c314a3092c5b51c7782015f6fa9ac093b46fa174..1f0796778754d8df0dfab9dd01302e26a397f064:/src/nominatim_db/tools/collect_os_info.py diff --git a/src/nominatim_db/tools/collect_os_info.py b/src/nominatim_db/tools/collect_os_info.py index e1f8b166..fc921b20 100644 --- a/src/nominatim_db/tools/collect_os_info.py +++ b/src/nominatim_db/tools/collect_os_info.py @@ -12,21 +12,15 @@ import os import subprocess import sys from pathlib import Path -from typing import List, Optional, Tuple, Union +from typing import List, Optional, Union import psutil -from psycopg2.extensions import make_dsn, parse_dsn from ..config import Configuration -from ..db.connection import connect +from ..db.connection import connect, server_version_tuple, execute_scalar from ..version import NOMINATIM_VERSION -def convert_version(ver_tup: Tuple[int, int]) -> str: - """converts tuple version (ver_tup) to a string representation""" - return ".".join(map(str, ver_tup)) - - def friendly_memory_string(mem: float) -> str: """Create a user friendly string for the amount of memory specified as mem""" mem_magnitude = ("bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") @@ -102,17 +96,17 @@ def report_system_information(config: Configuration) -> None: """Generate a report about the host system including software versions, memory, storage, and database configuration.""" - with connect(make_dsn(config.get_libpq_dsn(), dbname='postgres')) as conn: - postgresql_ver: str = convert_version(conn.server_version_tuple()) + with connect(config.get_libpq_dsn(), dbname='postgres') as conn: + postgresql_ver: str = '.'.join(map(str, server_version_tuple(conn))) with conn.cursor() as cur: - num = cur.scalar("SELECT count(*) FROM pg_catalog.pg_database WHERE datname=%s", - (parse_dsn(config.get_libpq_dsn())['dbname'], )) - nominatim_db_exists = num == 1 if isinstance(num, int) else False + cur.execute("SELECT datname FROM pg_catalog.pg_database WHERE datname=%s", + (config.get_database_params()['dbname'], )) + nominatim_db_exists = cur.rowcount > 0 if nominatim_db_exists: with connect(config.get_libpq_dsn()) as conn: - postgis_ver: str = convert_version(conn.postgis_version_tuple()) + postgis_ver: str = execute_scalar(conn, 'SELECT postgis_lib_version()') else: postgis_ver = "Unable to connect to database" @@ -138,24 +132,25 @@ def report_system_information(config: Configuration) -> None: - PostgreSQL version: {postgresql_ver} - PostGIS version: {postgis_ver} - OS: {os_name_info()} - - + + **Hardware Configuration:** - RAM: {friendly_memory_string(psutil.virtual_memory().total)} - number of CPUs: {psutil.cpu_count(logical=False)} - - bare metal/AWS/other cloud service (per systemd-detect-virt(1)): {run_command("systemd-detect-virt")} + - bare metal/AWS/other cloud service (per systemd-detect-virt(1)): + {run_command("systemd-detect-virt")} - type and size of disks: **`df -h` - df - report file system disk space usage: ** ``` {run_command(["df", "-h"])} ``` - + **lsblk - list block devices: ** ``` {run_command("lsblk")} ``` - - + + **Postgresql Configuration:** ``` {postgresql_config}