Parcourir la source

Main code

master
Marcel Haazen il y a 4 ans
Parent
révision
d38d3d7cda
14 fichiers modifiés avec 134 ajouts et 0 suppressions
  1. +9
    -0
      .editorconfig
  2. +5
    -0
      .gitignore
  3. +6
    -0
      .travis.yml
  4. +21
    -0
      LICENSE
  5. BIN
      hwinfo
  6. BIN
      hwinfo.o
  7. +6
    -0
      shard.lock
  8. +17
    -0
      shard.yml
  9. +9
    -0
      spec/hwinfo_spec.cr
  10. +2
    -0
      spec/spec_helper.cr
  11. +41
    -0
      src/hwinfo.cr
  12. +12
    -0
      src/hwinfo/memcalc.cr
  13. +3
    -0
      src/hwinfo/strgcalc.cr
  14. +3
    -0
      src/hwinfo/version.cr

+ 9
- 0
.editorconfig Voir le fichier

@ -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

+ 5
- 0
.gitignore Voir le fichier

@ -0,0 +1,5 @@
/docs/
/lib/
/bin/
/.shards/
*.dwarf

+ 6
- 0
.travis.yml Voir le fichier

@ -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

+ 21
- 0
LICENSE Voir le fichier

@ -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.

BIN
hwinfo Voir le fichier


BIN
hwinfo.o Voir le fichier


+ 6
- 0
shard.lock Voir le fichier

@ -0,0 +1,6 @@
version: 1.0
shards:
hardware:
github: crystal-community/hardware
version: 0.4.0

+ 17
- 0
shard.yml Voir le fichier

@ -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

+ 9
- 0
spec/hwinfo_spec.cr Voir le fichier

@ -0,0 +1,9 @@
require "./spec_helper"
describe Hwinfo do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end

+ 2
- 0
spec/spec_helper.cr Voir le fichier

@ -0,0 +1,2 @@
require "spec"
require "../src/hwinfo"

+ 41
- 0
src/hwinfo.cr Voir le fichier

@ -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

+ 12
- 0
src/hwinfo/memcalc.cr Voir le fichier

@ -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

+ 3
- 0
src/hwinfo/strgcalc.cr Voir le fichier

@ -0,0 +1,3 @@
module Strgcalc
end

+ 3
- 0
src/hwinfo/version.cr Voir le fichier

@ -0,0 +1,3 @@
module Hwinfo
VERSION = "0.1.0"
end

Chargement…
Annuler
Enregistrer