feat(mqtt): add SNMP support for radio diagnostics and stats
Implement SNMP functionality in MyMesh to provide radio diagnostics and statistics updates. This includes a new method for formatting radio diagnostic replies and periodic updates to the SNMP agent with radio stats, enhancing monitoring capabilities for users with SNMP enabled.
This commit is contained in:
1 parent
bd58d8af5b
commit
fbe608d6c0
6 files changed
+56
No files matched your search
@@ -1176,6 +1176,10 @@ void MyMesh::formatRadioStatsReply(char *reply) {
|
||||
StatsFormatHelper::formatRadioStats(reply, _radio, radio_driver, getTotalAirTime(), getReceiveAirTime());
|
||||
}
|
||||
|
||||
void MyMesh::formatRadioDiagReply(char *reply) {
|
||||
StatsFormatHelper::formatRadioDiag(reply, _radio, radio_driver, *_ms, _err_flags, hasOutbound());
|
||||
}
|
||||
|
||||
void MyMesh::formatPacketStatsReply(char *reply) {
|
||||
StatsFormatHelper::formatPacketStats(reply, radio_driver, getNumSentFlood(), getNumSentDirect(),
|
||||
getNumRecvFlood(), getNumRecvDirect());
|
||||
@@ -1587,6 +1591,25 @@ void MyMesh::loop() {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SNMP
|
||||
// Push radio stats to SNMP agent every 2 seconds
|
||||
if (_snmp_agent.isRunning()) {
|
||||
static unsigned long last_snmp_stats = 0;
|
||||
if (now - last_snmp_stats >= 2000) {
|
||||
last_snmp_stats = now;
|
||||
_snmp_agent.updateRadioStats(
|
||||
radio_driver.getPacketsRecv(), radio_driver.getPacketsSent(),
|
||||
radio_driver.getPacketsRecvErrors(),
|
||||
(int16_t)_radio->getNoiseFloor(),
|
||||
(int16_t)radio_driver.getLastRSSI(),
|
||||
(int16_t)(radio_driver.getLastSNR() * 4),
|
||||
getNumSentFlood(), getNumSentDirect(),
|
||||
getNumRecvFlood(), getNumRecvDirect(),
|
||||
getTotalAirTime() / 1000, uptime_millis / 1000);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(WITH_MQTT_NEIGHBORS)
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
#include "helpers/esp32/WebConfigServer.h" // defines WITH_WEBCONFIG on ESP32
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SNMP
|
||||
#include "helpers/SNMPAgent.h"
|
||||
#endif
|
||||
|
||||
/* ------------------------------ Config -------------------------------- */
|
||||
|
||||
#ifndef FIRMWARE_BUILD_DATE
|
||||
@@ -176,6 +180,9 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
MQTTBridge* bridge;
|
||||
#endif
|
||||
#ifdef WITH_SNMP
|
||||
MeshSNMPAgent _snmp_agent;
|
||||
#endif
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
AlertReporter _alerter;
|
||||
#endif
|
||||
@@ -290,6 +297,7 @@ public:
|
||||
void removeNeighbor(const uint8_t* pubkey, int key_len) override;
|
||||
void formatStatsReply(char *reply) override;
|
||||
void formatRadioStatsReply(char *reply) override;
|
||||
void formatRadioDiagReply(char *reply) override;
|
||||
void formatPacketStatsReply(char *reply) override;
|
||||
void startRegionsLoad() override;
|
||||
bool saveRegions() override;
|
||||
@@ -324,6 +332,13 @@ public:
|
||||
bridge->setBuildDate(getBuildDate());
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
bridge->setStatsSources(this, _radio, _cli.getBoard(), _ms);
|
||||
#ifdef WITH_SNMP
|
||||
if (_cli.getObserverPrefs()->snmp_enabled) {
|
||||
_snmp_agent.setNodeName(_prefs.node_name);
|
||||
_snmp_agent.setFirmwareVersion(getFirmwareVer());
|
||||
bridge->setSNMPAgent(&_snmp_agent);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
bridge->begin();
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
|
||||
Reference in new issue
Block a user