Git Product home page Git Product logo

systemstat's People

Contributors

adumbidiot avatar aep avatar antoyo avatar biluohc avatar colindean avatar dalan94 avatar davidkna avatar esukmean avatar fenhl avatar kevingage avatar leonpuchinger avatar liff avatar msrd0 avatar nemosupremo avatar nsavch avatar patrickelectric avatar pdcalado avatar pierrechevalier83 avatar rabite0 avatar shssoichiro avatar techno-fox avatar teutat3s avatar valpackett avatar velfi avatar warrenfalk avatar wose avatar zesterer avatar zn3x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

systemstat's Issues

cpu_temp returns the error message: "Not supported" on Windows 10

Upon running cargo run from terminal the call to system.cpu_temp() returns the error message: Not supported for Windows 10. Even though it says on the crates.io page that there should be support for Windows.

Attached code where i tried to get cpu_temp:

extern crate systemstat;

use std::thread;
use std::time::Duration;
use systemstat::{System, Platform, saturating_sub_bytes};

fn main() {
    let system = System::new();

    match system.cpu_temp() {
        Ok(cpu_temp) => println!("\nCPU temp: {}", cpu_temp),
        Err(ex) => println!("\nCPU temp: {}", ex) 
    }
}

Can't get memory usage on macOS

This code :

let sys = System::new();
let memory_usage = sys.memory().unwrap()

Panic with this error message :

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "Not supported" }', src/main.rs:36:24

Compile error on master (c27e070)

