Fleet statistics over API

In the UI you can get a breakdown of how many devices are in the various states on a per-fleet basis. However, as far as I can tell, there is no way to get this data over the API.

What we’d like to write is a Prometheus Exporter that pulls this data on a per-fleet basis so that we can visualize this data over time.

1 Like

Hello @vpetersson everything that appears on the balenaCloud dashboard might be available through API.

Did you check this? Resources - Balena Documentation

BTW did you check this? Monitoring the edge with Prometheus pt. 1

or this block? GitHub - DynamicDevices/prometheus-exporter: Balena Block providing 'node-exporter' metrics for a device/app to Prometheus

Finally there is this feature request on the balena roadmap → Provide fleet metrics · Balena Roadmap

Feel free to add here your ideas @vpetersson :slight_smile:

@mpous Thanks. The previous ones are for device perfomance metrics. I don’t really need that. What we need is metrics on the actual fleets.

The Provide fleet metrics · Balena Roadmap link is more like it but what I need is a lot more basic. There’s already an end-point for Getting Fleet by ID, which yields something like this:

> $  curl -s -X GET \                                                                                                                                                                                                                "https://api.balena-cloud.com/v6/application(xxx)" \
-H  "Content-Type: application/json"  \
-H "Authorization: Bearer [redacted]" | jq
  "d": [
      "id": [redacted],
      "organization": {
        "__id": [redacted],
        "__deferred": {
          "uri": "/v6/organization(@id)?@id=[redacted]"
      "actor": [redacted],
      "app_name": "anthias-pi3",
      "slug": "screenly_ose/anthias-pi3",
      "should_be_running__release": {
        "__id": [redacted],
        "__deferred": {
          "uri": "/v6/release(@id)?@id=[redacted]"
      "application_type": {
        "__id": 5,
        "__deferred": {
          "uri": "/v6/application_type(@id)?@id=5"
      "is_for__device_type": {
        "__id": 58,
        "__deferred": {
          "uri": "/v6/device_type(@id)?@id=58"
      "should_track_latest_release": true,
      "is_accessible_by_support_until__date": null,
      "is_public": true,
      "is_host": false,
      "is_archived": false,
      "is_discoverable": true,
      "is_stored_at__repository_url": "https://github.com/Screenly/Anthias",
      "created_at": "2022-09-28T14:49:27.848Z",
      "uuid": "[redacted]",
      "is_of__class": "fleet",
      "__metadata": {
        "uri": "/v6/application(@id)?@id=[redacted]"

If this API call could be extended to also include fleet information (e.g. the count of each device in the following states Online|Config|Updating|Offline|Post prov|Inactive, it would be trivial to write a Prometheus Exporter for this.

Also, we’d happily open source this exporter.

1 Like

@vpetersson feel free to add this on the https://roadmap.balena.io so we can internally analyze it :slight_smile:

Done: Fleet Statistics over API · Balena Roadmap

BTW @vpetersson find here an example (thanks @fisehara ) of how you can get the online devices from a fleet with this query.

api.balena-cloud.com/v6/application(id)?$expand=owns__device/$count($filter=is_online eq true)

let us know if you can proceed from here!

Nice! Can you provide a link to more documentation on this or is it undocumented?

Work in progress, but here’s the alpha version:

1 Like

Thank you for sharing @vpetersson i will try to test myself!

Did the query worked for you?

Yes. It’s not perfect, but gets the job done for now. I’ve had it running for almost two weeks now without issues.

1 Like