Skip to content

Commit

Permalink
wsd: dump the Prometheus metrics with USR1
Browse files Browse the repository at this point in the history
Change-Id: I51a2dd80bca4aa33a2829f7e8baf87034a654f61
Signed-off-by: Ashod Nakashian <[email protected]>
  • Loading branch information
Ashod committed Oct 8, 2024
1 parent 883fb0f commit 7974f9f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions wsd/Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <chrono>
#include <iomanip>
#include <sstream>
#include <string>
#include <sys/poll.h>
#include <unistd.h>
Expand Down Expand Up @@ -695,6 +696,17 @@ void Admin::pollingThread()
}
}

bool dumpMetrics = true;
if (_dumpMetrics.compare_exchange_strong(dumpMetrics, false))
{
std::ostringstream oss;
oss << "Admin Metrics:\n";
getMetrics(oss);
const std::string str = oss.str();
fprintf(stderr, "%s\n", str.c_str());
LOG_TRC(str);
}

// Handle websockets & other work.
const auto timeout = std::chrono::milliseconds(capAndRoundInterval(
std::min(std::min(std::min(cpuWait, memWait), netWait), cleanupWait)));
Expand Down
6 changes: 6 additions & 0 deletions wsd/Admin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class Admin : public SocketPoll

void getMetrics(std::ostringstream &metrics);

/// Will dump the metrics in the log and stderr from the Admin SocketPoll.
static void dumpMetrics() { instance()._dumpMetrics = true; }

// delete entry from _monitorSocket map
void deleteMonitorSocket(const std::string &uriWithoutParam);

Expand Down Expand Up @@ -226,6 +229,9 @@ class Admin : public SocketPoll
uint64_t _lastRecvCount;
std::string _forkitLogLevel;

/// When set, the metrics will be dumped into the log and stderr.
std::atomic_bool _dumpMetrics;

struct MonitorConnectRecord
{
void setWhen(std::chrono::steady_clock::time_point when) { _when = when; }
Expand Down
4 changes: 4 additions & 0 deletions wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4960,6 +4960,10 @@ void dump_state()
const std::string msg = oss.str();
fprintf(stderr, "%s\n", msg.c_str());
LOG_TRC(msg);

#if !MOBILEAPP
Admin::dumpMetrics();
#endif
}

void lslr_childroot()
Expand Down

0 comments on commit 7974f9f

Please sign in to comment.