A lib crate for gathering system info such as cpu, distro, environment, kernel, etc in Rust.

Overview

nixinfo

A lib crate for gathering system info such as cpu, distro, environment, kernel, etc in Rust.

To use: nixinfo = "0.2.8" in your Cargo.toml.

Currently supported

  • CPU model and temperature (Celsius)
    • nixinfo::cpu() -> Result
    • nixinfo::temp() -> Result
  • Device name
    • nixinfo::device() -> Result
  • Distro name
    • nixinfo::distro() -> Result
  • Environment (e.g. DE or WM)
    • nixinfo::environment() -> Result
  • env variables
    • nixinfo::env("VARIABLE") -> Option
  • GPU info (requires lspci and grep to be installed for now until I find a pure rust solution)
    • nixinfo::gpu() -> Result
  • Hostname
    • nixinfo::hostname() -> Result
  • Kernel
    • nixinfo::kernel() -> Result
  • Total memory in MBs
    • nixinfo::memory() -> Result
  • Music info (only mpd is supported, requires music feature to be enabled)
    • nixinfo::music() -> String
  • Package counts (managers supported are apk, apt, dnf, dpkg, eopkg, pacman, pip, portage, rpm, and xbps)
    • nixinfo::packages("manager") -> Result
  • Terminal being used (unless tmux is used, in which case N/A will be outputted because reasons)
    • nixnfo::terminal() -> Result
  • Uptime of device
    • nixinfo::uptime() -> Result

TODO

  • Obtain used memory in addition to total memory
  • Support *BSD
