Git Product home page Git Product logo

system-mqtt's Introduction

System MQTT

Inspired by system-bridge, System MQTT is essentially the same thing but for a different audience.

System MQTT takes several statistics from the computer it is running on and then reports them to an MQTT broker. With that it also transmits the necessary discovery messages to that broker for Home Assistant to be made aware of the device.

At this point in time the following information is reported:

  • CPU usage
  • Memory usage
  • Swap usage
  • Filesystem usage
  • Battery state
  • Battery level

The advantage of system-mqtt is that it's light weight in comparison to system-bridge. Weighing in at under a Megabyte and a CPU usage so small I can't get it to show up under htop, system-mqtt is light enough to run on your Pi.

The downside of system-mqtt is that its meant more for power users. There's no system tray icon, no web interface, or really any UI at all. All of the configuration is done using a config folder under /etc/system-mqtt.yaml. It's easy enough to work with but not certainly not as pretty as system-bridge.

Supported platforms

My main goal was for this to run on Linux, specifically Debian based distros since that's what I primarily use. In theory a port to Windows should require very minimal effort. Feel free to make a pull request if you wish to add such functionality. If you want some other package format like RPM, again, feel free to make a pull request and add such functionality.

Adding more statistics

Want more statistics to be reported? I'm fine with that. Just make a pull request. My main requirements be that you run cargo fmt, avoid use of unsafe, keep the memory usage at runtime under a Megabyte, and keep the CPU usage unnoticed.

If for some reason your feature just can't be fit within those requirement, make the pull request anyway and we'll talk about it. I'm sure we can find a compromise.

Dependencies

  • Building system-mqtt requires the Rust toolchain including the cargo package manager. Default repositories may be out of date and fail to build, so it is recommended to install Rust using the installer at Rustup. Remove any existing instances of rustc on your system, and install a fresh copy of Rust using the instructions on Rustup.rs.
  • The Cargo helper command cargo-deb is required to allow cargo to build a .deb package. Once Rust is installed, add cargo-deb with the command cargo install cargo-deb.
  • libdbus-1-dev is required, but not installed by default on many Debian systems. sudo apt install libdbus-1-dev will install from the Debian or Ubuntu repositories.
  • libdbus-1-3 or similar is required, but is installed by default on most Debian and Ubuntu systems.

Installation

I brewed this up in less than a day and have less than an hour of runtime with it, so I don't feel ready to publish proper releases or a fancy pre-packaged installer. This means you'll be installing it from source.

Step 1: Setup MQTT with Home Assistant.

Step 2: Clone this repository.

Step 3: Verify all dependencies are installed.

Step 4: Run the command cargo deb --install from the cloned directory.

At this point you've installed system-mqtt as a debian package that can easily be removed. It will automatically be registered with systemd, but may require a manual start with systemctl start system-mqtt.

At this point the daemon is installed, but won't run if the mqtt broker is not running on the local system. You'll need to edit the configuration to let it know about the mqtt broker and its credentials.

Configuration

The configuration file lives at /etc/system-mqtt.yaml.

If it does not appear when you first install system-mqtt, it will be created and populated when system-mqtt is run with default arguments.

Here is the default config with comments added explaining the configuration options:

# The URL to the mqtt broker.
mqtt_server: "mqtt://localhost"

# If no authentication is needed to log into the mqtt broker, leave this be.
# If authentication is needed, set this to the user name. The password will
# be fetched from the OS keyring.
# To set that password, run `system-mqtt set-password` and an interactive
# prompt will ask you for the login password.
username: ~

# If unspecified, this will default to `keyring`, where it uses the system keyring for your password.
password_source: keyring

# Alternatively, you can use a "secret file" for your password. It's an unencrypted plaintext file with the password. You must set the file to be owned by the user running system-mqtt (typically root) and set the permissions so that only the user can access the file.
# This is derived from the security policies used by ssh and OpenPGP. It's a little less ideal than keyring so you should prefer keyring if you can use it.
# Here's an example of how you'd point to where that file is located:
# password_source: !secret_file /path/to/file

# The amount of time to wait between each report of the system statistics.
update_interval:
  secs: 30
  nanos: 0

# You can have multiple filesystem disk usages be reported.
# Each entry here should have its path be set to the root of the filesystem
# you wish to report the usage of, and the name is what name it will
# reported as to mqtt.
drives:
  - path: /
    name: root

