Cross-platform async library for system information fetching 🦀

Overview

heim

Project banner

Latest Version Latest Version User guide Gitter
Coverage Status Financial Contributors on Open Collective Apache 2.0 OR MIT licensed

Cross-platform library for system information fetching

heim is an ongoing attempt to create the best tool for system information fetching (ex., CPU, memory, disks or processes stats) in the Rust crates ecosystem.
It targets to have at least the same functionality as psutil, gopsutil or oshi eventually.

Check user guide to get more information on the heim goals, integrations and showcases.

Why should I use heim instead of {crate-name}? See the comparison page.

Examples can be found here.

Background

heim has a few key goals which define its development and public interface:

  1. Async-first with tokio and async-std support.
    Bundled polyfill option could be used for other use cases, see documentation for more details.
  2. Cross-platform with platform-specific extensions.
  3. Modular design.
  4. Idiomatic and easy to use.

Technical notes

heim requires Rust 1.45 or higher; this version is explicitly tested in CI and may be bumped in any major or minor release as needed.
Any changes to the supported minimum version will be called out in the release notes.

Platform support

Right now heim support Tier 1 platforms (Linux, macOS, and Windows for i686 and x86_64). You can check the GitHub projects page for more information.

License

Licensed under either of Apache License 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Donations

If you appreciate my work and want to support me or speed up the project development, you can do it here or support this project at Open Collective.

Contributors

Code Contributors

This project exists thanks to all the people who contribute.

Financial Contributors

Become a financial contributor and help us sustain our community.

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website.

