Skip to content

Repository files navigation

resource-holder

简体中文

CI License: MIT Go Report Card

Cross-platform CLI: holder keeps CPU/memory usage at target levels; watch monitors a process and runs shell commands when thresholds are met.

Features

  • System-wide or per-core CPU hold
  • Memory hold by percentage or fixed size
  • CPU / memory sine-wave modes
  • Process CPU and memory thresholds with AND/OR logic
  • CLI flags and JSON config (flags override config)
  • Windows, Linux, macOS

Layout

.
├── cmd/resource-holder/   # main entrypoint
├── internal/cli/          # Cobra commands
├── internal/config/       # config loading
├── internal/platform/     # OS-specific code
├── internal/resource/     # hold & watch logic
└── examples/              # sample JSON configs

Build: make build → bin/resource-holder. Cross-compile: make build-all → dist/resource-holder_<os>_<arch>.

Install

Requires Go 1.22+.

git clone https://github.com/soraclub/resource-holder.git
cd resource-holder
go mod download
make build

Equivalent:

go build -o bin/resource-holder ./cmd/resource-holder

Install to $PATH:

make install

Usage

After make build or make install, commands below use resource-holder (or ./bin/resource-holder during local dev).

holder

Hold resources at the target when usage is below the target; do nothing when already above.

resource-holder holder -c 50%
resource-holder holder -m 1G
resource-holder holder -c 50% -m 1G -i 2s
resource-holder holder -f examples/holder_config.json
resource-holder holder -c 50% --cpu-sine --cpu-amplitude 20% --cpu-period 30s
resource-holder holder -m 1G --mem-sine --mem-amplitude 200MB --mem-period 30s

watch

Monitor a PID and run operations when thresholds match. Use {PID} in command strings.

resource-holder watch -p 1234 -c ">50%" -o "echo process {PID} over limit"
resource-holder watch -p 1234 -m ">1G" -o "kill {PID}"
resource-holder watch -p 1234 -c ">50%" -m ">1G" -l or -o "kill {PID}"
resource-holder watch -p 1234 -c ">50%" -o "kill {PID}" -t 1
resource-holder watch -f examples/watch_config.json

Config files

JSON with top-level holder or watch. Samples in examples/:

File Description
holder_config.json CPU (optional per-core), memory, interval
holder_sine_config.json holder with CPU sine wave
watch_config.json thresholds, logic, operations, trigger limit

Pass -f / --config. For field details and defaults, see:

resource-holder holder --help
resource-holder watch --help

Development

make test
make vet
make lint      # requires golangci-lint locally
make build-all

See CONTRIBUTING.md, CHANGELOG.md, and RELEASE.md (GitHub setup, main, tagging).

License

MIT

About

Cross-platform CLI to hold CPU/memory usage or watch processes on thresholds

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages