Push more or different information from a device

maxime louvel

Last Update 2 jaar geleden

How does your device pushes its info ?

When you created/registered your device (see help here if needed), here is what happened:


   1. The installation script was downloaded (curl part of the command) and executed;

   2. All requirements were installed and the push script was downloaded;

   3. The push script (push_device_info.py) was executed.


When the push script was executed, the following happened:


   1. Device information was gathered and formatted ;

   2. Information was sent to the BAG·Tower server via the API ;

   3. The API answered successfully and returned the period at which the device is expected to push its information (e.g. every 10 minutes);

   4. A crontab was created to run the push script periodically (the period can be configured in the device page by clicking on Edit).


Both scripts (installation and push) are stored, on the device, in ~/.bagtower/


The install script can run anytime, it will simply reinstall the push_script to its latest version.

How does the push script work?

By default, the following information are monitored for each device:


   - deviceStatus: device is either UP or DOWN

   - cpu: global percentage of CPU used

   - cpu_per_cpu: percentage of CPU usage, per cpu

   - memory: percentage of RAM used

   - diskusage: percentage of disk used

   - last boot date: raw information containing the last boot date

    - battery_status: battery status: PLUGGED, UNPLUGGED or NO_BATTERY

    - sockets_info: some informations about the sockets on the device


You may find all those information relevant and sufficient for your device ...or you may not.


If you want to remove some information or add new ones, you can extend the push_script.

How to extend the push script?

   1. Copy the script push_device_info.py (installed in ~/.bagtower/push/) to another location to avoid erasing it while reusing the install script.

   2. Modify the generate_device_log function to add a new log item or remove an existing one.


You MUST follow the data model expected by the server when updating the device as detailed here.


The idea is that your device periodically pushes a list (an JSON array) of data. You can push any data you want, as long as it is supported (it uses a valid format). All the data your device pushes are displayed in a dedicated graph in bagtower.app/devices in the devices details view.


For each data item, you can push:


   - a single value. Then, you will have one curve displayed on the graph.

E.g. to push the memory (RAM) usage of your device, you can use something like that :

   -

an array of values. Then, you will have multiple curves displayed on your graph : one curve per value. The legend is 0, 1, 2, ...

E.g. to push CPU usage of all your device's cpus, assuming your device have 4 cpus, use the following sample code. You will see 4 curves: 0, 1, 2, 3.

an object of values. Then you will have one curve per value (same as array), the legend is based on the keys of the object.

E.g. to push some socket information, use the following sample code. In this example you will have 4 curves: nb_established, nb_sockets_closing, nb_sockets_close, nb_sockets_listen.

Was this article helpful?

0 out of 0 liked this article