🎐 Makes Analytics service use system service for metrics
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
#include <filesystem.h>
|
||||
#include <event_socket.h>
|
||||
#include <task_manager.h>
|
||||
#include <system_service.h>
|
||||
#include <WiFi.h>
|
||||
#include <timing.h>
|
||||
|
||||
@@ -24,26 +24,8 @@ class AnalyticsService {
|
||||
void updateAnalytics() {
|
||||
if (!socket.hasSubscribers(EVENT_ANALYTICS)) return;
|
||||
doc.clear();
|
||||
doc["uptime"] = millis() / 1000;
|
||||
doc["free_heap"] = ESP.getFreeHeap();
|
||||
doc["total_heap"] = ESP.getHeapSize();
|
||||
doc["min_free_heap"] = ESP.getMinFreeHeap();
|
||||
doc["max_alloc_heap"] = ESP.getMaxAllocHeap();
|
||||
doc["fs_used"] = ESPFS.usedBytes();
|
||||
doc["fs_total"] = ESPFS.totalBytes();
|
||||
doc["core_temp"] = temperatureRead();
|
||||
doc["cpu0_usage"] = g_taskManager.getCpuUsage(0);
|
||||
doc["cpu1_usage"] = g_taskManager.getCpuUsage(1);
|
||||
doc["cpu_usage"] = g_taskManager.getCpuUsage();
|
||||
JsonArray tasks = doc["tasks"].to<JsonArray>();
|
||||
for (auto const &task : g_taskManager.getTasks()) {
|
||||
JsonObject nested = tasks.add<JsonObject>();
|
||||
nested["name"] = task.name;
|
||||
nested["stackSize"] = task.stackSize;
|
||||
nested["priority"] = task.priority;
|
||||
nested["coreId"] = task.coreId;
|
||||
}
|
||||
|
||||
JsonObject root = doc.to<JsonObject>();
|
||||
system_service::metrics(root);
|
||||
serializeJson(doc, message);
|
||||
socket.emit(EVENT_ANALYTICS, message);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,17 @@ void metrics(JsonObject &root) {
|
||||
root["fs_used"] = ESPFS.usedBytes();
|
||||
root["fs_total"] = ESPFS.totalBytes();
|
||||
root["core_temp"] = temperatureRead();
|
||||
root["cpu0_usage"] = g_taskManager.getCpuUsage(0);
|
||||
root["cpu1_usage"] = g_taskManager.getCpuUsage(1);
|
||||
root["cpu_usage"] = g_taskManager.getCpuUsage();
|
||||
JsonArray tasks = root["tasks"].to<JsonArray>();
|
||||
for (auto const &task : g_taskManager.getTasks()) {
|
||||
JsonObject nested = tasks.add<JsonObject>();
|
||||
nested["name"] = task.name;
|
||||
nested["stackSize"] = task.stackSize;
|
||||
nested["priority"] = task.priority;
|
||||
nested["coreId"] = task.coreId;
|
||||
}
|
||||
}
|
||||
|
||||
const char *resetReason(int reason) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifndef SYSTEM_SERVICE_H
|
||||
#define SYSTEM_SERVICE_H
|
||||
|
||||
#include <filesystem.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <PsychicHttp.h>
|
||||
#include <WiFi.h>
|
||||
#include <task_manager.h>
|
||||
#include <filesystem.h>
|
||||
#include <global.h>
|
||||
|
||||
namespace system_service {
|
||||
|
||||
Reference in New Issue
Block a user