aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2014-02-09 18:28:28 (GMT)
committerAdrian C. (anrxc) <anrxc@sysphere.org>2014-02-09 18:30:26 (GMT)
commit178bc65f1b5d3133e34a76b96dac484fe8a07e1e (patch)
tree661fda59d93d59dc86cc2b0dbccc8258254e89bc
parentdf19dac43eee3f15695e97a6eaec70b2a3ed85dd (diff)
downloadvicious-legacy-178bc65f1b5d3133e34a76b96dac484fe8a07e1e.tar.xz
contrib: import nvidia SMI widget type
Right now nvsmi is just interested in temperature information. My streaming server GPU 'fell of the bus' last night while decoding video, I suspect overheating.
-rw-r--r--contrib/README5
-rw-r--r--contrib/nvsmi.lua42
2 files changed, 47 insertions, 0 deletions
diff --git a/contrib/README b/contrib/README
index 0523b66..235599c 100644
--- a/contrib/README
+++ b/contrib/README
@@ -68,6 +68,11 @@ vicious.contrib.openweather
- returns a table with string keys: {city}, {wind deg}, {wind aim},
{wind kmh}, {wind mps}, {sky}, {weather}, {temp c}, {humid}, {press}
+vicious.contrib.nvsmi
+ - provides (very basic) information about Nvidia GPU status from SMI
+ - takes optional card ID as an argument, i.e. "1", or defaults to ID 0
+ - returns 1st value as temperature of requested graphics device
+
vicious.contrib.ossvol
-
diff --git a/contrib/nvsmi.lua b/contrib/nvsmi.lua
new file mode 100644
index 0000000..e68d4a1
--- /dev/null
+++ b/contrib/nvsmi.lua
@@ -0,0 +1,42 @@
+---------------------------------------------------
+-- Licensed under the GNU General Public License v2
+-- * (c) 2014, Adrian C. <anrxc@sysphere.org>
+---------------------------------------------------
+
+-- {{{ Grab environment
+local tonumber = tonumber
+local io = { popen = io.popen }
+local setmetatable = setmetatable
+local string = { match = string.match }
+-- }}}
+
+
+-- nvsmi: provides GPU information from nvidia SMI
+-- vicious.contrib.nvsmi
+local nvsmi = {}
+
+
+-- {{{ GPU Information widget type
+local function worker(format, warg)
+ -- Fallback to querying first device
+ if not warg then warg = "0" end
+
+ -- Get data from smi
+ -- * Todo: support more; MEMORY,UTILIZATION,ECC,POWER,CLOCK,COMPUTE,PIDS,PERFORMANCE
+ local f = io.popen("nvidia-smi -q -d TEMPERATURE -i " .. warg)
+ local smi = f:read("*all")
+ f:close()
+
+ -- Not installed
+ if smi == nil then return {0} end
+
+ -- Get temperature information
+ local _thermal = string.match(smi, "Gpu[%s]+:[%s]([%d]+)[%s]C")
+ -- Handle devices without data
+ if _thermal == nil then return {0} end
+
+ return {tonumber(_thermal)}
+end
+-- }}}
+
+return setmetatable(nvsmi, { __call = function(_, ...) return worker(...) end })