pikuseru

conkvidia-smi.lua

Nov 29th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.87 KB | None | 0 0
  1. --[[
  2. Firstly, thanks a ton for choosing to use my work on your machine, I hope it serves you well.
  3. I'd be very happy to hear if you have a way to improve or expand it, as this is one of my first real coding projects.
  4. -/u/Pikuseru1
  5.  
  6. In order to add any of these values to your conky configuration, first add
  7.  
  8.     lua_load = "~/PATH/TO/YOUR/conky/conkvidia-smi.lua",
  9.  
  10. to the conky.config section. Then, add $lua or $lua_bar variables as shown below.
  11.  
  12. Unfortunately, $lua_graph doesn't allow you to pass parameters to lua scripts, which is how most of this info gets sent to conky.
  13. This means that for $lua_graph variables, you need to use the functions at the bottom of this script which only provide percent use.
  14. Also, unless it is given a parameter, the "gpu" function will just give you overall utilization.
  15.  
  16. A few examples;
  17.  
  18. To display the base reading (no units) from a sensor:
  19. ${lua gpu}              --->   12
  20. ${lua gpu gpuutil}      --->   12
  21. ${lua gpu gclock}       --->   658
  22. ${lua gpu vrampct}      --->   24.654165934
  23. ${lua gpu vramwpct}     --->   24
  24.  
  25. To make a usage bar/gauge (these expect a 0-100), these are setup as 10x250px
  26.  
  27. ${lua_bar gpu 10,250 gpuutil}
  28. ${lua_bar gpu 10,250 vrampct}
  29. ${lua_bar gpu 10,250 fanspd}
  30.  
  31. To make a graph (the one that scrolls by over time), these are set up as 32x300px and fade from white to black
  32. REMEMBER you can't pass parameters for these! Use the "whole funtions"
  33.  
  34. ${lua_graph gpu 32,300 000000 ffffff}
  35. ${lua_graph gpu_vram 32,300 000000 ffffff}
  36. ${lua_graph gpu_pwr 32,300 000000 ffffff}
  37.  
  38. To be honest, if you even know what this is for, you can probably figure it out from here.
  39.  
  40. Again, thanks, and enjoy!
  41. ]]
  42.  
  43. function conky_gpu(want)
  44.  
  45.     -- collect sensor data, use with ${lua gpu <sensor>} variables
  46.     local gpuutil   =tonumber(conky_parse('${exec nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits}'))      -- overall utilization - %
  47.     local gputemp   =tonumber(conky_parse('${exec nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits}'))      -- temperature - c
  48.     local fanspd    =tonumber(conky_parse('${exec nvidia-smi --query-gpu=fan.speed --format=csv,noheader,nounits}'))            -- fan speed - %
  49.     local pstate    =tostring(conky_parse('${exec nvidia-smi --query-gpu=pstate --format=csv,noheader,nounits}'))               -- power state - (P0-P12, P0 is highest)
  50.     local gclock    =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.gr --format=csv,noheader,nounits}'))            -- current graphics clock speed - MHz
  51.     local gclmax    =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.max.gr --format=csv,noheader,nounits}'))        -- max graphics clock - MHz
  52.     local mclock    =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.mem --format=csv,noheader,nounits}'))           -- current memory clock speed -MHz
  53.     local mclmax    =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.max.mem --format=csv,noheader,nounits}'))       -- max memory clock - MHz
  54.     local vram      =tonumber(conky_parse('${exec nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits}'))          -- vram in use - MB
  55.     local vrammax   =tonumber(conky_parse('${exec nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits}'))         -- vram available - MB
  56.     local pwr       =tonumber(conky_parse('${exec nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits}'))           -- power draw - W
  57.     local pwrmax    =tonumber(conky_parse('${exec nvidia-smi --query-gpu=power.limit --format=csv,noheader,nounits}'))          -- power draw limit - W
  58.    
  59.     -- calulate exact percent values for sensors, use with ${lua_bar gpu <sensor>} variables, not great for display as the output is several decimals long, eg. 24.982734954
  60.     local vrampct   =vram/vrammax*100                                                                                       -- vram percentage
  61.     local gclpct    =gclock/gclmax*100                                                                                          -- graphics clock percentage
  62.     local mclpct    =mclock/mclmax*100                                                                                          -- memory clock percentage
  63.     local pwrpct    =pwr/pwrmax*100                                                                                             -- power draw percentage
  64.  
  65.     -- turn the exact percent values into whole numbers, use with ${lua gpu <sensor>} variables for displaying percents, eg. 24%
  66.     local vramwpct  =string.format("%3.0f", vrampct)                                                                            -- vram whole percentage
  67.     local gclwpct   =string.format("%3.0f", gclpct)                                                                             -- graphics clock whole percentage
  68.     local mclwpct   =string.format("%3.0f", mclpct)                                                                             -- memory clock whole percentage
  69.     local pwrwpct   =string.format("%3.0f", pwrpct)                                                                             -- power draw whole percentage
  70.  
  71.     -- feed the hungy
  72.     if want=='gpuutil' then
  73.         return gpuutil
  74.     end
  75.     if want=='gputemp' then
  76.         return gputemp
  77.     end
  78.     if want=='fanspd' then
  79.         return fanspd
  80.     end
  81.     if want=='gclock' then
  82.         return gclock
  83.     end
  84.     if want=='mclock' then
  85.         return mclock
  86.     end
  87.     if want=='gclmax' then
  88.         return gclmax
  89.     end
  90.     if want=='mclmax' then
  91.         return mclmax
  92.     end
  93.     if want=='vram' then
  94.         return vram
  95.     end
  96.     if want=='vrammax' then
  97.         return vrammax
  98.     end
  99.     if want=='vrampct' then
  100.         return vrampct
  101.     end
  102.     if want=='vramwpct' then
  103.         return vramwpct
  104.     end
  105.     if want=='gclpct' then
  106.         return gclpct
  107.     end
  108.     if want=='gclwpct' then
  109.         return gclwpct
  110.     end
  111.     if want=='mclpct' then
  112.         return mclpct
  113.     end
  114.     if want=='mclwpct' then
  115.         return mclwpct
  116.     end
  117.     if want=='pwr' then
  118.         return pwr
  119.     end
  120.     if want=='pwrmax' then
  121.         return pwrmax
  122.     end
  123.     if want=='pwrpct' then
  124.         return pwrpct
  125.     end
  126.     if want=='pwrwpct' then
  127.         return pwrwpct
  128.     end
  129.     if want=='pstate' then
  130.         return pstate
  131.     end
  132.        
  133.     -- This is here so that $lua_graph can show GPU load over time.
  134.     return gpuutil
  135. end
  136.  
  137. -- Ah, good to see you again! As a reminder, these are only meant for use with $lua_graph. They'll work elsewhere though, if you insist.
  138.  
  139. function conky_gpu_gclock() -- Clock speed percentage
  140.     return gclpct
  141. end
  142.  
  143. function conky_gpu_mclock() -- Memory clock speed percentage
  144.     return mclpct
  145. end
  146.  
  147. function conky_gpu_vram() -- VRAM load percentage
  148.     return vrampct
  149. end
  150.  
  151. function conky_gpu_pwr() -- Power draw percentage
  152.     return pwrpct
  153. end
Add Comment
Please, Sign In to add comment