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