Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create NVIDIA GPU usage/temperature widget #544

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions widget/contrib/nvidia.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--[[

Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2022, tronfy <https://github.com/tronfy>

--]]

local helpers = require("lain.helpers")
local wibox = require("wibox")

-- NVIDIA GPU usage/temperature info (requires nvidia-smi)
-- lain.widget.contrib.nvidia

local function factory(args)
args = args or {}

local nvidia = { widget = args.widget or wibox.widget.textbox() }
local timeout = args.timeout or 5
local exec = args.exec or "nvidia-smi --query-gpu=utilization.gpu,temperature.gpu --format=csv,noheader,nounits"
local format = args.format or "%.1f"
local settings = args.settings or function() end

function nvidia.update()
gpu = {
usage = "N/A",
temp = "N/A"
}

helpers.async(exec, function(f)
-- f -> "usage, temp"
gpu.usage, gpu.temp = f:match("([^,]+),([^,]+)")
gpu.temp = string.format(format, gpu.temp)

widget = nvidia.widget
settings()
end)
end

helpers.newtimer("nvidia-gpu", timeout, nvidia.update)

return nvidia
end

return factory