in nl2sql_library/nl2sql/commons/reporting/fingerprint.py [0:0]
def sys_info() -> dict[str, Any | None]:
"""
Provides information about the machine running the NL2SQL Code
To disable this data collection, create an environment variable
called "NL2SQL_DISABLE_SYSINFO".
"""
if "NL2SQL_DISABLE_SYSINFO" in os.environ:
return {"SYSINFO_ENABLED": False}
try:
base_url = "http://metadata.google.internal"
version = "computeMetadata/v1"
resource = "instance/hostname"
metadata_url = f"{base_url}/{version}/{resource}"
r_hostname = requests.get(
metadata_url,
headers={"Metadata-Flavor": "Google"},
timeout=60,
)
r_hostname.raise_for_status()
metadata_hostname = r_hostname.text
except Exception as exc: # pylint: disable=broad-exception-caught
logger.warning(str(exc))
metadata_hostname = None
try:
base_url = "http://metadata.google.internal"
version = "computeMetadata/v1"
resource = "instance/machine-type"
metadata_url = f"{base_url}/{version}/{resource}"
r_machinetype = requests.get(
metadata_url,
headers={"Metadata-Flavor": "Google"},
timeout=60,
)
r_machinetype.raise_for_status()
metadata_machinetype = r_machinetype.text
except Exception as exc: # pylint: disable=broad-exception-caught
logger.warning(str(exc))
metadata_machinetype = None
# cpu_info = cpuinfo.get_cpu_info()
mem_info = psutil.virtual_memory()
return {
"SYSINFO_ENABLED": True,
**platform.uname()._asdict(),
"node_uuid": uuid.getnode(),
"boot_time_epoch": psutil.boot_time(),
"python_version": "dummy",
"python_build": sys.version,
"cpu_bits": "dummy",
"cpu_count": "dummy",
"cpu_model": "dummy",
"cpu_vendor": "dummy",
"cpu_hz": "dummy",
"ram_total_bytes": mem_info.total,
"ram_available_bytes": mem_info.available,
"is_colab": "google.colab" in sys.modules,
"gcp_hostname": metadata_hostname,
"gcp_machinetype": metadata_machinetype,
}