Dead-simple battery monitor for Linux.
Find a file
NotAShelf 8e7365b93f
Some checks failed
Go Build / build (push) Has been cancelled
bump dependencies
2025-01-10 16:36:51 +03:00
.github/workflows CI: build with go 2024-01-11 22:56:10 +03:00
internal officially rename package to batmon 2024-01-11 23:38:08 +03:00
nix use default.target instead of multi-user.target 2025-01-08 23:46:19 +00:00
vendor bump dependencies 2025-01-10 16:36:51 +03:00
.envrc cleanup 2024-01-11 23:43:27 +03:00
.gitignore go rewrite 2024-01-11 22:51:07 +03:00
example.config.json go rewrite 2024-01-11 22:51:07 +03:00
flake.lock nix: modernize 2025-01-08 11:08:07 +03:00
flake.nix nix: remove redundant arg 2025-01-08 11:09:05 +03:00
go.mod bump dependencies 2025-01-10 16:36:51 +03:00
go.sum bump dependencies 2025-01-10 16:36:51 +03:00
LICENSE Initial commit 2024-01-08 19:13:35 +03:00
main.go add short description 2025-01-08 11:07:46 +03:00
README.md docs: expand nix installation; wording 2025-01-08 11:19:16 +03:00

🔋 Batmon

Dead-simple, somewhat configurable battery monitor for Linux. Batmon monitors the battery path in real time and adjusts your power profiles accordingly to optimize battery life for e.g. laptops.

Features

  • Real-time monitoring of battery status
  • Dynamic adjustment of power profiles
  • Simple configuration though JSON configuration file
    • Optional command execution on state changes

Installation

Prerequisites

  • Upower
  • powerprofilesctl
  • Nix or Go

Nix

You are strongly encouraged to get Batmon through Nix, using the flake located in this repository. You may install it manually on non-NixOS systems using nix profile install.

nix profile install github:NotAShelf/batmon

Or on NixOS systems using the package exposed for your system.

{inputs, pkgs, ...}: {
  environment.systemPackages = [
    inputs.batmon.packages.${pkgs.stdenv.system}.default
  ];
}

Alternatively, using the NixOS module to install Batmon and configure a systemd service for you.

{inputs, pkgs, ...}: {
  imports = [inputs.batmon.nixosModules.default];
  services.batmon.enable = true;
}

Manually

go install . # this will install Batmon in your $GOPATH

Start Batmon through your terminal, or as a systemd service.

Configuration

By default, Batmon will load the configuration from config.json located in the current directory. You can specify a different configuration file using the --config flag:

batmon -c /path/to/config.json

The configuration file should contain a list of batteries to monitor, along with any custom commands or extra commands to execute. Here's an example of a configuration file:

{
  "batPaths": [
    {
      "path": "/sys/class/power_supply/BAT0",
      "command": "powerprofilesctl set performance",
      "extraCommand": "echo 'Battery is charging' | wall"
    }
  ]
}
  • You can leave command empty to use the default behaviour - which will switch active powerprofile using powerprofiles set performance | balanced

  • extraCommand, if provided, will be executed in addition to the command value.