Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Firstly, thanks a ton for choosing to use my work on your machine, I hope it serves you well.
- 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.
- -/u/Pikuseru1
- In order to add any of these values to your conky configuration, first add
- lua_load = "~/PATH/TO/YOUR/conky/conkvidia-smi.lua",
- to the conky.config section. Then, add $lua or $lua_bar variables as shown below.
- Unfortunately, $lua_graph doesn't allow you to pass parameters to lua scripts, which is how most of this info gets sent to conky.
- This means that for $lua_graph variables, you need to use the functions at the bottom of this script which only provide percent use.
- Also, unless it is given a parameter, the "gpu" function will just give you overall utilization.
- A few examples;
- To display the base reading (no units) from a sensor:
- ${lua gpu} ---> 12
- ${lua gpu gpuutil} ---> 12
- ${lua gpu gclock} ---> 658
- ${lua gpu vrampct} ---> 24.654165934
- ${lua gpu vramwpct} ---> 24
- To make a usage bar/gauge (these expect a 0-100), these are setup as 10x250px
- ${lua_bar gpu 10,250 gpuutil}
- ${lua_bar gpu 10,250 vrampct}
- ${lua_bar gpu 10,250 fanspd}
- To make a graph (the one that scrolls by over time), these are set up as 32x300px and fade from white to black
- REMEMBER you can't pass parameters for these! Use the "whole funtions"
- ${lua_graph gpu 32,300 000000 ffffff}
- ${lua_graph gpu_vram 32,300 000000 ffffff}
- ${lua_graph gpu_pwr 32,300 000000 ffffff}
- To be honest, if you even know what this is for, you can probably figure it out from here.
- Again, thanks, and enjoy!
- ]]
- function conky_gpu(want)
- -- collect sensor data, use with ${lua gpu <sensor>} variables
- local gpuutil =tonumber(conky_parse('${exec nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits}')) -- overall utilization - %
- local gputemp =tonumber(conky_parse('${exec nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits}')) -- temperature - c
- local fanspd =tonumber(conky_parse('${exec nvidia-smi --query-gpu=fan.speed --format=csv,noheader,nounits}')) -- fan speed - %
- local pstate =tostring(conky_parse('${exec nvidia-smi --query-gpu=pstate --format=csv,noheader,nounits}')) -- power state - (P0-P12, P0 is highest)
- local gclock =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.gr --format=csv,noheader,nounits}')) -- current graphics clock speed - MHz
- local gclmax =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.max.gr --format=csv,noheader,nounits}')) -- max graphics clock - MHz
- local mclock =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.mem --format=csv,noheader,nounits}')) -- current memory clock speed -MHz
- local mclmax =tonumber(conky_parse('${exec nvidia-smi --query-gpu=clocks.max.mem --format=csv,noheader,nounits}')) -- max memory clock - MHz
- local vram =tonumber(conky_parse('${exec nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits}')) -- vram in use - MB
- local vrammax =tonumber(conky_parse('${exec nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits}')) -- vram available - MB
- local pwr =tonumber(conky_parse('${exec nvidia-smi --query-gpu=power.draw --format=csv,noheader,nounits}')) -- power draw - W
- local pwrmax =tonumber(conky_parse('${exec nvidia-smi --query-gpu=power.limit --format=csv,noheader,nounits}')) -- power draw limit - W
- -- 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
- local vrampct =vram/vrammax*100 -- vram percentage
- local gclpct =gclock/gclmax*100 -- graphics clock percentage
- local mclpct =mclock/mclmax*100 -- memory clock percentage
- local pwrpct =pwr/pwrmax*100 -- power draw percentage
- -- turn the exact percent values into whole numbers, use with ${lua gpu <sensor>} variables for displaying percents, eg. 24%
- local vramwpct =string.format("%3.0f", vrampct) -- vram whole percentage
- local gclwpct =string.format("%3.0f", gclpct) -- graphics clock whole percentage
- local mclwpct =string.format("%3.0f", mclpct) -- memory clock whole percentage
- local pwrwpct =string.format("%3.0f", pwrpct) -- power draw whole percentage
- -- feed the hungy
- if want=='gpuutil' then
- return gpuutil
- end
- if want=='gputemp' then
- return gputemp
- end
- if want=='fanspd' then
- return fanspd
- end
- if want=='gclock' then
- return gclock
- end
- if want=='mclock' then
- return mclock
- end
- if want=='gclmax' then
- return gclmax
- end
- if want=='mclmax' then
- return mclmax
- end
- if want=='vram' then
- return vram
- end
- if want=='vrammax' then
- return vrammax
- end
- if want=='vrampct' then
- return vrampct
- end
- if want=='vramwpct' then
- return vramwpct
- end
- if want=='gclpct' then
- return gclpct
- end
- if want=='gclwpct' then
- return gclwpct
- end
- if want=='mclpct' then
- return mclpct
- end
- if want=='mclwpct' then
- return mclwpct
- end
- if want=='pwr' then
- return pwr
- end
- if want=='pwrmax' then
- return pwrmax
- end
- if want=='pwrpct' then
- return pwrpct
- end
- if want=='pwrwpct' then
- return pwrwpct
- end
- if want=='pstate' then
- return pstate
- end
- -- This is here so that $lua_graph can show GPU load over time.
- return gpuutil
- end
- -- 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.
- function conky_gpu_gclock() -- Clock speed percentage
- return gclpct
- end
- function conky_gpu_mclock() -- Memory clock speed percentage
- return mclpct
- end
- function conky_gpu_vram() -- VRAM load percentage
- return vrampct
- end
- function conky_gpu_pwr() -- Power draw percentage
- return pwrpct
- end
Add Comment
Please, Sign In to add comment