DEV Community

Jain Wun
Jain Wun

Posted on

Nvtop - 在Linux即時監控GPU使用率


image.png

同時支援Nvidia以及AMD的GPU

Install

Apt



sudo apt update
sudo apt install nvtop


Enter fullscreen mode Exit fullscreen mode

Dockerfile



FROM nvidia/cuda

RUN apt-get update && \
    apt-get install -y cmake libncurses5-dev libncursesw5-dev git && \
    rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/local/cuda-10.1/targets/x86_64-linux/lib/stubs/libnvidia-ml.so /usr/local/lib/libnvidia-ml.so && \
    ln -s /usr/local/cuda-10.1/targets/x86_64-linux/lib/stubs/libnvidia-ml.so /usr/local/lib/libnvidia-ml.so.1 && \
    cd /tmp && \
    git clone https://github.com/Syllo/nvtop.git && \
    mkdir -p nvtop/build && cd nvtop/build && \
    cmake .. && \
    make && \
    make install && \
    cd / && \
    rm -r /tmp/nvtop && \
    rm /usr/local/lib/libnvidia-ml.so && \
    rm /usr/local/lib/libnvidia-ml.so.1

ENTRYPOINT ["/usr/local/bin/nvtop"]


Enter fullscreen mode Exit fullscreen mode

這裡cuda用的是10.2可能得視自身情況修改 (ex: RTX30不支援)

或是可以參考nvtop repo內的Dockerfile

FAQ

  1. ### Unable to Locate Package

Update Source List

有可能是清單內沒有可以下載的網址,比較常發生在debian,可以去source list設定non-free



sudo vim /etc/apt/sources.list


Enter fullscreen mode Exit fullscreen mode

在每行的結尾加上空格與non-free (這個做法不適用於Ubuntu)

Manual Compile

有些OS並沒有提供已經編譯好的套件供安裝,這裡就得自己compile了

撰寫文章時只支援Ubuntu 20.04/ 20.10,而18.04已經裝不了

先裝必要的套件



sudo apt install cmake libncurses5-dev libncursesw5-dev git


Enter fullscreen mode Exit fullscreen mode


git clone https://github.com/Syllo/nvtop.git
mkdir -p nvtop/build && cd nvtop/build
cmake .. -DNVIDIA_SUPPORT=ON -DAMDGPU_SUPPORT=ON
make

# Install globally on the system
sudo make install

# Alternatively, install without privileges at a location of your choosing
# make DESTDIR="/your/install/path" install


Enter fullscreen mode Exit fullscreen mode

Reference

GitHub - Syllo/nvtop: AMD and NVIDIA GPUs htop like monitoring tool

Wrap NVTOP in docker (Impossible to initialize nvidia nvml) · Issue #42 · Syllo/nvtop

nvtop not found in Debian Buster repositories · Issue #46 · Syllo/nvtop

Top comments (0)