Skip to content

Instantly share code, notes, and snippets.

@sergejmueller
Last active September 17, 2022 18:19
Show Gist options
  • Save sergejmueller/708db0fd4e96942cac3088a2967a0b97 to your computer and use it in GitHub Desktop.
Save sergejmueller/708db0fd4e96942cac3088a2967a0b97 to your computer and use it in GitHub Desktop.
NVIDIA GPUs Monitoring + Remote Dashboards (for each GPU)

Monitor anytime and anywhere your installed NVIDIA GPUs with permanent sync to dweet.io - a remote public dashboard for each GPU.

Features

  • No setup, no registration, easy to use Batch file
  • List of installed cards with their current properties
  • Display average properties
  • Push the single GPU data to dweet.io (can be disabled by remoteDashboardActive)
  • Auto refresh every 30 seconds (can be changed by refreshInterval)
  • One remote dashboard for each GPU

Properties

  • GPU ID
  • Overclock
  • Power
  • Temp
  • Load

Usage

  1. Download the batch file
  2. Optional: Customize the variable remoteDashboardName (your unique remote desktop name)
  3. Start the batch file

freeboard.io helps to group individual GPU dashboards into a single freeboard board.

@if (@CodeSection == @Batch) @then
@echo off & setlocal enabledelayedexpansion
:: :: CUSTOMIZING AREA START :: ::
:: Remote Dashboard On/Off (1=enabled; 0=disabled)
set remoteDashboardActive=1
:: Remote Dashboard Name (be unique)
set remoteDashboardName=my-test-rig-123456789
:: Refresh Interval in Seconds
set refreshInterval=30
:: Windows styling
mode con cols=70 lines=13
title NVIDIA GPUs Monitor + Remote Dashboard
color 0A
:: :: CUSTOMIZING AREA END :: ::
:: GPU metrics
set metrics[0]=clocks.gr
set metrics[1]=power.draw
set metrics[2]=temperature.gpu
set metrics[3]=utilization.gpu
:: GPU metrics units
set units[clocks.gr]=MHz
set units[power.draw]=W
set units[temperature.gpu]=C
set units[utilization.gpu]=%%
:: Headline columns
set headlines[clocks.gr]=Overclock
set headlines[power.draw]=Power
set headlines[temperature.gpu]=Temp
set headlines[utilization.gpu]=Load
:: GPU metrics units
set totals[clocks.gr]=0
set totals[power.draw]=0
set totals[temperature.gpu]=0
set totals[utilization.gpu]=0
:: Set app path
PATH=%PATH%;"%PROGRAMFILES%\NVIDIA Corporation\NVSMI\"
:: Get GPU count
for /f %%a in ('nvidia-smi --query-gpu^=count --format^=csv,noheader') do @set /a count=%%a
:: Skip if no GPUs
if %count% EQU 0 goto BYE_BYE
:: Define and set lines count
set /a lines=%count%+11
mode con cols=70 lines=%lines%
:MAIN
@cls
setlocal
call :SHOW_HEADER
call :SHOW_GPUS
call :SHOW_AVG
call :SHOW_DWEET_URL
endlocal
timeout /t %refreshInterval% >nul
GOTO :MAiN
:SHOW_HEADER
echo | set /p="GPUID "
for /f "tokens=2 delims==" %%y in ('set headlines[') do echo | set /p="| %%y "
echo.
GOTO :EOF
:SHOW_GPUS
for /l %%X in (1,1,%count%) do call :LOOP_GPUS %%X
echo.
GOTO :EOF
:LOOP_GPUS
set json=
set /a index=%1-1
echo. & echo | set /p="%index% "
for /f "tokens=2 delims==" %%s in ('set metrics[') do call :LOOP_GPU_METRICS %%s
call :SEND_DWEET
GOTO :EOF
:LOOP_GPU_METRICS
set metric=%1
set unit=!units[%metric%]!
set headline=!headlines[%metric%]!
for /f "tokens=1 delims=. " %%b in ('nvidia-smi -i %index% --query-gpu^=%metric% --format^=csv,noheader,nounits') do @set /a result=%%b
set /a totals[%metric%]=!totals[%metric%]!+%result%
set json=%json%'%headline%':'%result%',
echo | set /p="| %result% %unit% "
GOTO :EOF
:SHOW_AVG
for /L %%A in (1,1,42) do <nul set/p =-
echo. & echo | set /p="AVG "
for /f "tokens=2 delims==" %%i in ('set metrics[') do call :LOOP_AVG_METRICS %%i
echo.
GOTO :EOF
:LOOP_AVG_METRICS
set metric=%1
set unit=!units[%metric%]!
set /a total=!totals[%metric%]!/%count%
echo | set /p="| %total% %unit% "
GOTO :EOF
:SEND_DWEET
if %remoteDashboardActive% EQU 0 GOTO :EOF
set thing=%remoteDashboardName%
set json={%json:~0,-1%}
cscript /nologo /e:jscript "%~f0" "%thing%" "%json%" "%index%"
GOTO :EOF
:SHOW_DWEET_URL
if %remoteDashboardActive% EQU 0 GOTO :EOF
echo. && echo Remote Dashboard URLs:
echo https://dweet.io/dweet/for/%remoteDashboardName%-GPUID
GOTO :EOF
:: Bye, bye
:BYE_BYE
echo No GPUs available
pause
GOTO :EOF
endlocal
@end
// Jscript stuff
if ( WScript.Arguments.length === 3 ) {
var x = WSH.CreateObject( "MSXML2.ServerXMLHTTP" );
var thing = WScript.Arguments.Item(0);
var json = WScript.Arguments.Item(1);
var index = WScript.Arguments.Item(2);
var url = 'https://dweet.io/dweet/for/' + thing + '-' + index
json = json.split(" ").join('');
json = json.split("'").join('"');
x.open( "POST", url, false );
x.setRequestHeader( "Content-type", "application/json" );
x.send( json );
while ( x.readyState != 4 ) WSH.Sleep( 50 );
}
WScript.Quit();
@vhocker
Copy link

vhocker commented Mar 1, 2022

Content shows empty bracket in the dweet dashboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment