mqtt: log mosquitto_publish() failures with rate-limited cerr
Publish failures (invalid topic, offline broker, queue full) were silent because the rc was discarded. At production volume a naive log floods on any flap, so emit on first failure + error-code change, then suppress for 60s and include the suppressed count on the next line.
This commit is contained in:
1 parent
bd196d6365
commit
bc02c8c6d8
2 files changed
+37
-3
No files matched your search
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include <json/json.h>
|
||||
#include "ReflectorMsg.h"
|
||||
@@ -61,6 +62,10 @@ class MqttPublisher
|
||||
std::string m_tls_client_cert;
|
||||
std::string m_tls_client_key;
|
||||
|
||||
int m_last_pub_err_code = 0;
|
||||
time_t m_last_pub_err_logged = 0;
|
||||
uint64_t m_pub_err_suppressed = 0;
|
||||
|
||||
void publish(const std::string& topic_suffix, const std::string& payload,
|
||||
bool retain = false);
|
||||
|
||||
|
||||
Reference in new issue
Block a user