Compiling c27e070 on Linux:

   Compiling systemstat v0.1.2 (https://github.com/myfreeweb/systemstat#c27e070b)
error[E0308]: mismatched types
   --> /home/ploppz/.cargo/git/checkouts/systemstat-39467158cd685114/c27e070/src/platform/linux.rs:365:30
    |
365 |             .and_then(|data| data.parse::<f32>())
    |                              ^^^^^^^^^^^^^^^^^^^ expected struct `std::io::Error`, found struct `std::num::ParseFloatError`
    |
    = note: expected type `std::result::Result<_, std::io::Error>`
               found type `std::result::Result<f32, std::num::ParseFloatError>`

error: aborting due to previous error

I personally changed it to .and_then(|data| Ok(data.parse::<f32>().unwrap())) because I'm not sure how to convert to another error type sensibly. It would be easier with error_chain, don't you think? Or at least a custom error type that encompasses io::Error and num::ParseFloatError and whatever is needed.

Cross-compil from Linux to Windows failed

When building my application which use systemstat from a Linux host to a windows target (cargo build --target=x86_64-pc-windows-gnu the linker failed ( /usr/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lIphlpapi).
The problem is that the library in mingw is in totally in lowercase (iphlpapi) but the linker attribute (in socket.rs and network_interfaces.rs) has the first letter in uppercase (Iphlpapi).
Could you change the linker attributes to make the build succeed.
It shouldn't change the Windows behavior because the filename are case insensitive in Windows.

Regards

OS Error 21 thrown when getting mounts on Windows Server 2008R2

When executing the System::mounts() function on Windows Server 2008, it returns the following error:

The device is not ready. (os error 21)

I tried debugging the application but because this is a production machine, I am not able to install rust and therefore the backtrace generated is just a bunch of <unknown>s.

λ cargo --version
cargo 1.34.0 (6789d8a0a 2019-04-01)
λ rustc --version
rustc 1.34.1 (fc50f328b 2019-04-24)
Windows Version: Windows Server 2008 R2

Expose iowait statistics on linux

I thought this was already done when I wrote #22. I'd be interested in adding it.

I'd propose adding an os-specific field to CpuLoad to track this quantity (since I don't believe it's readily available on BSD).

Crates.io

Does crates.io automatically update,, or has the crate version with feature serde not been uploaded yet?

Add support for linux

Hello.
The network code for FreeBSD also works for Linux, so that would be great to add it for Linux.
The current Linux code for the battery, however, does not work on my computer since I do not have the same files.
Perhaps there is an API similar to the one used for FreeBSD.
Thanks.

Next release?

Sorry to bother you with an issue, but I was wondering if there were plans for a new release? It seems that the master branch has quite a few new things while the latest release e.g. doesn't support macOS yet :)

Request: Add total file count and available file count to Filesystem struct

Currently you can get Filename::files which holds the number files (inodes) in use for a filesystem. (On FreeBSD; in Linux it holds the total capacity which I think may be an error, see #28 )

In order to be able to report this as a percentage of the whole, it would be nice to be able to also get the total number of files a filesystem can have (e.g. files_total).

Also Linux has both "free" and "available" counts for files. It would be nice to be able to get both numbers, as the latter is often more relevant. Since FreeBSD doesn't seem to have "available" we could just map the same value as for "free".

So I'd like to add as follows

struct Filesystem {
    files: usize,
    files_total: usize, // definitely this
    files_avail: usize, // also this, if possible
    /* ... */
}

Call loop in provided uptime/boot_time methods

We are currently using this crate and are implementing the Platform trait for a dummy/test platform for our unit tests.
The trait provides methods uptime and boot_time, but they each call each other, leading to a stack overflow unless one overrides either of them (as is done in the implementation for Linux where uptime is overridden).

See also: https://github.com/myfreeweb/systemstat/blob/master/src/platform/common.rs#L37 and https://github.com/myfreeweb/systemstat/blob/master/src/platform/common.rs#L45.

In our opinion, the uptime method should not be provided but required or this should be documented at the minimum.

Panic under FreeBSD 12 - attempt to subtract with overflow

Using master at commit 59929b2d7f5d4e520e6dec03499d71c2460fd866 and using FreeBSD 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC amd64 with rustc 1.36.0-nightly (d35181ad8 2019-05-20)

I get the following error when running cargo test:

# cargo test   
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running target/debug/deps/systemstat-29c6b1a37a7b0b74

running 10 tests
test platform::tests::test_battery_life ... ok
test platform::tests::test_cpu_measurement_is_send ... ok
test platform::tests::test_memory ... ok
test platform::tests::test_load_average ... ok
test platform::tests::test_mount_at ... FAILED
test platform::tests::test_networks ... ok
test platform::tests::test_on_ac_power ... FAILED
test platform::tests::test_mounts ... FAILED
test platform::tests::test_cpu_load ... ok
test platform::tests::test_cpu_load_aggregate ... ok

failures:

---- platform::tests::test_mount_at stdout ----
thread 'platform::tests::test_mount_at' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: StringError("statfs() failed") }', src/libcore/result.rs:999:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

---- platform::tests::test_on_ac_power stdout ----
thread 'platform::tests::test_on_ac_power' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: StringError("sysctl() failed") }', src/libcore/result.rs:999:5

---- platform::tests::test_mounts stdout ----
thread 'platform::tests::test_mounts' panicked at 'attempt to subtract with overflow', src/platform/freebsd.rs:220:20


failures:
    platform::tests::test_mount_at
    platform::tests::test_mounts
    platform::tests::test_on_ac_power

test result: FAILED. 7 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--lib'

(I encountered this problem when I tried to run https://github.com/rabite0/hunter).

Cpu temp issue

I really like your library!! I noticed there is an issue with cpu_temp()

let sys = System::new(); let temp = sys.cpu_temp().unwrap(); println!("{:?}", temp);

Returns

Err(Custom { kind: Other, error: StringError("Could not parse float") })

inconsistent readings vs other polling tools...

Hey there,

When putting the example code into a loop I only get 0% usage reporting.

The Idle and temp values seem to reflect what a cat /proc/stat and glances readout are giving me...

Any ideas?
image

Adding a video as probably it's more illustrative:
https://imgur.com/a/ybisqaa

(Manjaro Linux 64bit / Linux 5.4.34-1-MANJARO)

Consider switching from Unlicense to MIT to allow code reuse from other crates

It is generous that you have decided to dedicate systemstat to the public domain, but unfortunately, there is a flip side to this also: Even permissively licensed code, which constitutes the vast majority of all crates available today, cannot be reused in systemstat.

This prevents code from the MIT-licensed sysinfo crate from being used to improve systemstat. Most notably, sysinfo has full macOS support while systemstat has basically none at this point, and Windows support seems to be a lot better as well. I have studied both crates and prefer systemstat's design overall, but of course there are a few things that sysinfo does better and that could be shared.

My request is therefore that you consider changing this repository's license to one that allows inclusion of MIT-licensed code. I realize that since there are currently no license restrictions at all, I could do this myself in a fork, but I would prefer not to have to fork just for that. Also, I use neither macOS nor Windows myself, so I can't make the relevant changes anyway.

/ref p-e-w/hegemon#3

Invoking networks() results in STATUS_ACCESS_VIOLATION

fn main() {
   let sys_stat = systemstat::System::new();
   do_something(&sys_stat);
}

fn do_something(sys_stat: &systemstat::System) {
    let net = sys_stat.networks(); // crash (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
}

platform: windows 11
version: 0.1.10

CPU load output isn't showing actual load

My 4 CPU cores are in 100% load but the cpu_load_aggregate output rarely goes to 10% of usage. Most of the times all of them are 0.

Following code is called every 250ms:

let sys = System::new();
match sys.cpu_load_aggregate() {
  Ok(cpu) => {
    let cpu = cpu.done().unwrap();
    Some(
      SystemStat {
        user: cpu.user * 100.0,
        nice: cpu.nice * 100.0,
        system: cpu.system * 100.0,
        interrupt: cpu.interrupt * 100.0,
        idle: cpu.idle * 100.0,
      }
      .into(),
    )
  }
  Err(x) => {
    println!("\nCPU load: error: {}", x);
    None
  }
}

Request for proper name/model of CPU

I have a project I'm working on that I think I'm about to incorporate your crate for. The goal is to get the name and clock rate of the CPU and GPU, the amount of RAM and its clock rate, and the total storage size of attached SSDs and HDDs, and to display them on the screen in a screensaver kind of fashion. I'm having a hard time finding a way to do this. It looks like your crate will work great for the RAM and other useful info, but right now I'm resorting to using command line output from wmic on windows to get the proper name of the processor and it feels hacky. It works, but I want it to compile and run on any system, not just windows. It tells me I have an Intel Core i5, etc., which is true, but there has to be a way to get that same string without resorting to the command line.

In summary... PLEASE! PLEASE PLEASE PLEASE!
I'm sorry, I lost it there for a minute.

Do not use this library if at all possible

Tried using latest stable build. It managed to crash my PC while compiling. Even if you want to assume it wasn't this library's fault, the library cannot compile in its current state.

Compile error on windows msvc 64-bit

Hello,

In trying to compile my code, I'm getting the following:

Compiling systemstat v0.1.2
error[E0432]: unresolved import `self::platform::PlatformImpl`
  --> C:\Users\#####\.cargo\registry\src\github.com-1ecc6299db9ec823\systemstat-0.1.2\src\lib.rs:14:9
   |
14 | pub use self::platform::PlatformImpl as System;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `PlatformImpl` in `platform`. Did you mean to use `Platform`?

error[E0412]: cannot find type `PlatformMemory` in this scope
  --> C:\Users\#####\.cargo\registry\src\github.com-1ecc6299db9ec823\systemstat-0.1.2\src\data.rs:92:26
   |
92 |     pub platform_memory: PlatformMemory,
   |                          ^^^^^^^^^^^^^^ not found in this scope

error: aborting due to previous error(s)

error: Could not compile `systemstat`.

I'm using the stable windows toolchain with MSVC, although the error also happens if I switch to the gnu toolset.

Any ideas on what could be causing this?

Compile error if systemstat is included as a dep in a 2018 edition project

I'm using systemstat as a library for one my project. The project uses rust 2018 edition. While systemstat as a standalone crate compiles properly, when included as a dep it fails to compile with a bunch of errors like:

error[E0597]: `data` does not live long enough
   --> /home/nick/Nextcloud/src/systemstat/src/platform/linux.rs:109:29
    |
109 |         proc_stat_cpu_times(data.as_bytes())
    |                             ^^^^ borrowed value does not live long enough
...
112 |     })
    |     - borrowed value only lives until here
    |
    = note: borrowed value must be valid for the static lifetime...

