diff --git a/.editorconfig b/.editorconfig new file mode 100755 index 0000000..163eb75 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..0bb75ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/docs/ +/lib/ +/bin/ +/.shards/ +*.dwarf diff --git a/.travis.yml b/.travis.yml new file mode 100755 index 0000000..765f0e9 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..0bfc21c --- /dev/null +++ b/LICENSE @@ -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. diff --git a/hwinfo b/hwinfo new file mode 100755 index 0000000..12cf3d6 Binary files /dev/null and b/hwinfo differ diff --git a/hwinfo.o b/hwinfo.o new file mode 100644 index 0000000..c73c485 Binary files /dev/null and b/hwinfo.o differ diff --git a/shard.lock b/shard.lock new file mode 100755 index 0000000..7155059 --- /dev/null +++ b/shard.lock @@ -0,0 +1,6 @@ +version: 1.0 +shards: + hardware: + github: crystal-community/hardware + version: 0.4.0 + diff --git a/shard.yml b/shard.yml new file mode 100755 index 0000000..6e48043 --- /dev/null +++ b/shard.yml @@ -0,0 +1,17 @@ +name: hwinfo +version: 0.1.0 + +authors: + - Marcel Haazen + +targets: + hwinfo: + main: src/hwinfo.cr + +dependencies: + hardware: + github: crystal-community/hardware + +crystal: 0.30.1 + +license: MIT diff --git a/spec/hwinfo_spec.cr b/spec/hwinfo_spec.cr new file mode 100755 index 0000000..6896217 --- /dev/null +++ b/spec/hwinfo_spec.cr @@ -0,0 +1,9 @@ +require "./spec_helper" + +describe Hwinfo do + # TODO: Write tests + + it "works" do + false.should eq(true) + end +end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr new file mode 100755 index 0000000..95dbb72 --- /dev/null +++ b/spec/spec_helper.cr @@ -0,0 +1,2 @@ +require "spec" +require "../src/hwinfo" diff --git a/src/hwinfo.cr b/src/hwinfo.cr new file mode 100755 index 0000000..2555094 --- /dev/null +++ b/src/hwinfo.cr @@ -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 diff --git a/src/hwinfo/memcalc.cr b/src/hwinfo/memcalc.cr new file mode 100644 index 0000000..abfa740 --- /dev/null +++ b/src/hwinfo/memcalc.cr @@ -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 \ No newline at end of file diff --git a/src/hwinfo/strgcalc.cr b/src/hwinfo/strgcalc.cr new file mode 100644 index 0000000..4d8be7c --- /dev/null +++ b/src/hwinfo/strgcalc.cr @@ -0,0 +1,3 @@ +module Strgcalc + +end \ No newline at end of file diff --git a/src/hwinfo/version.cr b/src/hwinfo/version.cr new file mode 100644 index 0000000..fa6238f --- /dev/null +++ b/src/hwinfo/version.cr @@ -0,0 +1,3 @@ +module Hwinfo + VERSION = "0.1.0" +end \ No newline at end of file