Once you have adjusted the configuration as needed, run systemctl reload system-mqtt to restart the service with the new configuration.

Run systemctl status system-mqtt after to verify the configuration loaded and the daemon is running correctly.

system-mqtt's People

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

Watchers

 avatar  avatar  avatar  avatar

system-mqtt's Issues

FR: Allow other password storage methods

The default password storage method relies on the system keychain, which for some reason does not work well on headless systems. Are there other ways that the password could be stored, or is there a way to ensure that the keychain will work with a headless system?

Error received:

$ system-mqtt set-password
Password: <entered interactively>
Fatal error: Keyring Error: Secret Service Error: Dbus error: "The name org.freedesktop.secrets was not provided by any .service files"
If you have not yet set the password run `system-mqtt set-password`.

cargo deb --install results in I/O error

Hi! So I've made sure all dependencies are installed but when I run cargo deb --install I get

cargo-
deb: I/O error: No such file or directory (os error 2)
because: No such file or directory (os error 2)

at the end.

Any thoughts on this? Been trying to get my Intel NUC's stats into Home Assistant for ages now.

Cannot set password

I think I almost have this running, but it's fighting me on the password. What am I doing wrong here?

I first tried the keyring, following the directions. But I get the error:
Fatal error: Failed to get password from keyring. If you have not yet set the password, run system-mqtt set-password.

I have used that command, several times. It always gives a single "Password:" prompt and seems to take my password and shows no following error or message. I've tried copy/pasting in the password, and manually typing it, or even typing a bad password. I always get this error.

So next I tried the password file. But that too gives me an error:
Fatal error: Permission bits for password file must be set to 0o600 (only owner can read and write)

password_source: !secret_file /opt/system-mqtt/system-mqtt.pwd

/opt/system-mqtt$ ls -l
total 8
drwxr-xr-x 6 root root 4096 Jul 10 15:30 system-mqtt
-rw------- 1 root root 13 Jul 10 16:08 system-mqtt.pwd

I tried setting it to 660 and chown to my account, and in all cases get the same error.

I am running Ubuntu if that makes any difference.

Next Generation of this application

I've been finding myself wishing there were certain tools for Home Assistant, but they don't exist.
Last time I had that feeling I created this project to fill that void.

I think that the new tools I want for HA overlap with the purpose of this application, so I may add those features into this application, but the changes would be rather radical, and be breaking changes. I want a way to create automatons involving my desktop computer, but be more secure than having my HA server ssh into the machine, but less complicated than spinning up a new application with an mqtt interface.

The I want to copy the idea of ESPHome: a platform for making your own HA devices without needing to know how to write embedded C++. You just write a bunch of YAML config files.

This tool would be very similar, but would focus on the SoCs (like the Raspberry Pi) and desktops. Many features would be built in, such as the ones system-mqtt already provides. It would also be able to advertise services to HA, like to reboot the system, power it off entirely, or run a shell script. It can also advertise sensors. It could be extended by calling into other applications and parsing stdout for data. While ESPHome uses YAML, I think Lua would be a better fit for system-mqtt, as it already has the ability to read files from under /proc and would be easier to create parsers with.

A dedicated plugin for HA could make setup much easier and secure. It's important the service not advertise itself to any HA instance on any network. The same concerns apply to MQTT.

Missing some Sensors

Hi Carl -
first of all, thanks for the great tool.

Do you have any idea why only CPU usage and Memory usage, but not Swap usage, Filesystem usage, Battery state and Battery level are visible in Broker?
My environment: Linux Mint / HA in VMware.

Thanks in advance.

Request: temperature sensors

Really cool project, would be great if you could add temperature sensor support (heim already some support)!

EDIT: created a simple, quick-and-dirty script with MQTT Discovery to address my needs here

Heim is abandoned

It hasn't been updated in two years and its old dependencies prevent me from updating more security critical dependencies.
I'll either have to update it myself, or use something else.

Cant install, `no such command: "deb"`

I followed your installation and tried to install & build your app.
But it fails on step 4. (cargo deb --install)
(Installed rust via https://rustup.rs/)

Error message:

error: no such command: `deb`

	Did you mean `b`?

	View all installed commands with `cargo --list`

OS: Ubuntu 18.04.06
Cargo: 1.66.1

I tried it with "cargo build" first, but didnt work either.
What do im wrong?

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.