Get hardware metrics inside the container

Hi,
Is there a way to get BALENA_SUPERVISOR_HARDWARE_METRICS from inside the container?
Thank you!

Hi,

BALENA_SUPERVISOR_HARDWARE_METRICS is a boolean environment variable. Are you checking whether you can find if it’s turned on/off from in a container? If so, you could try using a balenaAPI call:

curl -H "Authorization: Bearer $BALENA_API_KEY" "https://api.balena-cloud.com/v6/device_config_variable(device=$(cat /mnt/boot/config.json | jq -r '.deviceId'),name='BALENA_SUPERVISOR_HARDWARE_METRICS')" | jq .

This requires the jq package inside the container if you are making the API call from the command line using the command above. You’d also need the io.balena.features.balena-api docker label so you have access to the BALENA_API_KEY container env var. See docker-compose.yml fields - Balena Documentation for more information.

Let us know if this works for you!

Regards,
Christina

Alternatively, if this doesn’t answer the question you were asking, could you clarify what you’re trying to do with this variable?

Hi Christina,

In fact I want to read the processor usage, memory usage and the temperature. Sorry for my poor choice of words.

Andrei

Hi,

Thanks for clarifying! In that case, you can make the following request to the balena API:

curl -H "Authorization: Bearer $BALENA_API_KEY" "https://api.balena-cloud.com/v6/device?\$filter=startswith(uuid,'$BALENA_DEVICE_UUID')"

This also requires the io.balena.features.balena-api label in your service’s docker-compose.yml. In the response, the fields cpu_id, cpu_temp, memory_usage, memory_total, storage_block_device, storage_usage, storage_total, cpu_usage, and is_undervolted all currently fall into the category of device hardware metrics. You may modify the curl command above to only select the fields you’re interested in. For example, if you wish to only select processor usage, memory usage, and temperature as indicated in your response, you can achieve this via the following:

curl -H "Authorization: Bearer $BALENA_API_KEY" "https://api.balena-cloud.com/v6/device?\$filter=startswith(uuid,'$BALENA_DEVICE_UUID')&\$select=cpu_usage,memory_usage,memory_total,cpu_temp"

Note that both memory_usage and memory_total need to be selected to calculate percentage memory. cpu_usage is always reported as a percent value though.

As a side note, we are planning on adding a metrics reporting endpoint to the Supervisor. This will save you a network call in the future since you can just query the Supervisor API, available locally. You can follow this issue to get notified when this Supervisor feature becomes available: User would like the supervisor API to report CPU load and temperature · Issue #1710 · balena-os/balena-supervisor · GitHub

Let us know if this answers your question!

Regards,
Christina

2 Likes

thank you, that works for me