fix: calc latency when fetching node infos
This commit is contained in:
@@ -83,11 +83,14 @@ void ClusterManager::fetchNodeInfo(const IPAddress& ip) {
|
||||
Serial.println("[Cluster] Skipping fetch for local node");
|
||||
return;
|
||||
}
|
||||
unsigned long requestStart = millis();
|
||||
HTTPClient http;
|
||||
WiFiClient client;
|
||||
String url = "http://" + ip.toString() + ClusterProtocol::API_NODE_STATUS;
|
||||
http.begin(client, url);
|
||||
int httpCode = http.GET();
|
||||
unsigned long requestEnd = millis();
|
||||
unsigned long requestDuration = requestEnd - requestStart;
|
||||
if (httpCode == 200) {
|
||||
String payload = http.getString();
|
||||
JsonDocument doc;
|
||||
@@ -104,6 +107,7 @@ void ClusterManager::fetchNodeInfo(const IPAddress& ip) {
|
||||
node.resources.cpuFreqMHz = doc["cpuFreqMHz"];
|
||||
node.resources.flashChipSize = doc["flashChipSize"];
|
||||
node.status = NodeInfo::ACTIVE;
|
||||
node.latency = requestDuration;
|
||||
node.lastSeen = millis();
|
||||
node.apiEndpoints.clear();
|
||||
if (doc["api"].is<JsonArray>()) {
|
||||
@@ -153,7 +157,6 @@ void ClusterManager::updateAllNodeStatuses() {
|
||||
for (auto& pair : memberList) {
|
||||
NodeInfo& node = pair.second;
|
||||
updateNodeStatus(node, now, ctx.config.node_inactive_threshold_ms, ctx.config.node_dead_threshold_ms);
|
||||
node.latency = now - node.lastSeen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user