Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add heap details to system info and prometheus #595

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/WebApi_prometheus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/WebApi_sysstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
55 changes: 55 additions & 0 deletions webapp/src/components/HeapDetails.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<template>
<CardElement :text="$t('heapdetails.HeapDetails')" textVariant="text-bg-primary">
<div class="table-responsive">
<table class="table table-hover table-condensed">
<tbody>
<tr>
<th>{{ $t('heapdetails.TotalFree') }}</th>
<td>{{ $n(Math.round(getFreeHeap() / 1024), 'kilobyte') }}</td>
</tr>
<tr>
<th>{{ $t('heapdetails.LargestFreeBlock') }}</th>
<td>{{ $n(Math.round(systemStatus.heap_max_block / 1024), 'kilobyte') }}</td>
</tr>
<tr>
<th>{{ $t('heapdetails.Fragmentation') }}</th>
<td>{{ $n(getFragmentation(), 'percent') }}</td>
</tr>
<tr>
<th>{{ $t('heapdetails.MaxUsage') }}</th>
<td>{{ $n(Math.round(getMaxUsageAbs() / 1024), 'kilobyte') }} ({{ $n(getMaxUsageRel(), 'percent') }})</td>
</tr>
</tbody>
</table>
</div>
</CardElement>
</template>

<script lang="ts">
import CardElement from '@/components/CardElement.vue';
import type { SystemStatus } from '@/types/SystemStatus';
import { defineComponent, type PropType } from 'vue';

export default defineComponent({
components: {
CardElement,
},
props: {
systemStatus: { type: Object as PropType<SystemStatus>, required: true },
},
methods: {
getFreeHeap() {
return this.systemStatus.heap_total - this.systemStatus.heap_used;
},
getMaxUsageAbs() {
return this.systemStatus.heap_total - this.systemStatus.heap_min_free;
},
getMaxUsageRel() {
return this.getMaxUsageAbs() / this.systemStatus.heap_total;
},
getFragmentation() {
return 1 - (this.systemStatus.heap_max_block / this.getFreeHeap());
},
},
});
</script>
7 changes: 7 additions & 0 deletions webapp/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/types/SystemStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/views/SystemInfoView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<div class="mt-5"></div>
<MemoryInfo :systemStatus="systemDataList" />
<div class="mt-5"></div>
<HeapDetails :systemStatus="systemDataList" />
<div class="mt-5"></div>
<RadioInfo :systemStatus="systemDataList" />
<div class="mt-5"></div>
</BasePage>
Expand All @@ -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';
Expand All @@ -27,6 +30,7 @@ export default defineComponent({
FirmwareInfo,
HardwareInfo,
MemoryInfo,
HeapDetails,
RadioInfo,
},
data() {
Expand Down