SHARE
TWEET

Untitled

a guest Feb 17th, 2017 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function get_mem_vals()
  2.     local result={}
  3.     local keys={"MemTotal","MemFree","MemAvailable","Buffers"}
  4.    
  5.     local f=assert(io.open("/proc/loadavg", "r"))
  6.     local loadavg = f:read("*all")
  7.     local t={}
  8.  
  9.     for k,v in loadavg:gmatch("%d+%.%d+") do table.insert(t,k) end
  10.  
  11.     result["load_1m"]=t[1]
  12.     result["load_5m"]=t[2]
  13.     result["load_15m"]=t[3]
  14.  
  15.     local f=assert(io.popen("grep -E '(^Mem|^Buf)' /proc/meminfo ", "r"))
  16.     for l in f:lines() do
  17.         for k2,v2 in pairs(keys) do
  18.             if l:find(v2) then
  19.                 result[v2]=l:match("%d+")
  20.             end
  21.         end
  22.     end
  23.  
  24.     return result
  25. end
  26.  
  27.  
  28. for _,v in pairs(get_mem_vals()) do
  29.     print(_..": "..v)
  30. end
RAW Paste Data
Top