Comments
  • Add an error type

    Add an error type

    This doesn't do much for now, but it paves the way towards avoiding a lot of the unwraps that are now present in the code.

    And by the way, hello again!

    opened by lnicola 4
  • Faster count and apt package retriving method

    Faster count and apt package retriving method

    I noticed that retrieving total package count was slowing down the output and was quite jarring. So I have proposed a new package retrieval method as well as new counting method that is quicker

    | Method | Time to complete execution | |------------------------------ |-------------------------------------------------------- | | stock | real 0.38s user 0.32s sys 0.06s cpu 100% | | dpkg w/ stock count | real 0.36s user 0.31s sys 0.06s cpu 99% | | stock w/ new counting method | real 0.37s user 0.33s sys 0.04s cpu 99% | | dpkg w/ new counting method | real 0.08s user 0.04s sys 0.04s cpu 97% |

    These are the numbers I got during my test, I have not tried this on other systems other than a laptop and a pc

    opened by Dam-0 2
  • add android support

    add android support

    This PR updates the info fields; cpu, device, distro, hostname, and user to be better supported on Android.

    Example output from rsfetch on my Moto E4 phone:

    $ ./target/debug/rsfetch -cDdhkmsuUC 0:

    0─────────────────────────────────────────────────────0
    │ CPU      │ ARMv7 Processor rev 4 (v7l)              │
    │ Device   │ Moto E4 XT1765 (perry)                   │
    │ Distro   │ Android 7.1.2 (aokp_perry-userdebug)     │
    │ Hostname │ localhost                                │
    │ Kernel   │ 3.18.63-NPL26.118-20-g9365253            │
    │ Memory   │ 1868 MB                                  │
    │ Shell    │ /data/data/com.termux/files/usr/bin/bash │
    │ Uptime   │ 14h 50m                                  │
    │ User     │ u0_a73                                   │
    0─────────────────────────────────────────────────────0
    
    opened by Phate6660 0
  • Logical error in meminfo possible

    Logical error in meminfo possible

    Hi,

    You assume in your implementation of memory() that "MemTotal" is always in the first line. If this is not the case, then a wrong value will be returned, which is however assumed as "correct" (here no error handling takes place, it is a "logical error"). I think the memory() function should be implemented in another way. I've written two example implementations, you can use one of them, if you want:

    use std::io;
    use std::fs;
    
    /// Obtain total memory in a human readable size, outputs to a Result<String>
    pub fn memory() -> io::Result<String> {
    	let meminfo = fs::read_to_string(MEMINFO)?;
    	for line in meminfo.lines() {
    		if line.starts_with(MEMTOTAL) {
    			let mut rsplit = line.rsplit(SEPARATOR_COLON);
    			let size = match rsplit.next() {
    				Some(x) => x.replace(UNIT[0], EMPTY_STRING).trim().parse::<u64>().to_io_result()?,
    				None => return Err(io::Error::new(io::ErrorKind::Other, ERROR_02))
    			};
    			let mut current_multiplier = 1.0;
    			while (size as f64) >= DIVISOR_F64.powf(current_multiplier) {
    				current_multiplier += 1.0;
    			}
    			let mut memory = String::new();
    			memory.push_str(&(format!("{:.2}", (size as f64) / 
    				DIVISOR_F64.powf(current_multiplier - 1.0))).to_string());
    			memory.push_str(&(UNIT[(current_multiplier - 1.0) as usize].to_string()));
    			return Ok(memory)
    		}
    	}
    	Err(io::Error::new(io::ErrorKind::Other, ERROR_01))
    }
    
    /// Obtain total memory in MB, outputs to a Result<String>
    pub fn memory_mb() -> io::Result<String> {
    	let meminfo = fs::read_to_string(MEMINFO)?;
    	for line in meminfo.lines() {
    		if line.starts_with(MEMTOTAL) {
    			let mut rsplit = line.rsplit(SEPARATOR_COLON);
    			let size = match rsplit.next() {
    				Some(x) => x.replace(UNIT[0], EMPTY_STRING).trim().parse::<u64>().to_io_result()?,
    				None => return Err(io::Error::new(io::ErrorKind::Other, ERROR_02))
    			};
    			return Ok(format!("{} {}", (size / DIVISOR_U64), UNIT_MB))
    		}
    	}
    	Err(io::Error::new(io::ErrorKind::Other, ERROR_01))
    }
    
    pub trait ToIOResult<T> {
    	fn to_io_result(self) -> io::Result<T>;
    }
    
    impl<T, E: ToString> ToIOResult<T> for Result<T, E> {
    	fn to_io_result(self) -> io::Result<T> {
    		match self {
    			Ok(x) => Ok(x),
    			Err(err) => Err(io::Error::new(io::ErrorKind::Other, err.to_string())),
    		}
    	}
    }
    
    const MEMTOTAL: &str = "MemTotal";
    const MEMINFO: &str = "/proc/meminfo";
    const ERROR_01: &str = "no MemTotal line found in /proc/meminfo!";
    const ERROR_02: &str = "No memoryinfo in MemTotal line!";
    const UNIT: [&str; 5] = ["kB", "MB", "GB", "TB", "PB"];
    const DIVISOR_F64: f64 = 1024.0;
    const SEPARATOR_COLON: &str = ":";
    const EMPTY_STRING: &str = "";
    
    const DIVISOR_U64: u64 = 1024;
    const UNIT_MB: &str = "MB";
    
    fn main() {
        println!("{:?}", memory());
        println!("{:?}", memory_mb());
    }
    
    opened by ph0llux 0
  • [Feature] Windows Support

    [Feature] Windows Support

    Similar to MacOS Support #5, it would be nice if Windows was a supported target, It may be possible to reference winfetch for some inspiration.

    This should probably include Win-Get and Chocolatey package counts.

    opened by tracker1 2
  • It's not working on mac

    It's not working on mac

    this is the code:

    use nixinfo;
    
    fn main() {
        let cpu = nixinfo::hostname();
        println!("cpu: {:?}", cpu);
    }
    

    and this is the error. If I'm wrong somewhere let me know

    cpu: Err(Os { code: 2, kind: NotFound, message: "No such file or directory" })

    opened by MehdiOrang 6
  • [Idea] Get GPU information using pure Rust

    [Idea] Get GPU information using pure Rust

    First of all, I love the initiative of the project. I started to learn Rust a few weeks ago and as my first project I set out to build a neofetch style tool, without realizing the existence of rsfetch, so I'd like to contribute here in what I can.

    I saw that external commands are used to obtain information from the GPU, so I started to investigate how else could be done without depending on grep and lspci.

    I found in the pciutils repository the following:

    In runs on the following systems:

    Linux (via /sys/bus/pci, /proc/bus/pci or i386 ports) FreeBSD (via /dev/pci) NetBSD (via libpci) OpenBSD (via /dev/pci) GNU/kFreeBSD (via /dev/pci) Solaris/i386 (direct port access) Aix (via /dev/pci and odmget) GNU Hurd (direct port access) Windows (direct port access, see README.Windows for caveats) CYGWIN (direct port access) BeOS (via syscalls) Haiku (via /dev/misc/poke) Darwin (via IOKit) DOS/DJGPP (via i386 ports) SylixOS (via /proc/pci)

    There are many possible places to search, depending on the kernel (or operating system). But in some cases it's a matter of reading a plain text file. In order not to make the issue too long, I recommend the first part of this article. As you can see in the article, it is possible to read the vendor identifier, device identifier and class identifier.

    I quote again the previous repository, the following:

    The database of PCI IDs (the pci.ids file) gets out of date much faster than I release new versions of this package, so it is maintained separately.

    It lives at https://pci-ids.ucw.cz/, where you can browse the database, download the most recent pci.ids file (e.g., by running the update-ids utility) and also submit new entries.

    If we go through that website, we can corroborate that the GPU information (in addition to other devices that are not relevant) can be obtained from these ID's.

    At first I thought that the pci.ids file should be downloaded regularly to keep it updated but, at least in Arch Linux, I found it in /usr/share/hwdata/pci.ids.

    I'm not sure this is the best way to solve it, but I think it can work, without relying on system commands or external crates.

    opened by PandaFoss 3
