1

I have Ubuntu, I am using the i3 window manager and want to display GPU temperature in the i3-statusbar.

What should I do?

1 Answers1

0

There is a possibility to run external commands and put their output in status bar, using wrapper. Original wrapper was written on Pearl, here I am providing Python example from https://github.com/i3/i3status/blob/main/contrib/wrapper.py

Code for NVIDIA GPU temp I took from How to see the Video Card Temperature (Nvidia, ATI, Intel...)

import sys
import json
import subprocess

def get_gpu_temp(): # https://askubuntu.com/questions/34449/how-to-see-the-video-card-temperature-nvidia-ati-intel cmd = 'nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader' return subprocess.check_output(cmd, shell=True, text=True).strip()

def print_line(message): """ Non-buffered printing to stdout. """ sys.stdout.write(message + '\n') sys.stdout.flush()

def read_line(): """ Interrupted respecting reader for stdin. """ # try reading a line, removing any extra whitespace try: line = sys.stdin.readline().strip() # i3status sends EOF, or an empty line if not line: sys.exit(3) return line # exit on ctrl-c except KeyboardInterrupt: sys.exit()

if name == 'main': # Skip the first line which contains the version header. print_line(read_line())

# The second line contains the start of the infinite array.
print_line(read_line())

while True:
    line, prefix = read_line(), ''
    # ignore comma at start of lines
    if line.startswith(','):
        line, prefix = line[1:], ','

    j = json.loads(line)

    # GPU
    x = get_gpu_temp()
    # \u00b0 -- degree sign
    data = {'full_text': f'GPU {x}\u00b0C',
            'name': 'GPU',
            # make it red on the limit of 47 degrees
            'color': "#FF0000" if int(x) > 47 else ""}
    j.append(x)

    # and echo back new encoded json
    print_line(prefix + json.dumps(j))

Next, you need to add some code in i3 config file, to use at automatically on startup:

bar {
    status_command i3status -c ~/.config/i3/i3status.conf | ~/.config/i3/wrapper.py
}

NB: i3status must provide output in i3bar format, add next section in i3status.conf:

general {
        colors = "true"
        interval = 2
        color_degraded = "#FF0000"
        # this line 
        output_format = "i3bar"
}