rbonghi / jetson_stats

📊 Simple package for monitoring and control your NVIDIA Jetson [Orin, Xavier, Nano, TX] series
https://rnext.it/jetson_stats
GNU Affero General Public License v3.0
2.14k stars 261 forks source link

Use jtop in python script inside docker container failling #80

Closed assafzam closed 3 years ago

assafzam commented 4 years ago

Hi,

I've installed jetson-stats successfully inside a docker container via:

root@office:/var/remote-python# sudo -H pip install -U jetson-stats

and than run the exapmle from your docs:

root@office:/var/remote-python# python

Python 3.6.12 (default, Sep  1 2020, 14:19:07)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.`

>>> from jtop import jtop
>>> with jtop() as jetson:
...     # jetson.ok() will provide the proper update frequency
...     while jetson.ok():
...         # Read tegra stats
...         print(jetson.stats)

And got:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/jtop/jtop.py", line 927, in start
    self._broadcaster.connect()
  File "/usr/local/lib/python3.6/multiprocessing/managers.py", line 489, in connect
    conn = Client(self._address, authkey=self._authkey)
  File "/usr/local/lib/python3.6/multiprocessing/connection.py", line 487, in Client
    c = SocketClient(address)
  File "/usr/local/lib/python3.6/multiprocessing/connection.py", line 614, in SocketClient
    s.connect(address)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/jtop/jtop.py", line 1081, in __enter__
    self.start()
  File "/usr/local/lib/python3.6/site-packages/jtop/jtop.py", line 930, in start
    raise JtopException("The jetson_stats.service is not active. Please run:\nsudo systemctl restart jetson_stats.service")
jtop.core.exceptions.JtopException: The jetson_stats.service is not active. Please run:
sudo systemctl restart jetson_stats.service

what can I do to fix it? (cannot run 'sudo systemctl restart jetson_stats.service' inside the container in automation pipeline)


this is the docker build coomand:

build --platform=linux/arm64 -t $(registryUrl)/$(ProjectNamespace)/$(baseProjectName):$(Build.BuildNumber).arm64 --load --build-arg INDEX_URL=$(artifactUrl) -f  python/Dockerfile-base python/

the Dockerfile:

FROM arm64v8/python:3.6-buster

RUN apt-get update && apt-get install -y \
    sshpass \
    git \
    sudo \
    build-essential

ADD setup.py /var/remote-python/
WORKDIR /var/remote-python/

RUN pip install -r ./requirements.txt

RUN sudo -H pip install -U jetson-stats
rbonghi commented 4 years ago

I test your docker and the build works, remember when you run your container to add the volume: /run/jtop.sock:/run/jtop.sock

like this example: docker run --rm -it -v /run/jtop.sock:/run/jtop.sock rbonghi/jetson-stats

This Dockerfile works fine for me:

FROM arm64v8/python:3-buster
RUN pip install -U jetson-stats

Hints:

Other hints are here: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

assafzam commented 4 years ago

@rbonghi great! Thanks

rbonghi commented 2 years ago

I'm updating the readme and making a demo docker to test jtop