Owner
ValleyKnight
ValleyKnight
A TUI system monitor written in Rust

NO LONGER MAINTAINED. For a similar program, check out https://github.com/ClementTsang/bottom. ytop Another TUI based system monitor, this time in Rus

Caleb Bassi 2.1k Jan 3, 2023
A system handler to get information and interact with processes written in Rust

A system handler to get information and interact with processes written in Rust

Guillaume Gomez 1.1k Jan 3, 2023
A simple rust-based tool for fetching system information

?? azf a simple rust-based tool for fetching system information you need a patched nerd font and the material design icons font ?? compiling you can c

Pedro Henrique 3 Dec 17, 2022
Basic system information fetcher, with a focus on performance.

Table of Contents: About Changelog Dependencies Benchmarks Features Installation Platform Support About Macchina Macchina lets you view basic system i

null 677 Dec 28, 2022
System Tools with real-time Web UI

HeroicToys The remake of useful CLI tools, but with Web UI. The project uses RillRate - Dynamic UI for bots, microservices, and IoT.

RillRate 27 Nov 10, 2022
System Tools with real-time Web UI

MultiTool System Tools with real-time Web UI. The project uses RillRate - Dynamic UI for bots, microservices, and IoT. Included Implemented: System Mo

RillRate 27 Nov 10, 2022
Cap'n Proto is a type system for distributed systems

Cap'n Proto for Rust documentation blog Introduction Cap'n Proto is a type system for distributed systems. With Cap'n Proto, you describe your data an

Cap'n Proto 1.5k Jan 1, 2023
A crate implementing POSIX/GNU-style --flags.

pflag is a port of the spf13's popular fork of the Go package by the same name.

null 11 Jul 21, 2022
A theming crate for fltk-rs

fltk-theme A theming crate for fltk-rs, based on work by Remy Oukaour and Greg Ercolano, and schemes developed by the NTK GUI library. Usage [dependen

null 53 Dec 27, 2022
minimalistic command launcher in rust

rrun Note: Apart from the occasional fix, this project is not actively developed anymore. rrun works fine and should run/compile for the time being on

null 105 Nov 18, 2022
Yet another fancy watcher. (Rust)

funzzy Yet another fancy watcher. (Inspired by antr / entr) Configure execution of different commands using semantic yaml. # .watch.yaml # list here a

Cristian Oliveira 188 Dec 12, 2022
A modern replacement for ps written in Rust

procs procs is a replacement for ps written in Rust. Documentation quick links Features Platform Installation Usage Configuration Features Output by t

null 3.6k Jan 5, 2023
A more intuitive version of du in rust

Dust du + rust = dust. Like du but more intuitive. Why Because I want an easy way to see where my disk is being used. Demo Install Cargo cargo install

andy.boot 5.5k Jan 8, 2023
Blazing 💥 fast terminal-ui for git written in rust 🦀

Blazing fast terminal client for git written in Rust Features Fast and intuitive keyboard only control Context based help (no need to memorize tons of

Stephan Dilly 11.8k Jan 5, 2023
A simple and fast download accelerator, written in Rust

zou A simple and fast download accelerator, written in Rust Zou is a Snatch fork by @k0pernicus. Snatch is a fast and interruptable download accelerat

Antonin Carette 173 Dec 4, 2022
Fuzzy Finder in rust!

Life is short, skim! Half of our life is spent on navigation: files, lines, commands… You need skim! It is a general fuzzy finder that saves you time.

Jinzhou Zhang 3.7k Jan 4, 2023
A bash-like Unix shell written in Rust

Cicada Unix Shell Cicada is a simple Unix shell written in Rust. Documents Install cicada Environment Variables Cicada Builtins Completion RC File His

Hugo Wang 921 Dec 28, 2022
Performs distributed command execution, written in Rust w/ Tokio

Concurr: Distributed and Concurrent Command Execution, in Rust This project is dual licensed under MIT and Apache 2.0. Originally inspired by the GNU

Michael Murphy 93 Dec 18, 2022
A library to listen to global hotkeys in Rust

Rust Hotkey A library to listen to global hotkeys in Rust How to use See the examples folder for how to use this library. OS Support This lib aims to

James Birtles 44 Dec 12, 2022