Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/webservice/GetStatsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@

#include "common/base/Base.h"
#include "common/stats/StatsManager.h"
#include "common/time/WallClock.h"
#include "webservice/Common.h"

namespace nebula {

// Process start time (auto-recorded via static initialization)
static const int64_t g_processStartTime = nebula::time::WallClock::fastNowInSec();

using nebula::stats::StatsManager;
using proxygen::HTTPMessage;
using proxygen::HTTPMethod;
Expand Down Expand Up @@ -96,14 +100,24 @@ folly::dynamic GetStatsHandler::getStats() const {
if (statNames_.empty()) {
// Read all stats
StatsManager::readAllValue(stats);
// Add process uptime metric to all stats
const int64_t uptimeSeconds = nebula::time::WallClock::fastNowInSec() - g_processStartTime;
addOneStat(stats, "process_uptime_seconds", uptimeSeconds);
} else {
for (auto& sn : statNames_) {
auto status = StatsManager::readValue(sn);
if (status.ok()) {
int64_t statValue = status.value();
addOneStat(stats, sn, statValue);
// Handle process uptime metrics specially
if (sn == "process_uptime_seconds") {
const int64_t uptimeSeconds = nebula::time::WallClock::fastNowInSec() - g_processStartTime;
addOneStat(stats, sn, uptimeSeconds);
} else {
addOneStat(stats, sn, status.status().toString());
// Handle regular metrics
auto status = StatsManager::readValue(sn);
if (status.ok()) {
const int64_t statValue = status.value();
addOneStat(stats, sn, statValue);
} else {
addOneStat(stats, sn, status.status().toString());
}
}
}
}
Expand Down