Comments
  • Adds configurable path to /sys and /proc via naive global state

    Adds configurable path to /sys and /proc via naive global state

    Closes #276

    I work with @MOZGIII and @jamtur01 on vector. I implemented this as requested in #276. I think some of the concerns of an implementation in this shape will probably be clear from the PR. However this does at least unblock us in Vector. Obviously please let us know any alterations you'd like me to make!

    Signed-off-by: Ian Henry [email protected]

    opened by eeyun 26
  • Implement nic on windows

    Implement nic on windows

    Hello, I had to implement a piece of heim for my needs, let"s share it!

    This MR implements heim::net::nic() on Windows using the GetAdaptersAddresses API. It closes #24

    It also adds an index() member function for Nics on Windows, macOS and Linux

    opened by daladim 10
  • Cpu frequency with neon bindings

    Cpu frequency with neon bindings

    Hello, i'm new to Heim and rust, i'm building a neon-binding for Heim.

    i tried Host module and it works great, but i have a problem with cpu frequency, it returns zero, is there a compatibility issue with neon?

    i'm using Windows 10, with AMD cpu and my version of rustc is 1.42.0

    heim = { git='https://github.com/heim-rs/heim', features = ["cpu","host","runtime-tokio"] } tokio = { version = "*", features = ["full", "macros"] } neon = "0.4.0"

    heres my code

    struct CpuFreq;
    
    impl Task for CpuFreq{
        type Output = u64;
        type Error = Error;
        type JsEvent = JsNumber;
        #[tokio::main]
        async fn perform(&self) -> Result<u64> {
            let freq = cpu::frequency().await?;
            Ok(freq.current().get::<units::frequency::millihertz>())
        }
        fn complete(self, mut cx: TaskContext, result: Result<u64>) -> JsResult<JsNumber> {
            match result {
                Ok(cpu) => Ok(cx.number(cpu as f64)),
                Err(err) => cx.throw_error(err.to_string()),
            }
        }
    }
    
    
    pub fn cpu_frequency(mut cx: FunctionContext) -> JsResult<JsUndefined> {
        let f = cx.argument::<JsFunction>(0)?;
        CpuFreq.schedule(f);
        Ok(cx.undefined())
    }
    
    register_module!(mut cx, {
        cx.export_function("cpuFrequency", cpu_frequency)?;
        Ok(())
    });
    

    i run in node with this

    var addon = require('../native');
    const { promisify } = require('util');
    
    addon.cpuFrequencyP= promisify(addon.cpuFrequency);
    
      addon
          .cpuFrequencyP()
          .then(console.log)
          .catch(console.error)
    
    A-cpu C-bug O-windows 
    opened by zenhuw 10
  • Provide ability to configure the location of the /proc and /sys directories

    Provide ability to configure the location of the /proc and /sys directories

    A lot of folks collect host metrics using monitoring tools running inside Docker or Kubernetes. Inside these containers, to access the host system underneath, we need to bind-mount /proc and /sys into the container so the monitoring tool finds the right filesystem. The monitoring tool is then configurable to specify the bind-mount instead of the container's filesystem.

    A good example is the Prometheus node_exporter, this setup you can see in their Helm chart for deploying in k8s: https://github.com/prometheus-community/helm-charts/blob/main/charts/prometheus-node-exporter/templates/daemonset.yaml). The node_exporter then has some configuration to specify the location of /proc and /sys:

    The volumes:

          volumes:
            - name: proc
              hostPath:
                path: /proc
            - name: sys
              hostPath:
                path: /sys
    

    The bind-mount:

              volumeMounts:
                - name: proc
                  mountPath: /host/proc
                  readOnly:  true
                - name: sys
                  mountPath: /host/sys
                  readOnly: true
    

    The node_exporter configuration:

         containers:
            - name: node-exporter
              image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
              imagePullPolicy: {{ .Values.image.pullPolicy }}
              args:
                - --path.procfs=/host/proc
                - --path.sysfs=/host/sys
    

    It'd be great if heim had the option to configure the location of the relevant filesystems to allow this use case.

    A-virt C-enhancement O-linux 
    opened by jamtur01 9
  • Building heim 0.0.6 with musl

    Building heim 0.0.6 with musl

    I'm trying to compile heim with --target x86_64-unknown-linux-musl and running into the following:

    error[E0425]: cannot find value `ST_RELATIME` in crate `libc`
      --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/heim-disk-0.0.6/src/os/unix/usage.rs:59:32
       |
    59 |         const RELATIME = libc::ST_RELATIME;
       |                                ^^^^^^^^^^^ help: a constant with a similar name exists: `MS_RELATIME`
    
    error: aborting due to previous error
    

    This flag isn't defined in rusts musl libc (though it is relatively recently defined upstream in musl itself in 1.1.20) The usage is here: https://github.com/heim-rs/heim/blob/master/heim-disk/src/os/unix/usage.rs#L53-L59

    But the comment is confusing me, as it seems to imply that the flag should only exist on macOS targets but then the cfg! macro says the opposite (that it should exist on any non-macOS unix-like).

    I wasn't sure if this was an issue for either libc or for heim (perhaps both) but the seeming contradiction in the comments made me think that an issue should be raised here.

    A-disk C-bug O-linux 
    opened by bsundsrud 9
  • Fix macos process kinfo

    Fix macos process kinfo

    copy-pasting from rust-psutil/rust-psutil#80 with some small tweaks

    In cjbassi/ytop#75 some users, specifically on MacOS, were running into issues where OsError { source: Os { code: 12, kind: Other, message: "Cannot allocate memory" } } was being returned when trying to update the process list.

    I eventually tracked this down to processes() that had a couple of issues leading to this problem:

    1. reserve will reserve an additional number of elements represented by the value passed in whereas here it was being given the expected size of all elements in bytes. This was resulting in much more space being reserved than was required.
    2. Incorrectly checking for ENOMEM. Based on this document:

    If the amount of data available is greater than the size of the buffer supplied, the call supplies as much data as fits in the buffer provided and returns with the error code ENOMEM.

    However

    Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

    So I can understand the confusion from the wording, but when it mentions returning ENOMEM this is in the form of errno, not as the return value from the function call. This manifested where the code would check for ENOMEM from sysctl instead of errno, which would cause the error to bubble up instead of appropriately retrying. I think the large reserve size made this case easier to hit since it would stall for more time between reading for the required size and attempting to store.

    I would appreciate a thorough look over the changes since it's pretty close to messing with unsafe code and I was able to reproduce the issue on MacOS, but didn't have a chance to verify that the changes work correctly.

    opened by LovecraftianHorror 8
  • process::Process:name is truncated for Linux

    process::Process:name is truncated for Linux

    /proc/{pid}/stat returns truncated (capped to 15 chars) process name, Process::cmdline could be used to fetch full process name if necessary.

    Blocked by #97

    A-process C-enhancement O-linux 
    opened by svartalf 8
  • fix swap file calculation on windows

    fix swap file calculation on windows

    ullTotalPageFile and ullAvailPageFile include both the swap and physical memory so in order to get the correct swap memory values the physical memory size/usage needs to be subtracted.

    https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex

    opened by davidkna 6
  • Bump ordered-float to v1.1.1 in v0.0.x due to potential UB

    Bump ordered-float to v1.1.1 in v0.0.x due to potential UB

    As per RUSTSEC-2020-0082, version 1.1.1 of the ordered-float dependency fixes a potential cause of UB.

    This doesn't appear to affect the master branch, but it does affect v0.0.x versions.

    opened by ClementTsang 6
  • Fix building on non-x86 compatible archs

    Fix building on non-x86 compatible archs

    I am using an ARM arch, so the commit fixes project building under non-x86 compatibility architectures by disabling raw-cpuid crate that may work on x86\amd64 archs only.

    opened by Fenex 6
  • Querying users crashes in Windows

    Querying users crashes in Windows

    I can pretty consistently get a crash from this code snippet while querying the users on Windows (Windows 10 Enterprise, Version 1903. Build: 18362.239):

        let mut users = heim::host::users();
        while let Some(user) = users.next().await {
        }
    

    I can only reproduce this when running in release mode. It doesn't seem to repro in debug mode.

    A-host C-bug O-windows P-high 
    opened by jntrnr 6
  • RUSTSEC-2021-0139: ansi_term is Unmaintained

    RUSTSEC-2021-0139: ansi_term is Unmaintained

    ansi_term is Unmaintained

    | Details | | | ------------------- | ---------------------------------------------- | | Status | unmaintained | | Package | ansi_term | | Version | 0.12.1 | | URL | https://github.com/ogham/rust-ansi-term/issues/72 | | Date | 2021-08-18 |

    The maintainer has adviced this crate is deprecated and will not receive any maintenance.

    The crate does not seem to have much dependencies and may or may not be ok to use as-is.

    Last release seems to have been three years ago.

    Possible Alternative(s)

    The below list has not been vetted in any way and may or may not contain alternatives;

    See advisory page for additional details.

    opened by github-actions[bot] 0
  • Maintained

    Maintained

    I noticed this project is not receiving any updates and a few security concerns have shown up.

    @svartalf are you needing any help maintaining this project?

    opened by wyatt-herkamp 6
  • error when compiling  heim-net under Ubuntu 18.04 and 20.04

    error when compiling heim-net under Ubuntu 18.04 and 20.04

    It seems that there is an error in a dependency to heim when trying to compile heim-net, complaining for a not implemented Error train coming from testdir crate:

    Compiling heim-net v0.1.0-beta.2
     Compiling tofnd v0.9.1 (/home/tofnd)
    error[E0277]: `?` couldn't convert the error to `heim_common::Error`
    --> /home/.cargo/registry/src/github.com-1ecc6299db9ec823/heim-net-0.1.0-beta.2/src/sys/unix/nic.rs:66:37
     |
    66 |     let iter = ifaddrs::getifaddrs()?.filter_map(|addr| {
     |                                     ^ the trait `From<nix::Error>` is not implemented for `heim_common::Error`
     |
     = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
     = help: the following implementations were found:
               <heim_common::Error as From<Infallible>>
               <heim_common::Error as From<NulError>>
               <heim_common::Error as From<ParseFloatError>>
               <heim_common::Error as From<ParseIntError>>
             and 2 others
     = note: required because of the requirements on the impl of `FromResidual<std::result::Result<Infallible, nix::Error>>` for `std::result::Result<_, heim_common::Error>`
    
    For more information about this error, try `rustc --explain E0277`.
    
    opened by leontiad 0
  • RUSTSEC-2021-0127: serde_cbor is unmaintained

    RUSTSEC-2021-0127: serde_cbor is unmaintained

    serde_cbor is unmaintained

    | Details | | | ------------------- | ---------------------------------------------- | | Status | unmaintained | | Package | serde_cbor | | Version | 0.11.2 | | URL | https://github.com/pyfisch/cbor | | Date | 2021-08-15 |

    The serde_cbor crate is unmaintained. The author has archived the github repository.

    Alternatives proposed by the author:

    See advisory page for additional details.

    opened by github-actions[bot] 0
  • Can't use `sensors::temperatures` function in different thread

    Can't use `sensors::temperatures` function in different thread

    If the sensors::temperatures function is spawned into a different thread, it fails with implementation of `std::ops::FnOnce` is not general enough.

    MWE:

    use futures::StreamExt;
    use heim::sensors;
    
    #[tokio::main]
    async fn main() {
        tokio::spawn(async {
            sensors::temperatures()
                .collect::<Vec<Result<sensors::TemperatureSensor, heim::Error>>>()
                .await
        });
    }
    
    opened by ravenclaw900 0
Releases(v0.1.0-rc.1)
An impish, cross-platform binary parsing crate, written in Rust

libgoblin Documentation https://docs.rs/goblin/ changelog Usage Goblin requires rustc 1.40.0. Add to your Cargo.toml [dependencies] goblin = "0.4" Fea

null 891 Dec 29, 2022
A self-hosted Fuzzing-As-A-Service platform

OneFuzz A self-hosted Fuzzing-As-A-Service platform Project OneFuzz enables continuous developer-driven fuzzing to proactively harden software prior t

Microsoft 2.6k Jan 8, 2023
Secure sandboxing system for untrusted code execution

Godbox Secure sandboxing system for untrusted code execution. It uses isolate which uses specific functionnalities of the Linux kernel, thus godbox no

Nathanael Demacon 19 Dec 14, 2022
MimiRust - Hacking the Windows operating system to hand us the keys to the kingdom with Rust.

MimiRust - Hacking the Windows operating system to hand us the keys to the kingdom with Rust. MimiRust is a program based on the wdigest attack vector

Thotty 0 Nov 29, 2022
A private network system that uses WireGuard under the hood.

innernet A private network system that uses WireGuard under the hood. See the announcement blog post for a longer-winded explanation. innernet is simi

Tonari, Inc 4.1k Jan 6, 2023
A cryptographically verifiable code review system for the cargo (Rust) package manager.

image credit cargo-crev A cryptographically verifiable code review system for the cargo (Rust) package manager. Introduction Crev is a language and ec

crev - Code REView system 1.8k Jan 5, 2023
Cover your tracks during Linux Exploitation by leaving zero traces on system logs and filesystem timestamps. 👻🐚

moonwalk Cover your tracks during Linux Exploitation / Penetration Testing by leaving zero traces on system logs and filesystem timestamps. ?? Table o

Mufeed VH 1.1k Jan 6, 2023
Bottlerocket - An operating system designed for hosting containers

Bottlerocket OS Welcome to Bottlerocket! Bottlerocket is a free and open-source Linux-based operating system meant for hosting containers. If you’re r

null 7k Dec 31, 2022
Crate for calling NT System Calls easily

ntcall-rs Easily call NT System Calls from rust. All System Call ID’s are dumped at compile-time. To get started just import the function you would li

joshuа 7 Sep 14, 2022
cert_installer - a utility that adds a CA certificate to Android's System Trust Store

cert_installer is a utility that adds a CA certificate to Android's System Trust Store by overwriting the /system/etc/security/cacerts directory with a tmpfs mount. Changes made to the System Trust Store is not persistant across reboots.

Terry Chia 5 Apr 11, 2022
Rust implementation of the H3 geospatial indexing system.

h3o Rust implementation of the H3 geospatial indexing system. Design This is not a binding of the reference implementation, but a reimplementation fro

Hydronium Labs 196 Jan 31, 2023
CVEs for the Rust standard library

Rust CVE Preface This is a list of CVEs for unsound APIs in the Rust standard library. These bugs break Rust's memory safety guarantee and lead to sec

Yechan Bae 26 Dec 4, 2022
Rust library for building and running BPF/eBPF modules

RedBPF A Rust eBPF toolchain. Overview The redbpf project is a collection of tools and libraries to build eBPF programs using Rust. It includes: redbp

foniod 1.5k Jan 1, 2023
unfuck is a utility and library for deobfuscating obfuscated Python 2.7 bytecode

unfuck is a utility and library for deobfuscating obfuscated Python 2.7 bytecode. It is essentially a reimplementation of the Python VM with taint tracking.

Lander Brandt 171 Dec 14, 2022
Rust library for developing safe canisters.

IC Kit This library provides an alternative to ic-cdk that can help developers write canisters and unit test them in their Rust code. Install Add this

Psychedelic 26 Nov 28, 2022
Advanced Fuzzing Library - Slot your Fuzzer together in Rust! Scales across cores and machines. For Windows, Android, MacOS, Linux, no_std, ...

LibAFL, the fuzzer library. Advanced Fuzzing Library - Slot your own fuzzers together and extend their features using Rust. LibAFL is written and main

Advanced Fuzzing League ++ 1.2k Jan 6, 2023
Xori is an automation-ready disassembly and static analysis library for PE32, 32+ and shellcode

Xori - Custom disassembly framework Xori is an automation-ready disassembly and static analysis library that consumes shellcode or PE binaries and pro

ENDGAME 712 Nov 28, 2022
QuickCheck bug hunting in Rust standard library data structures

BugHunt, Rust This project is aiming to provide "stateful" QuickCheck models for Rust's standard library. That is, we build up a random list of operat

Brian L. Troutwine 161 Dec 15, 2022
Mundane is a Rust cryptography library backed by BoringSSL that is difficult to misuse, ergonomic, and performant (in that order).

Mundane Mundane is a Rust cryptography library backed by BoringSSL that is difficult to misuse, ergonomic, and performant (in that order). Issues and

Google 1.1k Jan 3, 2023