Accessing RPI metrics from supervisor

Hello forum,

I realise my question is probably explained and answered in the documentation I list below, but being an absolute newbie with anything linux and Balena. I’ve spent most of the day trying to piece this together but I’ve made no progress.

I have a RPI 4 running on balena cloud and I run a simple nodejs script on it which connects to a mysql database, sending its ID (defined as a device variable on balena dashboard) with a timestamp to the database. The idea is to use these heartbeat checkins as a type of watchdog.

I’ve been looking at the metrics which are displayed in the top right of the dashboard and I would love to access and also send this info to the database. This is cpu usage and temp, disk and memory usage.

I found these links explaining how to access this data, but I’ve not been able to piece it together. In my NodeJS script I use a simple expression process.env.ID to grab the variable I mentioned, but how do I get hold of the device metrics?

This link tells me to use the NodeJS SDK, I assume, since I’m running a NodeJS script in my balena container: Device Metrics - Balena Documentation

This link explains how to do this: Balena Node.js SDK - Balena Documentation

The example code supplied:
balena.models.device.getMetrics('7cf02a6').then(function(deviceMetrics) { console.log(deviceMetrics); });

What do I do with this? I’m embarrassed to even say this, but when running it in node it clearly doesn’t work.

Also, it seems like the UUID is needed to get this working, how do I go about getting the UUID from the NodeJS script?

Any guidance would be much appreciated.

Hi @heinburgh can you please share any error logs which you receive when you try to run this code? You can find the UUID of your device by going to your Dashboard and viewing your device summary. Place it as the string in the getMetrics function. Does this return anything?