From 6e1d8809e723f6836630eb7f7ea2c9089c5eaa49 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Fri, 5 Jan 2024 16:39:22 +0100 Subject: [PATCH] Feature: add heap details to system info and prometheus this change adds the values of ESP.gteMaxAllocHeap() and ESP.getMinFreeHead() to the prometheus metrics and the system information object. the web UI uses these values to diplay the size of the largest free contiguous block, calculate a rough estimate for the level of fragmentation, and the maximum usage of heap memory since boot in absolute and relative amounts. --- src/WebApi_prometheus.cpp | 8 ++++ src/WebApi_sysstatus.cpp | 2 + webapp/src/components/HeapDetails.vue | 55 +++++++++++++++++++++++++++ webapp/src/locales/de.json | 7 ++++ webapp/src/locales/en.json | 7 ++++ webapp/src/locales/fr.json | 7 ++++ webapp/src/types/SystemStatus.ts | 2 + webapp/src/views/SystemInfoView.vue | 4 ++ 8 files changed, 92 insertions(+) create mode 100644 webapp/src/components/HeapDetails.vue diff --git a/src/WebApi_prometheus.cpp b/src/WebApi_prometheus.cpp index 0f46c97f3..b2e566545 100644 --- a/src/WebApi_prometheus.cpp +++ b/src/WebApi_prometheus.cpp @@ -54,6 +54,14 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques stream->print("# TYPE opendtu_free_heap_size gauge\n"); stream->printf("opendtu_free_heap_size %zu\n", ESP.getFreeHeap()); + stream->print("# HELP opendtu_biggest_heap_block Biggest free heap block\n"); + stream->print("# TYPE opendtu_biggest_heap_block gauge\n"); + stream->printf("opendtu_biggest_heap_block %zu\n", ESP.getMaxAllocHeap()); + + stream->print("# HELP opendtu_heap_min_free Minimum free memory since boot\n"); + stream->print("# TYPE opendtu_heap_min_free gauge\n"); + stream->printf("opendtu_heap_min_free %zu\n", ESP.getMinFreeHeap()); + stream->print("# HELP wifi_rssi WiFi RSSI\n"); stream->print("# TYPE wifi_rssi gauge\n"); stream->printf("wifi_rssi %d\n", WiFi.RSSI()); diff --git a/src/WebApi_sysstatus.cpp b/src/WebApi_sysstatus.cpp index 85324f08f..ffd032593 100644 --- a/src/WebApi_sysstatus.cpp +++ b/src/WebApi_sysstatus.cpp @@ -49,6 +49,8 @@ void WebApiSysstatusClass::onSystemStatus(AsyncWebServerRequest* request) root["heap_total"] = ESP.getHeapSize(); root["heap_used"] = ESP.getHeapSize() - ESP.getFreeHeap(); + root["heap_max_block"] = ESP.getMaxAllocHeap(); + root["heap_min_free"] = ESP.getMinFreeHeap(); root["sketch_total"] = ESP.getFreeSketchSpace(); root["sketch_used"] = ESP.getSketchSize(); root["littlefs_total"] = LittleFS.totalBytes(); diff --git a/webapp/src/components/HeapDetails.vue b/webapp/src/components/HeapDetails.vue new file mode 100644 index 000000000..04c589319 --- /dev/null +++ b/webapp/src/components/HeapDetails.vue @@ -0,0 +1,55 @@ + + + diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index ac0714002..054c6928c 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -248,6 +248,13 @@ "LittleFs": "LittleFs", "Sketch": "Sketch" }, + "heapdetails": { + "HeapDetails": "Detailinformationen zum Heap", + "TotalFree": "Insgesamt frei", + "LargestFreeBlock": "Größter zusammenhängender freier Block", + "MaxUsage": "Maximale Speichernutzung seit Start", + "Fragmentation": "Grad der Fragmentierung" + }, "radioinfo": { "RadioInformation": "Funkmodulinformationen", "Status": "{module} Status", diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index c819fea44..a5abe2d5a 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -249,6 +249,13 @@ "LittleFs": "LittleFs", "Sketch": "Sketch" }, + "heapdetails": { + "HeapDetails": "Heap Details", + "TotalFree": "Total free", + "LargestFreeBlock": "Biggest contiguous free block", + "MaxUsage": "Maximum usage since start", + "Fragmentation": "Level of fragmentation" + }, "radioinfo": { "RadioInformation": "Radio Information", "Status": "{module} Status", diff --git a/webapp/src/locales/fr.json b/webapp/src/locales/fr.json index 8f1e88efa..b9f11d965 100644 --- a/webapp/src/locales/fr.json +++ b/webapp/src/locales/fr.json @@ -248,6 +248,13 @@ "LittleFs": "LittleFs", "Sketch": "Sketch" }, + "heapdetails": { + "HeapDetails": "Heap Details", + "TotalFree": "Total free", + "LargestFreeBlock": "Biggest contiguous free block", + "MaxUsage": "Maximum usage since start", + "Fragmentation": "Level of fragmentation" + }, "radioinfo": { "RadioInformation": "Informations sur la radio", "Status": "{module} Statut", diff --git a/webapp/src/types/SystemStatus.ts b/webapp/src/types/SystemStatus.ts index 4c5578581..22c382976 100644 --- a/webapp/src/types/SystemStatus.ts +++ b/webapp/src/types/SystemStatus.ts @@ -22,6 +22,8 @@ export interface SystemStatus { // MemoryInfo heap_total: number; heap_used: number; + heap_max_block: number; + heap_min_free: number; littlefs_total: number; littlefs_used: number; sketch_total: number; diff --git a/webapp/src/views/SystemInfoView.vue b/webapp/src/views/SystemInfoView.vue index 15b02af00..f9e5388d9 100644 --- a/webapp/src/views/SystemInfoView.vue +++ b/webapp/src/views/SystemInfoView.vue @@ -6,6 +6,8 @@
+ +
@@ -16,6 +18,7 @@ import BasePage from '@/components/BasePage.vue'; import FirmwareInfo from "@/components/FirmwareInfo.vue"; import HardwareInfo from "@/components/HardwareInfo.vue"; import MemoryInfo from "@/components/MemoryInfo.vue"; +import HeapDetails from "@/components/HeapDetails.vue"; import RadioInfo from "@/components/RadioInfo.vue"; import type { SystemStatus } from '@/types/SystemStatus'; import { authHeader, handleResponse } from '@/utils/authentication'; @@ -27,6 +30,7 @@ export default defineComponent({ FirmwareInfo, HardwareInfo, MemoryInfo, + HeapDetails, RadioInfo, }, data() {