@ -0,0 +1,9 @@ | |||||
root = true | |||||
[*.cr] | |||||
charset = utf-8 | |||||
end_of_line = lf | |||||
insert_final_newline = true | |||||
indent_style = space | |||||
indent_size = 2 | |||||
trim_trailing_whitespace = true |
@ -0,0 +1,5 @@ | |||||
/docs/ | |||||
/lib/ | |||||
/bin/ | |||||
/.shards/ | |||||
*.dwarf |
@ -0,0 +1,6 @@ | |||||
language: crystal | |||||
# Uncomment the following if you'd like Travis to run specs and check code formatting | |||||
# script: | |||||
# - crystal spec | |||||
# - crystal tool format --check |
@ -0,0 +1,21 @@ | |||||
The MIT License (MIT) | |||||
Copyright (c) 2019 your-name-here | |||||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||||
of this software and associated documentation files (the "Software"), to deal | |||||
in the Software without restriction, including without limitation the rights | |||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||||
copies of the Software, and to permit persons to whom the Software is | |||||
furnished to do so, subject to the following conditions: | |||||
The above copyright notice and this permission notice shall be included in | |||||
all copies or substantial portions of the Software. | |||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||||
THE SOFTWARE. |
@ -0,0 +1,6 @@ | |||||
version: 1.0 | |||||
shards: | |||||
hardware: | |||||
github: crystal-community/hardware | |||||
version: 0.4.0 | |||||
@ -0,0 +1,17 @@ | |||||
name: hwinfo | |||||
version: 0.1.0 | |||||
authors: | |||||
- Marcel Haazen <marcel@haazen.xyz> | |||||
targets: | |||||
hwinfo: | |||||
main: src/hwinfo.cr | |||||
dependencies: | |||||
hardware: | |||||
github: crystal-community/hardware | |||||
crystal: 0.30.1 | |||||
license: MIT |
@ -0,0 +1,9 @@ | |||||
require "./spec_helper" | |||||
describe Hwinfo do | |||||
# TODO: Write tests | |||||
it "works" do | |||||
false.should eq(true) | |||||
end | |||||
end |
@ -0,0 +1,2 @@ | |||||
require "spec" | |||||
require "../src/hwinfo" |
@ -0,0 +1,41 @@ | |||||
# TODO: Write documentation for `Hwinfo` | |||||
require "hardware" | |||||
require "./hwinfo/*" | |||||
module Hwinfo | |||||
include Memcalc | |||||
extend self | |||||
memory = Hardware::Memory.new | |||||
cpu = Hardware::CPU.new | |||||
puts "Host Information" | |||||
puts "Hostname: #{System.hostname}" | |||||
puts "Uptime: #{uptime.first.seconds}" | |||||
puts "Idle Time: #{uptime[1].seconds}" | |||||
puts "Kernel Version: #{kernel[2]}" | |||||
puts "" | |||||
puts "CPU Information" | |||||
puts "Cores: #{System.cpu_count}" | |||||
puts "CPU Usage: #{cpu.usage.to_i}%" | |||||
puts "" | |||||
puts "Memory Information" | |||||
puts "Used: #{gb(memory.used).round(2)}GB" | |||||
puts "Available: #{gb(memory.available).round(2)}GB" | |||||
puts "Total: #{gb(memory.total).round(2)}GB" | |||||
private def self.read_file(filename : String) | |||||
File.read(File.join("/proc", filename)).strip | |||||
end | |||||
def self.uptime | |||||
uptimes = read_file("uptime").split(/\s+/).map(&.to_f64) | |||||
end | |||||
def self.kernel | |||||
kernel = read_file("version").split(/\s+/) | |||||
end | |||||
end |
@ -0,0 +1,12 @@ | |||||
module Memcalc | |||||
extend self | |||||
def mb(kb) | |||||
kb.to_f / (1 << 10) | |||||
end | |||||
def gb(kb) | |||||
kb.to_f / (1 << 20) | |||||
end | |||||
def tb(kb) | |||||
kb.to_f / (1 << 30) | |||||
end | |||||
end |
@ -0,0 +1,3 @@ | |||||
module Strgcalc | |||||
end |
@ -0,0 +1,3 @@ | |||||
module Hwinfo | |||||
VERSION = "0.1.0" | |||||
end |