metisvela / sailtrack-core

Central component of the SailTrack system, it manages connections and gathers data.
GNU General Public License v3.0
12 stars 0 forks source link

Add status script #4

Closed matteocarnelos closed 3 years ago

matteocarnelos commented 3 years ago

The script periodically publishes an MQTT message containing the following statistics:

The MQTT message format is the following:

{
  "measurement": String,
  "battery": {
    "voltage": Float,
    "capacity": Float,
    "charging": Boolean
  },
  "cpu": {
    "temperature": Float,
    "load": Float
  },
  "disk": {
    "usage": Float
  }
}

The publish and log rates are configurable through the /etc/sailtrack/sailtrackd.conf file.

matteocarnelos commented 3 years ago

Yes, I understand what you mean. In the first version of the script I was logging every published message with its content, but, since systemd saves every message log on the system journal I soon realized that logging every published message doubles the memory impact of the script (every message is saved both in the database and in the journal).

So, I decided to log only the published messages because, if the publishing mechanism works, then the message content can be checked in the broker.

Anyway, to be on the safe side, we can log the last sent message at log_rate, so to not overwhelm the memory and still get the content of the messages at the source.

Ps: This script has a very low publish rate (0.1/sec), all this reasoning was done thinking at scripts with high rates (like 10/sec or more).