A basic module to get CPU, memory and network informations of the current running OS and its processes.
Tested on Linux.
Add this to your application's
dependencies: hardware: github: crystal-community/hardware
The documentation is accessible at https://crystal-community.github.io/hardware.
It is generated with crystal docs in the
require "hardware" memory = Hardware::Memory.new memory.used #=> 2731404 memory.percent.to_i #=> 32 cpu = Hardware::CPU.new pid = Hardware::PID.new # Default is Process.pid app = Hardware::PID.new "firefox" # Take the first matching PID loop do sleep 1 cpu.usage.to_i #=> 17 pid.cpu_usage #=> 1.5 app.cpu_usage.to_i #=> 4 end
You can run the specs in a Docker container:
$ docker-compose up $ docker-compose run spec
- Fork it ( https://github.com/crystal-community/hardware/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request