Hostmetrics user string (#6850)

This commit is contained in:
Jonathan Bennett
2025-05-20 13:04:05 -05:00
committed by GitHub
parent c70fa0ef13
commit e0f878872f
4 changed files with 16 additions and 7 deletions

View File

@@ -30,11 +30,11 @@ bool HostMetricsModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp,
#ifdef DEBUG_PORT
const char *sender = getSenderShortName(mp);
LOG_INFO("(Received Host Metrics from %s): uptime=%u, diskfree=%lu, memory free=%lu, load=%04.2f, %04.2f, %04.2f", sender,
t->variant.host_metrics.uptime_seconds, t->variant.host_metrics.diskfree1_bytes,
LOG_INFO("(Received Host Metrics from %s): uptime=%u, diskfree=%lu, memory free=%lu, load=%04.2f, %04.2f, %04.2f, %s",
sender, t->variant.host_metrics.uptime_seconds, t->variant.host_metrics.diskfree1_bytes,
t->variant.host_metrics.freemem_bytes, static_cast<float>(t->variant.host_metrics.load1) / 100,
static_cast<float>(t->variant.host_metrics.load5) / 100,
static_cast<float>(t->variant.host_metrics.load15) / 100);
static_cast<float>(t->variant.host_metrics.load15) / 100, t->variant.host_metrics.user_string);
#endif
}
return false; // Let others look at this message also if they want
@@ -107,18 +107,24 @@ meshtastic_Telemetry HostMetricsModule::getHostMetrics()
proc_loadavg.close();
}
}
if (settingsStrings[hostMetrics_user_command] != "") {
std::string userCommandResult = exec(settingsStrings[hostMetrics_user_command].c_str());
if (userCommandResult.length() > 1) {
strncpy(t.variant.host_metrics.user_string, userCommandResult.c_str(), 200);
t.variant.host_metrics.has_user_string = true;
}
}
return t;
}
bool HostMetricsModule::sendMetrics()
{
meshtastic_Telemetry telemetry = getHostMetrics();
LOG_INFO("Send: uptime=%u, diskfree=%lu, memory free=%lu, load=%04.2f, %04.2f, %04.2f",
LOG_INFO("Send: uptime=%u, diskfree=%lu, memory free=%lu, load=%04.2f, %04.2f, %04.2f %s",
telemetry.variant.host_metrics.uptime_seconds, telemetry.variant.host_metrics.diskfree1_bytes,
telemetry.variant.host_metrics.freemem_bytes, static_cast<float>(telemetry.variant.host_metrics.load1) / 100,
static_cast<float>(telemetry.variant.host_metrics.load5) / 100,
static_cast<float>(telemetry.variant.host_metrics.load15) / 100);
static_cast<float>(telemetry.variant.host_metrics.load15) / 100, telemetry.variant.host_metrics.user_string);
meshtastic_MeshPacket *p = allocDataProtobuf(telemetry);
p->to = NODENUM_BROADCAST;