{"id":13504051,"url":"https://github.com/GuillaumeGomez/sysinfo","last_synced_at":"2025-03-29T19:30:43.768Z","repository":{"id":28470368,"uuid":"31986253","full_name":"GuillaumeGomez/sysinfo","owner":"GuillaumeGomez","description":"Cross-platform library to fetch system information","archived":false,"fork":false,"pushed_at":"2025-03-25T12:33:42.000Z","size":3390,"stargazers_count":2389,"open_issues_count":69,"forks_count":342,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-03-25T15:04:43.767Z","etag":null,"topics":["linux","macos","raspberry","rust","system","unix","windows"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GuillaumeGomez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["GuillaumeGomez"],"patreon":"GuillaumeGomez","custom":["https://paypal.me/imperioland"]}},"created_at":"2015-03-10T22:54:41.000Z","updated_at":"2025-03-25T12:33:47.000Z","dependencies_parsed_at":"2023-12-20T08:15:54.095Z","dependency_job_id":"7be7ea74-d973-49be-8c66-5ae4e28284cb","html_url":"https://github.com/GuillaumeGomez/sysinfo","commit_stats":{"total_commits":1660,"total_committers":177,"mean_commits":9.378531073446327,"dds":"0.27409638554216864","last_synced_commit":"88f9c4bd6208140fd1d6ce1f54b5a802fa0e7676"},"previous_names":[],"tags_count":242,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuillaumeGomez%2Fsysinfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuillaumeGomez%2Fsysinfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuillaumeGomez%2Fsysinfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GuillaumeGomez%2Fsysinfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GuillaumeGomez","download_url":"https://codeload.github.com/GuillaumeGomez/sysinfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246234657,"owners_count":20745010,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linux","macos","raspberry","rust","system","unix","windows"],"created_at":"2024-07-31T23:00:53.197Z","updated_at":"2025-03-29T19:30:43.178Z","avatar_url":"https://github.com/GuillaumeGomez.png","language":"Rust","funding_links":["https://github.com/sponsors/GuillaumeGomez","https://patreon.com/GuillaumeGomez","https://paypal.me/imperioland","https://www.patreon.com/GuillaumeGomez"],"categories":["Rust","Libraries","虚拟化"],"sub_categories":["System","系统信息"],"readme":"# sysinfo [![][img_crates]][crates] [![][img_doc]][doc]\n\n`sysinfo` is a crate used to get a system's information.\n\n## Supported OSes\n\nIt currently supports the following OSes (alphabetically sorted):\n\n * Android\n * FreeBSD\n * iOS\n * Linux\n * macOS\n * Raspberry Pi\n * Windows\n\nYou can still use `sysinfo` on non-supported OSes, it'll simply do nothing and always return\nempty values. You can check in your program directly if an OS is supported by checking the\n[`IS_SUPPORTED_SYSTEM`] constant.\n\nThe minimum-supported version of `rustc` is **1.74**.\n\n## Usage\n\nIf you want to migrate from an older version, don't hesitate to take a look at the\n[CHANGELOG](https://github.com/GuillaumeGomez/sysinfo/blob/master/CHANGELOG.md) and at the\n[migration guide](https://github.com/GuillaumeGomez/sysinfo/blob/master/migration_guide.md).\n\n⚠️ Before any attempt to read the different structs' information, you need to update them to\nget up-to-date information because for most of them, it works on diff between the current value\nand the old one.\n\nWhich is why, it's much better to keep the same instance of [`System`] around instead of\nrecreating it multiple times.\n\nYou have an example into the `examples` folder. You can run it with `cargo run --example simple`.\n\nOtherwise, here is a little code sample:\n\n```rust\nuse sysinfo::{\n    Components, Disks, Networks, System,\n};\n\n// Please note that we use \"new_all\" to ensure that all lists of\n// CPUs and processes are filled!\nlet mut sys = System::new_all();\n\n// First we update all information of our `System` struct.\nsys.refresh_all();\n\nprintln!(\"=\u003e system:\");\n// RAM and swap information:\nprintln!(\"total memory: {} bytes\", sys.total_memory());\nprintln!(\"used memory : {} bytes\", sys.used_memory());\nprintln!(\"total swap  : {} bytes\", sys.total_swap());\nprintln!(\"used swap   : {} bytes\", sys.used_swap());\n\n// Display system information:\nprintln!(\"System name:             {:?}\", System::name());\nprintln!(\"System kernel version:   {:?}\", System::kernel_version());\nprintln!(\"System OS version:       {:?}\", System::os_version());\nprintln!(\"System host name:        {:?}\", System::host_name());\n\n// Number of CPUs:\nprintln!(\"NB CPUs: {}\", sys.cpus().len());\n\n// Display processes ID, name na disk usage:\nfor (pid, process) in sys.processes() {\n    println!(\"[{pid}] {:?} {:?}\", process.name(), process.disk_usage());\n}\n\n// We display all disks' information:\nprintln!(\"=\u003e disks:\");\nlet disks = Disks::new_with_refreshed_list();\nfor disk in \u0026disks {\n    println!(\"{disk:?}\");\n}\n\n// Network interfaces name, total data received and total data transmitted:\nlet networks = Networks::new_with_refreshed_list();\nprintln!(\"=\u003e networks:\");\nfor (interface_name, data) in \u0026networks {\n    println!(\n        \"{interface_name}: {} B (down) / {} B (up)\",\n        data.total_received(),\n        data.total_transmitted(),\n    );\n    // If you want the amount of data received/transmitted since last call\n    // to `Networks::refresh`, use `received`/`transmitted`.\n}\n\n// Components temperature:\nlet components = Components::new_with_refreshed_list();\nprintln!(\"=\u003e components:\");\nfor component in \u0026components {\n    println!(\"{component:?}\");\n}\n```\n\nPlease remember that to have some up-to-date information, you need to call the equivalent\n`refresh` method. For example, for the CPU usage:\n\n```rust,no_run\nuse sysinfo::System;\n\nlet mut sys = System::new();\n\nloop {\n    sys.refresh_cpu_usage(); // Refreshing CPU usage.\n    for cpu in sys.cpus() {\n        print!(\"{}% \", cpu.cpu_usage());\n    }\n    // Sleeping to let time for the system to run for long\n    // enough to have useful information.\n    std::thread::sleep(sysinfo::MINIMUM_CPU_UPDATE_INTERVAL);\n}\n```\n\nBy default, `sysinfo` uses multiple threads. However, this can increase the memory usage on some\nplatforms (macOS for example). The behavior can be disabled by setting `default-features = false`\nin `Cargo.toml` (which disables the `multithread` cargo feature).\n\n### Good practice / Performance tips\n\nMost of the time, you don't want all information provided by `sysinfo` but just a subset of it.\nIn this case, it's recommended to use `refresh_specifics(...)` methods with only what you need\nto have much better performance.\n\nAnother issues frequently encountered: unless you know what you're doing, it's almost all the\ntime better to instantiate the `System` struct once and use this one instance through your\nprogram. The reason is because a lot of information needs a previous measure to be computed\n(the CPU usage for example). Another example why it's much better: in case you want to list\nall running processes, `sysinfo` needs to allocate all memory for the `Process` struct list,\nwhich takes quite some time on the first run.\n\nIf your program needs to use a lot of file descriptors, you'd better use:\n\n```rust,no_run\nsysinfo::set_open_files_limit(0);\n```\n\nas `sysinfo` keeps a number of file descriptors open to have better performance on some\ntargets when refreshing processes.\n\n### Running on Raspberry Pi\n\nIt'll be difficult to build on Raspberry Pi. A good way-around is to cross-build, then send the\nexecutable to your Raspberry Pi.\n\nFirst install the arm toolchain, for example on Ubuntu:\n\n```bash\n\u003e sudo apt-get install gcc-multilib-arm-linux-gnueabihf\n```\n\nThen configure cargo to use the corresponding toolchain:\n\n```bash\ncat \u003c\u003c EOF \u003e ~/.cargo/config\n[target.armv7-unknown-linux-gnueabihf]\nlinker = \"arm-linux-gnueabihf-gcc\"\nEOF\n```\n\nFinally, cross compile:\n\n```bash\nrustup target add armv7-unknown-linux-gnueabihf\ncargo build --target=armv7-unknown-linux-gnueabihf\n```\n\n### Linux on Docker \u0026 Windows Subsystem for Linux (WSL)\n\nVirtual Linux systems, such as those run through Docker and Windows Subsystem for Linux (WSL), do\nnot receive host hardware information via `/sys/class/hwmon` or `/sys/class/thermal`. As such,\nquerying for components may return no results (or unexpected results) when using this library on\nvirtual systems.\n\n### Use in binaries running inside the macOS or iOS Sandbox/stores\n\nApple has restrictions as to which APIs can be linked into binaries that are distributed through the app store.\nBy default, `sysinfo` is not compatible with these restrictions. You can use the `apple-app-store`\nfeature flag to disable the Apple prohibited features. This also enables the `apple-sandbox` feature.\nIn the case of applications using the sandbox outside of the app store, the `apple-sandbox` feature\ncan be used alone to avoid causing policy violations at runtime.\n\n### How it works\n\nI wrote a blog post you can find [here][sysinfo-blog] which explains how `sysinfo` extracts information\non the different systems.\n\n[sysinfo-blog]: https://blog.guillaume-gomez.fr/articles/2021-09-06+sysinfo%3A+how+to+extract+systems%27+information\n\n### C interface\n\nIt's possible to use this crate directly from C. Take a look at the `Makefile` and at the\n`examples/simple.c` file.\n\nTo build the C example, just run:\n\n```bash\n\u003e make\n\u003e ./simple\n# If needed:\n\u003e LD_LIBRARY_PATH=target/debug/ ./simple\n```\n\n### Benchmarks\n\nYou can run the benchmarks locally with rust **nightly** by doing:\n\n```bash\n\u003e cargo bench\n```\n\n## Donations\n\nIf you appreciate my work and want to support me, you can do it with\n[github sponsors](https://github.com/sponsors/GuillaumeGomez) or with\n[patreon](https://www.patreon.com/GuillaumeGomez).\n\n[img_crates]: https://img.shields.io/crates/v/sysinfo.svg\n[img_doc]: https://img.shields.io/badge/rust-documentation-blue.svg\n\n[crates]: https://crates.io/crates/sysinfo\n[doc]: https://docs.rs/sysinfo/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGuillaumeGomez%2Fsysinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGuillaumeGomez%2Fsysinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGuillaumeGomez%2Fsysinfo/lists"}