hardware

Get CPU, Memory and Network informations of the running OS and its processes hardware cpu memory network system
0.2.2 released

hardware

Build Status

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.

.each_use(sleep_time = 1) : Int32

Returns the cpu used in percentage each sleep_time seconds infinitely.

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
Hardware::CPU.each_use do |cpu|
  cpu              #=> 17
end

Development

Docker

You can run the specs in a Docker container:

$ docker-compose up
$ docker-compose run spec

Contributing

  1. Fork it ( https://github.com/crystal-community/hardware/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

hardware:
  github: crystal-community/hardware
  version: ~> 0.2.2
License MIT
Crystal 0.24.2

Authors

Dependencies 0

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently