get_sysinfo - Retrieves system information and formats it as a JSON string. Return: A pointer to a dynamically allocated string containing the system information in JSON format, or NULL on failure.
18 {
19 struct new_utsname *uts = utsname();
21 if (!info)
22 return NULL;
23
24 unsigned long ram_mb = (totalram_pages() << PAGE_SHIFT) / 1024 / 1024;
25 int cpu_count = num_online_cpus();
26 const char *cpu_model =
27 boot_cpu_data.x86_model_id[0] ? boot_cpu_data.x86_model_id : "Unknown";
28
30 "{\n"
31 " \"hostname\": \"%s\",\n"
32 " \"system\": \"%s\",\n"
33 " \"virtual_env\": \"%s\",\n"
34 " \"release\": \"%s\",\n"
35 " \"version\": \"%s\",\n"
36 " \"architecture\": \"%s\",\n"
37 " \"ram_mb\": \"%lu\",\n"
38 " \"cpu_model\": \"%s\",\n"
39 " \"cpu_cores\": \"%d\"\n"
40 "}\n",
41 uts->nodename, uts->sysname,
43 uts->version, uts->machine, ram_mb, cpu_model, cpu_count);
44
45 return info;
46}
bool is_running_in_virtual_env(void)
Determines if the system is running in a virtualized environment.