in 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:
r_hostname = requests.get(
"http://metadata.google.internal/computeMetadata/v1/instance/hostname",
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:
r_machinetype = requests.get(
"http://metadata.google.internal/computeMetadata/v1/instance/machine-type",
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": cpu_info["python_version"],
"python_build": sys.version,
"cpu_bits": cpu_info["bits"],
"cpu_count": cpu_info["count"],
"cpu_model": cpu_info["brand_raw"],
"cpu_vendor": cpu_info["vendor_id_raw"],
"cpu_hz": cpu_info["hz_actual_friendly"],
"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,
}