How to execute command on the host and collect the input


#1

I need to be able to run psutil or top on the host from the container. Currently the commands are limited to a running container.
Main target is to have a container where we can monitor the behavior of the whole os including the containers.

thanks


#2

Specifically for psutils I found the solution on stack overflow https://stackoverflow.com/questions/47072586/docker-access-host-proc
Solution is:

start the container with
balena run -v /:/rootfs:ro -it resin/raspberrypi3-python:3.6 /bin/bash

and in the python code

import psutil
# will list only from the exiting container
psutil.pids()
#will list from all containers
psutil.PROCFS_PATH = '/rootfs/proc'
psutil.pids()

#3

Hey @gancev

Currently I don’t think that there is a way to get access to the /proc host fs currently. Ensuring the container runs privileged is a start, but I don’t think that the /proc directory is mirrored.

What is it you’re trying to achieve with this? Would it be possible to use the supervisor API instead? If not, which features are missing?

Supervisor API: https://www.balena.io/docs/reference/supervisor/supervisor-api/


#4

@CameronDiver, what we try to achieve is to have two separate containers, one that stores the psutil’s data in a CSV file and the other that induces anomaly (memory, cpu, or both). The container that induces anomaly has a named python process that we would like to see in the container that stores psutil’s data. For that matter we mounted the proc host fs through the console of the host device in Balena cloud (as suggested by @gancev above) , however we would like that to be automated. We are aware of the “volumes” field in docker-compose file, however Balena doesn’t allow bind mounts so we are stuck. We have working solution, but doesn’t apply to our use case.
Thank you for your time