Might be related to new borrow checking algos in rust 2018.

I have a patch to fix this, can submit it as a pull request later today.

calls to mounts() yielding unpredictable results

Although the first call to mounts() returns all the system's mounts, repeated calls return only a subset and rather unpredictably.

I've traced this down to here:

fn stat_mount(mount: ProcMountsData) -> io::Result<Filesystem> {
    let mut info: statvfs = unsafe { std::mem::zeroed() };
    let result = unsafe { statvfs(mount.target.as_ptr() as *const c_char, &mut info) };
//                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    match result {
        0 => Ok(Filesystem {

I think the indicated part needs to be a null terminated string, and isn't. So this works for a while until memory begins to get reused and is not initialized with zeros.

This fixes it:

fn stat_mount(mount: ProcMountsData) -> io::Result<Filesystem> {
    let mut info: statvfs = unsafe { std::mem::zeroed() };
    let target = format!("{}\0", mount.target); // null terminated string
    let result = unsafe { statvfs(target.as_ptr() as *const c_char, &mut info) };
    match result {
        0 => Ok(Filesystem {

Compile error for version 0.1.2

Hello! I'm trying to use your crate for retrieving system uptime and received the following errors when trying to compile version 0.1.2 upon running cargo build:

   Compiling systemstat v0.1.2
error[E0432]: unresolved import `self::platform::PlatformImpl`
  --> /Users/natalie/.cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.2/src/lib.rs:14:9
   |
14 | pub use self::platform::PlatformImpl as System;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `PlatformImpl` in `platform`. Did you mean to use `Platform`?

error[E0412]: cannot find type `PlatformMemory` in this scope
  --> /Users/natalie/.cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.2/src/data.rs:92:26
   |
92 |     pub platform_memory: PlatformMemory,
   |                          ^^^^^^^^^^^^^^ not found in this scope

error: aborting due to 2 previous errors

error: Could not compile `systemstat`.

If the problem is as simple as switching out Platform for PlatformImpl, I'd be happy to submit a patch!

wrong number of CPUs from cpu_load() on Linux

It's only returning 3 for me on a 4-core system.

Here's the contents of my /proc/stat:

cpu  301439 3431 227659 131840429 103226 131240 368724 0 0 0
cpu0 79479 749 60245 32813939 49566 48200 184931 0 0 0
cpu1 76930 862 57391 32892308 19437 40731 153489 0 0 0
cpu2 71106 889 55988 33042231 19820 27443 24650 0 0 0
cpu3 73923 930 54032 33091950 14401 14865 5653 0 0 0
intr 129549542 7 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 421200 0 0 0 0 0 0 0 0 0 0 0 23844 0 0 0 0 0 0 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1739270 6936 36 0 0 0 0 35227285 39050363 198 362 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ctxt 102400080
btime 1612511454
processes 31382
procs_running 1
procs_blocked 0
softirq 130779335 6933 13070143 953419 91889261 1493492 0 730179 17947091 1372 4687445

and the return value from cpu_load() after waiting and calling .done():

Ok(
    [
        CPULoad {
            user: 0.02,
            nice: 0.0,
            system: 0.01,
            interrupt: 0.0,
            idle: 0.97,
            platform: PlatformCpuLoad {
                iowait: 0.0,
            },
        },
        CPULoad {
            user: 0.02970297,
            nice: 0.0,
            system: 0.01980198,
            interrupt: 0.0,
            idle: 0.95049506,
            platform: PlatformCpuLoad {
                iowait: 0.0,
            },
        },
        CPULoad {
            user: 0.01,
            nice: 0.0,
            system: 0.01,
            interrupt: 0.01,
            idle: 0.97,
            platform: PlatformCpuLoad {
                iowait: 0.0,
            },
        },
    ],
)

Rename other field for CPU statistics

I noticed that the other field on CpuTime is only used in the linux implementation to provide iowait statistics.

Is there any reason to keep it this way, or might I propose changing it to iowait?. It looks like it might also be possible to have OS specific struct fields using the cfg macro, which could also be an option.

What's your take on this? Again, happy to do the work.

All the best,
Richard

Demo Segfault

I tried playing around with your library and was surprised to see one of the few segfaults i've seen in rust and running your demo file too.

     Running `target/debug/bin`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr:          Custom(Custom { kind: Other, error: StringError("Not supported") }) }',     ../src/libcore/result.rs:785
stack backtrace:
   1:     0x55a355aeafef - std::sys::backtrace::tracing::imp::write::h6528da8103c51ab9
   2:     0x55a355aed3eb -     std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hbe741a5cc3c49508
   3:     0x55a355aed06f - std::panicking::default_hook::he0146e6a74621cb4
   4:     0x55a355ae4f3e - std::panicking::rust_panic_with_hook::h983af77c1a2e581b
   5:     0x55a355aed631 - std::panicking::begin_panic::he426e15a3766089a
   6:     0x55a355ae58aa - std::panicking::begin_panic_fmt::hdddb415186c241e7
   7:     0x55a355aed5ce - rust_begin_unwind
   8:     0x55a355b22aaf - core::panicking::panic_fmt::hf4e16cb7f0d41a25
   9:     0x55a355ad9f1b - core::result::unwrap_failed::hf40cb93f6f31ec3d
                        at ../src/libcore/macros.rs:29
  10:     0x55a355ad9551 - _<core..result..Result<T, E>>::unwrap::ha10f31560a1ef478
                        at ../src/libcore/result.rs:723
  11:     0x55a355ad81ba - bin::main::h526525808e6ff144
                         at src/main.rs:10
  12:     0x55a355aecca8 - std::panicking::try::call::h852b0d5f2eec25e4
  13:     0x55a355af6cbb - __rust_try
  14:     0x55a355af6c5e - __rust_maybe_catch_panic
  15:     0x55a355aec74e - std::rt::lang_start::hfe4efe1fc39e4a30
  16:     0x55a355ae1cf9 - main
  17:     0x7f9fa817d740 - __libc_start_main
  18:     0x55a355ad7ce8 - _start
  19:                0x0 - <unknown>
error: Process didn't exit successfully: `target/debug/bin` (exit code: 101)

Since I rarely run into segfaults im unsure of how to continue, do you have any ideas as to what could be causeing this?

Incorrect filesystem data on Raspbian

I have used this library to write a simple diskspace utility to display available (and optionally, total) disk space. The utility works fine on Debian (and with #53, on macOS), but reports what seem to be wildly incorrect results on Raspbian. I have tested this with the following script:

diskspace --bytes; py -c 'import shutil; print(shutil.disk_usage("/").free)'

On my Debian server, this produced:

20506071040
20506071040

And on my MacBook:

55125647360
55125647360

On my Raspberry Pi however:

1290358784
9880293376

The df utility agrees with the Python script.

Swap support

In addition to memory()-usage also report swap usage. I would be willing to implement this myself.

Would you prefer this as a separate swap() function or as a part of memory()? Some platform-APIs will return memory and swap information together.

error: linker `cc` not found

hello, when I build this crate or cargo run example I will get that error

➜  systemstat git:(master) cargo build --release
   Compiling autocfg v1.0.1
   Compiling bitflags v1.2.1
   Compiling radium v0.5.3
   Compiling ryu v1.0.5
   Compiling libc v0.2.82
   Compiling version_check v0.9.2
   Compiling lexical-core v0.7.4
   Compiling memchr v2.3.4
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `lexical-core`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: build failed
➜  systemstat git:(master) uname -a
Linux ubuntu 5.8.0-40-generic #45~20.04.1-Ubuntu SMP Fri Jan 15 11:35:04 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

macOS purgeable space

macOS has a concept of purgeable space. It can be treated like free space for most purposes, because the OS deletes from it if space gets too low. As such, it would make sense to either include it in Filesystem.avail or add it as a separate API.

Compiler Warnings on Latest Stable

Attempting to use this library yields many compiler warnings. Here is what I get when i try to compile this on Windows 10 with the latest stable:

warning: unused `#[macro_use]` import
  --> src\lib.rs:10:1
   |
10 | #[macro_use]
   | ^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
   --> src\platform\windows\disk.rs:133:46
    |
133 |     let mut avail: ULARGE_INTEGER = unsafe { mem::uninitialized() };
    |                                              ^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
   --> src\platform\windows\disk.rs:134:46
    |
134 |     let mut total: ULARGE_INTEGER = unsafe { mem::uninitialized() };
    |                                              ^^^^^^^^^^^^^^^^^^

warning: use of deprecated item 'std::mem::uninitialized': use `mem::MaybeUninit` instead
   --> src\platform\windows\disk.rs:135:45
    |
135 |     let mut free: ULARGE_INTEGER = unsafe { mem::uninitialized() };
    |                                             ^^^^^^^^^^^^^^^^^^

warning: use of deprecated item 'libc::uint8_t': Use u8 instead.
 --> src\platform\windows\network_interfaces.rs:1:42
  |
1 | use libc::{c_void, free, malloc, size_t, uint8_t};
  |                                          ^^^^^^^

warning: use of deprecated item 'libc::uint8_t': Use u8 instead.
  --> src\platform\windows\network_interfaces.rs:59:28
   |
59 |     on_link_prefix_length: uint8_t,
   |                            ^^^^^^^

warning: use of deprecated item 'libc::uint8_t': Use u8 instead.
   --> src\platform\windows\network_interfaces.rs:199:60
    |
199 | fn parse_addr_and_netmask(aptr: *const SOCKADDR, net_bits: uint8_t) -> NetworkAddrs {
    |                                                            ^^^^^^^

warning: unused variable: `path`
   --> src\platform\windows\mod.rs:295:46
    |
295 |     fn mount_at<P: AsRef<path::Path>>(&self, path: P) -> io::Result<Filesystem> {
    |                                              ^^^^ help: consider prefixing with an underscore: `_path`
    |
    = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `interface`
   --> src\platform\windows\mod.rs:307:29
    |
307 |     fn network_stats(&self, interface: &str) -> io::Result<NetworkStats> {
    |                             ^^^^^^^^^ help: consider prefixing with an underscore: `_interface`

warning: unused variable: `rhs`
  --> src\data.rs:58:26
   |
58 |     pub fn avg_add(self, rhs: &Self) -> Self {
   |                          ^^^ help: consider prefixing with an underscore: `_rhs`

warning: unused variable: `input`
  --> src\data.rs:86:17
   |
86 |     pub fn from(input: f32) -> Self {
   |                 ^^^^^ help: consider prefixing with an underscore: `_input`

warning: function is never used: `physical_address_to_string`
   --> src\platform\windows\network_interfaces.rs:186:4
    |
186 | fn physical_address_to_string(array: &[u8; 8], length: DWORD) -> String {
    |    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

    Finished dev [unoptimized + debuginfo] target(s) in 5.61s

I think the worst thing here is the use of std::mem::uninitialized. Regardless, all the warnings should probably be fixed at some point.

Move away from serde-feature-hack

serde-feature-hack has been marked as deprecated by it's maintainer, with a "workaround" provided by Cargo itself, since version 1.31. So unless you want to actually support MSRV lower than 1.31, I would consider to moving to depending directly on serde itself.

Parsing error for socket statistic

I am calling socket stat exactly like in examples

match sys.socket_stats() {
    Ok(stats) => trace!("\nSystem socket statistics: {:?}", stats),
    Err(x) => error!("\nSystem socket statistics: error: {}", x.to_string()),
}

It is runnning on ARM ( raspberry pi 4 ) and it worked correctly, but suddenly it gives this Parsing Error

Parsing Error: Error { input: "\nTCP: inuse 7 orphan 0 tw 5 alloc 12 mem 0\nUDP: inuse 3 mem 3\nUDPLITE: inuse 0\nRAW: inuse 0\nFRAG: inuse 0 memory 0\n", code: Tag }

Using this version:

[[package]]
name = "systemstat"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1f726379f0c746ad672b7e932bd390b5faae073f502e37d314950ced761ac3e"

Test with winapi-rs from git

Winapi 0.3 is about to be released and the maintainer is looking for people to test against it as it's a large refactoring. Since I saw you were using 0.2 I'd recommend you test against the git winapi-rs version now or even better switch to the git dependency so that any issues you run into can be resolved.

Missing cast prevents compilation under 32-bit MacOS and 32-bit FreeBSD

While implementing a CI solution for the hunter file manager, I've come across a bug in systemstat that prevents it from compiling under 32-bit BSD and 32-bit MacOS systems.

chrono::NaiveDateTime::from_timestamp() expects its secs parameter to always be an i64. However, in /src/platform/macos.rs:Platform:boot_time() and /src/platform/freebsd.rs:Platform:boot_time(), the tv_sec field of the libc::timeval struct is passed without casting it to an i64.

We're using the cross crate by the Rust Embedded Devices Working Group to build binaries for foreign architectures.

Here is the build log for 32-bit MacOS:

$ cross build --target i686-apple-darwin --release
info: downloading component 'rust-std' for 'i686-apple-darwin'
info: installing component 'rust-std' for 'i686-apple-darwin'
 51.5 MiB /  51.5 MiB (100 %)  12.4 MiB/s ETA:   0 s
   Compiling systemstat v0.1.4
error[E0308]: mismatched types
  --> /Users/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.4/src/platform/macos.rs:65:68
   |
65 |         Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec, data.tv_usec as u32), Utc))
   |                                                                    ^^^^^^^^^^^ expected i64, found i32
help: you can cast an `i32` to `i64`, which will sign-extend the source value
   |
65 |         Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec.into(), data.tv_usec as u32), Utc))
   |                                                                    ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

Here is the build log for 32-bit FreeBSD:

$ cross build --target i686-unknown-freebsd --release
info: downloading component 'rust-std' for 'i686-unknown-freebsd'
info: installing component 'rust-std' for 'i686-unknown-freebsd'
 62.9 MiB /  62.9 MiB (100 %)  13.9 MiB/s ETA:   0 s
Unable to find image 'japaric/i686-unknown-freebsd:v0.1.14' locally
v0.1.14: Pulling from japaric/i686-unknown-freebsd
Status: Downloaded newer image for japaric/i686-unknown-freebsd:v0.1.14
   Compiling systemstat v0.1.4
error[E0308]: mismatched types
   --> /cargo/registry/src/github.com-1ecc6299db9ec823/systemstat-0.1.4/src/platform/freebsd.rs:109:68
    |
109 |         Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec, data.tv_usec as u32), Utc))
    |                                                                    ^^^^^^^^^^^ expected i64, found i32
help: you can cast an `i32` to `i64`, which will sign-extend the source value
    |
109 |         Ok(DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(data.tv_sec.into(), data.tv_usec as u32), Utc))
    |                                                                    ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

cpu_load doesn't supports Windows

When this is called, the function only returns with an error saying it's not supported.
But I believe there's actually some way to get the idel time, system time, user time, etc with performance counter or PDH APIs.

And I think here's the example that may be useful.

http://dostf.blogspot.com/2012/02/measuure-cpu-usage-on-windows-with-pdh.html

At least windows can provide:
"Processor({index})\% {type} Time" performance counter, and this should be exactly similar to the definitions of the value in the CpuLoad.

image

Inconsistent implementation of Filesystem::files for FreeBSD and Linux

FreeBSD is implemented like this:

Filesystem {
    files: self.f_files as usize - self.f_ffree as usize,
    /* ... */
}

Linux is implemented like this:

Filesystem {
    files: info.f_files as usize,
    /* ... */
}

So the same field, Filesystem::files, actually has different meanings in each platform. I assume Linux is wrong here because it isn't actually very useful to have only the capacity. I plan to submit a PR for this

Why reexport std types?

data.rs:

pub use std::time::Duration;
pub use std::net::{Ipv4Addr, Ipv6Addr};
pub use std::collections::BTreeMap;

cargo build doesn't work

Hi Team,
I am new to Rust. I just cloned the repo and did a cargo build, it fails and gives the following message on console:
`_error[E0432]: unresolved import self::platform::PlatformImpl
--> src/lib.rs:14:9
|
14 | pub use self::platform::PlatformImpl as System;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no PlatformImpl in platform. Did you mean to use Platform?

error[E0412]: cannot find type PlatformMemory in this scope
--> src/data.rs:92:26
|
92 | pub platform_memory: PlatformMemory,
| ^^^^^^^^^^^^^^ not found in this scope

error: aborting due to previous error(s)

error: Could not compile systemstat._`

Could you please look into this?

android support

should be a matter of just enabling the linux implementation for android?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.