hardware
This is a very basic module to help get CPU and memory usage of the current running OS
Tested on Linux.
Installation
Add this to your application's shard.yml
:
dependencies:
hardware:
github: crystal-community/hardware
Usage
Methods included in the Hardware::CPU
module:
.info : NamedTuple(used: Int32, idle: Int32, total: Int32)
Returns a NamedTuple including the used, idle and total CPU time.
.used(sleep_time = 1) : Int32
Returns the cpu used in percentage in the last sleep_time
seconds.
Methods included in the Hardware::Memory
struct:
.new
Creates a new Hardware::Memory
based on the current memory state.
#available : Int32
Returns the available memory in KiloBytes.
#meminfo : Hash(String, Int64)
Returns an Hash from a parsed /proc/meminfo
#percent(used = true) : Int32
Returns either the used/available memory in percentage.
#total : Int32
Returns the total memory in KiloBytes.
#used : Int32
Returns the memory used in KiloBytes.
Examples
require "hardware"
memory = Hardware::Memory.new
memory.used #=> 2731404
memory.percent #=> 32
Hardware::CPU.used #=> 12
Development
Docker
You can run the specs in a Docker container:
$ docker-compose up
$ docker-compose run spec
Contributing
- 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