mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-27 19:57:38 +00:00
[Metrics] Add network traffic data TX/RX bytes and frames (Prometheus)
This commit is contained in:
@@ -5,6 +5,16 @@
|
||||
|
||||
#ifdef WEBSERVER_METRICS
|
||||
|
||||
# if FEATURE_NETWORK_STATS
|
||||
# ifdef ESP8266
|
||||
# define MAX_NR_NETWORKS_IN_TABLE 2
|
||||
# endif
|
||||
# ifdef ESP32
|
||||
# define MAX_NR_NETWORKS_IN_TABLE NETWORK_MAX
|
||||
# endif
|
||||
|
||||
# endif // if FEATURE_NETWORK_STATS
|
||||
|
||||
# ifdef ESP32
|
||||
# include <esp_partition.h>
|
||||
# endif // ifdef ESP32
|
||||
@@ -77,6 +87,52 @@ void handle_metrics() {
|
||||
addHtml(getValue(LabelType::NUMBER_RECONNECTS));
|
||||
addHtml('\n');
|
||||
|
||||
# if FEATURE_NETWORK_STATS
|
||||
|
||||
for (ESPEasy::net::networkIndex_t x = 0; x < MAX_NR_NETWORKS_IN_TABLE; x++)
|
||||
{
|
||||
const ESPEasy::net::nwpluginID_t nwpluginID = Settings.getNWPluginID_for_network(x);
|
||||
const bool nwplugin_set = nwpluginID.isValid();
|
||||
|
||||
if (nwplugin_set)
|
||||
{
|
||||
struct EventStruct TempEvent;
|
||||
|
||||
TempEvent.NetworkIndex = x;
|
||||
|
||||
const bool res = ESPEasy::net::NWPluginCall(NWPlugin::Function::NWPLUGIN_GET_TRAFFIC_COUNT, &TempEvent);
|
||||
|
||||
if (res) {
|
||||
const String networkName = ESPEasy::net::makeRFCCompliantName(ESPEasy::net::getNWPluginNameFromNWPluginID(nwpluginID), '_', '_', 0);
|
||||
|
||||
// Network traffic
|
||||
addHtml(prefixHELP);
|
||||
addHtml(F("network_"));
|
||||
addHtml(networkName);
|
||||
addHtml(F(" Network Data TX and RX totals in bytes and frames\n"));
|
||||
addHtml(prefixTYPE);
|
||||
addHtml(F("network_"));
|
||||
addHtml(networkName);
|
||||
addHtml(F(" gauge\n"));
|
||||
|
||||
const __FlashStringHelper*names[] = { F("TX_bytes"), F("RX_bytes"), F("TX_frames"), F("RX_frames") };
|
||||
const int64_t values[] = { TempEvent.Par64_1, TempEvent.Par64_2, TempEvent.Par5, TempEvent.Par6 };
|
||||
constexpr uint8_t vcount = NR_ELEMENTS(values);
|
||||
|
||||
for (uint8_t n = 0; n < vcount; ++n) {
|
||||
addHtml(F("espeasy_network_"));
|
||||
addHtml(networkName);
|
||||
addHtml(F("{valueName=\""));
|
||||
addHtml(names[n]);
|
||||
addHtml(F("_total\"} "));
|
||||
addHtml(ll2String(values[n]));
|
||||
addHtml('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# endif // if FEATURE_NETWORK_STATS
|
||||
|
||||
# if FEATURE_INTERNAL_TEMPERATURE
|
||||
|
||||
// CPU Temperature
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
# include "../DataStructs/ESPEasy_EventStruct.h"
|
||||
# include "../Globals/Settings.h"
|
||||
# include "../Helpers/ESPEasy_Storage.h"
|
||||
# include "../Helpers/ESPEasy_Storage.h"
|
||||
# include "../Helpers/StringConverter.h"
|
||||
# include "../WebServer/ESPEasy_WebServer.h"
|
||||
# include "../WebServer/HTML_wrappers.h"
|
||||
|
||||
Reference in New Issue
Block a user