Sha256: 58dfa924d7a51fc45a2d0e1adc20ec702900846a0e74132a79a6d6942bc44880
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true module StatsLite module Default class << self def host { hostname: h.command("hostname", cache: true), ip: ip } end def cpu { model: h.command("lscpu | grep 'Model name' | cut -f 2 -d \":\" | awk '{$1=$1}1'", cache: true), cores: h.command("nproc", cache: true), usage: _cpu_usage } end def ip { public: h.command("curl -s ifconfig.me", cache: true) } end def ram result = -> do map = Vidibus::Sysinfo.memory.to_h map.map do |k, v| map[k] = "#{(v / 1024.to_f).round(2)}GB" end map end { usage: h.fetch(:ram, result, expires_in: 10) } end def _cpu_usage total = <<-CMD (grep 'cpu ' /proc/stat;sleep 0.1;grep 'cpu ' /proc/stat)|awk -v RS="" '{print ""($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)"%"}' CMD { total: fmt_nr(h.command(total)) } end def hdd result = -> do map = Vidibus::Sysinfo.storage.to_h map.map do |k, v| map[k] = "#{v}GB" end map end { usage: h.fetch(:hdd, result, expires_in: 60) } end def fmt_nr(number) "#{number.gsub("%", "").to_i}%" end def h StatsLite::Helper end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stats_lite-0.5.2 | lib/stats_lite/default.rb |