From cad72ca13ff06c5594d81e93dec4167ea8503d63 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 21 Dec 2019 14:11:17 +0100 Subject: [PATCH 1/6] Add initial support to export metrics for Prometheus See https://prometheus.io/ for project information. --- tasmota/i18n.h | 1 + tasmota/language/bg-BG.h | 1 + tasmota/language/cs-CZ.h | 1 + tasmota/language/de-DE.h | 1 + tasmota/language/el-GR.h | 1 + tasmota/language/en-GB.h | 1 + tasmota/language/es-ES.h | 1 + tasmota/language/fr-FR.h | 1 + tasmota/language/he-HE.h | 1 + tasmota/language/hu-HU.h | 1 + tasmota/language/it-IT.h | 1 + tasmota/language/ko-KO.h | 1 + tasmota/language/nl-NL.h | 1 + tasmota/language/pl-PL.h | 1 + tasmota/language/pt-BR.h | 1 + tasmota/language/pt-PT.h | 1 + tasmota/language/ru-RU.h | 1 + tasmota/language/sk-SK.h | 1 + tasmota/language/sv-SE.h | 1 + tasmota/language/tr-TR.h | 1 + tasmota/language/uk-UK.h | 1 + tasmota/language/zh-CN.h | 1 + tasmota/language/zh-TW.h | 1 + tasmota/xdrv_01_webserver.ino | 33 +++++++++++++++++++++++++++++++++ 24 files changed, 56 insertions(+) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index fed6930d7639..7e024aac0737 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -632,6 +632,7 @@ const char S_RESTORE_CONFIGURATION[] PROGMEM = D_RESTORE_CONFIGURATION; const char S_FIRMWARE_UPGRADE[] PROGMEM = D_FIRMWARE_UPGRADE; const char S_CONSOLE[] PROGMEM = D_CONSOLE; const char S_INFORMATION[] PROGMEM = D_INFORMATION; +const char S_METRICS[] PROGMEM = D_METRICS; const char S_RESTART[] PROGMEM = D_RESTART; #endif // USE_WEBSERVER diff --git a/tasmota/language/bg-BG.h b/tasmota/language/bg-BG.h index 1f18d8efbc52..3464b32c8281 100644 --- a/tasmota/language/bg-BG.h +++ b/tasmota/language/bg-BG.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Превключване" #define D_CONFIGURATION "Конфигурация" #define D_INFORMATION "Информация" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Обновяване на фърмуера" #define D_CONSOLE "Конзола" #define D_CONFIRM_RESTART "Потвърдете рестартирането" diff --git a/tasmota/language/cs-CZ.h b/tasmota/language/cs-CZ.h index 1d7c6f381880..031545daaf9b 100644 --- a/tasmota/language/cs-CZ.h +++ b/tasmota/language/cs-CZ.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Přepínač" #define D_CONFIGURATION "Nastavení" #define D_INFORMATION "Informace" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Aktualizace firmware" #define D_CONSOLE "Konzole" #define D_CONFIRM_RESTART "Potvrzení restartu" diff --git a/tasmota/language/de-DE.h b/tasmota/language/de-DE.h index 6569dd232349..412b10cc0f19 100644 --- a/tasmota/language/de-DE.h +++ b/tasmota/language/de-DE.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "An/Aus" #define D_CONFIGURATION "Einstellungen" #define D_INFORMATION "Informationen" +#define D_METRICS "Metriken" #define D_FIRMWARE_UPGRADE "Firmware Update" #define D_CONSOLE "Konsole" #define D_CONFIRM_RESTART "Wirklich neustarten?" diff --git a/tasmota/language/el-GR.h b/tasmota/language/el-GR.h index f8b9c9614723..ca4fbf223d78 100644 --- a/tasmota/language/el-GR.h +++ b/tasmota/language/el-GR.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Εναλλαγή" #define D_CONFIGURATION "Ρυθμίσεις" #define D_INFORMATION "Πληροφορίες" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Αναβάθμιση" #define D_CONSOLE "Κονσόλα" #define D_CONFIRM_RESTART "Επιβεβαίωση επανεκκίνησης" diff --git a/tasmota/language/en-GB.h b/tasmota/language/en-GB.h index 257a34c861da..d8a3d5de0949 100644 --- a/tasmota/language/en-GB.h +++ b/tasmota/language/en-GB.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Toggle" #define D_CONFIGURATION "Configuration" #define D_INFORMATION "Information" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Firmware Upgrade" #define D_CONSOLE "Console" #define D_CONFIRM_RESTART "Confirm Restart" diff --git a/tasmota/language/es-ES.h b/tasmota/language/es-ES.h index 7527bb77a081..c10d3cf738f3 100644 --- a/tasmota/language/es-ES.h +++ b/tasmota/language/es-ES.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Alternar ON/OFF" #define D_CONFIGURATION "Configuración" #define D_INFORMATION "Información" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Actualizar Firmware" #define D_CONSOLE "Consola" #define D_CONFIRM_RESTART "Confirmar Reinicio" diff --git a/tasmota/language/fr-FR.h b/tasmota/language/fr-FR.h index e107409e33a8..9477e5930470 100644 --- a/tasmota/language/fr-FR.h +++ b/tasmota/language/fr-FR.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "on/off" #define D_CONFIGURATION "Configuration" #define D_INFORMATION "Informations" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Mise à jour du Firmware" #define D_CONSOLE "Console" #define D_CONFIRM_RESTART "Confirmer redémarrage" diff --git a/tasmota/language/he-HE.h b/tasmota/language/he-HE.h index ac4dadb8e566..4d774b6c3dbe 100644 --- a/tasmota/language/he-HE.h +++ b/tasmota/language/he-HE.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "מצב" #define D_CONFIGURATION "הגדרות" #define D_INFORMATION "מידע" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "שדרוג קושחה" #define D_CONSOLE "קונסול" #define D_CONFIRM_RESTART "אישור הפעלה מחדש" diff --git a/tasmota/language/hu-HU.h b/tasmota/language/hu-HU.h index 62806fa4659b..0de66754b20d 100644 --- a/tasmota/language/hu-HU.h +++ b/tasmota/language/hu-HU.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Megfordítás" #define D_CONFIGURATION "Beállítások" #define D_INFORMATION "Információ" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Firmware frissítés" #define D_CONSOLE "Konzol" #define D_CONFIRM_RESTART "Biztosan újraindítsam a modult?" diff --git a/tasmota/language/it-IT.h b/tasmota/language/it-IT.h index 0585c12d8b40..36bd7f685e34 100644 --- a/tasmota/language/it-IT.h +++ b/tasmota/language/it-IT.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "On/Off" #define D_CONFIGURATION "Configurazione" #define D_INFORMATION "Informazioni" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Aggiornamento Firmware" #define D_CONSOLE "Console" #define D_CONFIRM_RESTART "Conferma Riavvio" diff --git a/tasmota/language/ko-KO.h b/tasmota/language/ko-KO.h index bff508474c6e..714a23b21b7c 100644 --- a/tasmota/language/ko-KO.h +++ b/tasmota/language/ko-KO.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "켜기/끄기" #define D_CONFIGURATION "설정 메뉴" #define D_INFORMATION "정보" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "펌웨어 업그레이드" #define D_CONSOLE "콘솔" #define D_CONFIRM_RESTART "재시작" diff --git a/tasmota/language/nl-NL.h b/tasmota/language/nl-NL.h index 75d841ddc517..1c7700ed260e 100644 --- a/tasmota/language/nl-NL.h +++ b/tasmota/language/nl-NL.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Toggle" // Wissel, Tuimel #define D_CONFIGURATION "Configuratie" #define D_INFORMATION "Informatie" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Opwaarderen" #define D_CONSOLE "Console" #define D_CONFIRM_RESTART "Bevestig herstart" diff --git a/tasmota/language/pl-PL.h b/tasmota/language/pl-PL.h index 8f5af68133b3..df1a21f7a843 100644 --- a/tasmota/language/pl-PL.h +++ b/tasmota/language/pl-PL.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Załącz/Wyłącz" #define D_CONFIGURATION "Konfiguracja" #define D_INFORMATION "Informacje" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Aktualizacja oprogramowania" #define D_CONSOLE "Konsola" #define D_CONFIRM_RESTART "Potwierdź restart" diff --git a/tasmota/language/pt-BR.h b/tasmota/language/pt-BR.h index 0efa57789ffc..a437371f8a0e 100644 --- a/tasmota/language/pt-BR.h +++ b/tasmota/language/pt-BR.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Comandar" #define D_CONFIGURATION "Configuração" #define D_INFORMATION "Informação" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Atualização de Firmware" #define D_CONSOLE "Console" #define D_CONFIRM_RESTART "Confirmar o reinicio" diff --git a/tasmota/language/pt-PT.h b/tasmota/language/pt-PT.h index a6299c0c8f60..37c57c87e5c9 100644 --- a/tasmota/language/pt-PT.h +++ b/tasmota/language/pt-PT.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Alternar" #define D_CONFIGURATION "Configuração" #define D_INFORMATION "Informação" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Atualização de Firmware" #define D_CONSOLE "Consola" #define D_CONFIRM_RESTART "Confirmar o reinício" diff --git a/tasmota/language/ru-RU.h b/tasmota/language/ru-RU.h index 3bd788edecca..035949104371 100644 --- a/tasmota/language/ru-RU.h +++ b/tasmota/language/ru-RU.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Переключить" #define D_CONFIGURATION "Конфигурация" #define D_INFORMATION "Информация" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Обновление прошивки" #define D_CONSOLE "Консоль" #define D_CONFIRM_RESTART "Подтвердить перезагрузку" diff --git a/tasmota/language/sk-SK.h b/tasmota/language/sk-SK.h index a64e49e018dc..ca5d751a7eb0 100644 --- a/tasmota/language/sk-SK.h +++ b/tasmota/language/sk-SK.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Prepínač" #define D_CONFIGURATION "Nastavenia" #define D_INFORMATION "Informácie" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Aktualizácia firmware" #define D_CONSOLE "Konzola" #define D_CONFIRM_RESTART "Potvrdenie reštartu" diff --git a/tasmota/language/sv-SE.h b/tasmota/language/sv-SE.h index 51ffc2ae37ac..f29252992a1a 100644 --- a/tasmota/language/sv-SE.h +++ b/tasmota/language/sv-SE.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Växla" #define D_CONFIGURATION "Konfigurering" #define D_INFORMATION "Information" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Uppgradera firmware" #define D_CONSOLE "Konsol" #define D_CONFIRM_RESTART "Bekräfta omstart" diff --git a/tasmota/language/tr-TR.h b/tasmota/language/tr-TR.h index 6bc48c40f93a..1d15355d98dd 100644 --- a/tasmota/language/tr-TR.h +++ b/tasmota/language/tr-TR.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Toggle" #define D_CONFIGURATION "Konfigürasyon" #define D_INFORMATION "Bilgi" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Cihaz yazılımını Güncelle" #define D_CONSOLE "Konsol" #define D_CONFIRM_RESTART "Yeniden Başlatmayı Onayla" diff --git a/tasmota/language/uk-UK.h b/tasmota/language/uk-UK.h index b4a314630546..09b86e8ac1c9 100644 --- a/tasmota/language/uk-UK.h +++ b/tasmota/language/uk-UK.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "Переключити" #define D_CONFIGURATION "Конфігурація" #define D_INFORMATION "Інформація" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "Оновлення прошивки" #define D_CONSOLE "Консоль" #define D_CONFIRM_RESTART "Підтвердити перезавантаження" diff --git a/tasmota/language/zh-CN.h b/tasmota/language/zh-CN.h index 21aa63be3666..67f35c681bc5 100644 --- a/tasmota/language/zh-CN.h +++ b/tasmota/language/zh-CN.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "状态切换" #define D_CONFIGURATION "设置" #define D_INFORMATION "信息" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "固件升级" #define D_CONSOLE "控制台" #define D_CONFIRM_RESTART "确认重启" diff --git a/tasmota/language/zh-TW.h b/tasmota/language/zh-TW.h index 1d78f181eaca..fe9265d899e3 100644 --- a/tasmota/language/zh-TW.h +++ b/tasmota/language/zh-TW.h @@ -239,6 +239,7 @@ #define D_BUTTON_TOGGLE "狀態切換" #define D_CONFIGURATION "設置" #define D_INFORMATION "信息" +#define D_METRICS "Metrics" #define D_FIRMWARE_UPGRADE "固件升級" #define D_CONSOLE "控制台" #define D_CONFIRM_RESTART "確認重啟" diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 5dbec658a2c6..386a5d0c8b8a 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -585,6 +585,7 @@ void StartWebserver(int type, IPAddress ipweb) WebServer->on("/rs", HandleRestoreConfiguration); WebServer->on("/rt", HandleResetConfiguration); WebServer->on("/in", HandleInformation); + WebServer->on("/metrics", HandleMetrics); XdrvCall(FUNC_WEB_ADD_HANDLER); XsnsCall(FUNC_WEB_ADD_HANDLER); #endif // Not FIRMWARE_MINIMAL @@ -1963,6 +1964,38 @@ void HandleRestoreConfiguration(void) /*-------------------------------------------------------------------------------------------*/ +void HandleMetrics(void) +{ + if (!HttpCheckPriviledgedAccess()) { return; } + + AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_METRICS); + + WSContentStart_P(S_METRICS); + EnergyUsage u = Settings.energy_usage; + WSContentSend_P(PSTR("# HELP usage1_kWhtotal Total kWh used (counter 1).")); + WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter")); + WSContentSend_P(PSTR("usage1_kWhtotal %f"), (double)u.usage1_kWhtotal); + WSContentSend_P(PSTR("# HELP usage2_kWhtotal Total kWh used (counter 2).")); + WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter")); + WSContentSend_P(PSTR("usage2_kWhtotal %f"), (double)u.usage2_kWhtotal); + WSContentSend_P(PSTR("# HELP return1_kWhtotal Total kWh returned (counter 1).")); + WSContentSend_P(PSTR("# TYPE return1_kWhtotal counter")); + WSContentSend_P(PSTR("return1_kWhtotal %f"), (double)u.return1_kWhtotal); + WSContentSend_P(PSTR("# HELP return2_kWhtotal Total kWh returned (counter 2).")); + WSContentSend_P(PSTR("# TYPE return2_kWhtotal counter")); + WSContentSend_P(PSTR("return2_kWhtota l%f"), (double)u.return2_kWhtotal); + WSContentSend_P(PSTR("# HELP last_return_kWhtotal ???.")); + WSContentSend_P(PSTR("# TYPE last_return_kWhtotal gauge")); + WSContentSend_P(PSTR("last_return_kWhtotal %f"), (double)u.last_return_kWhtotal); + WSContentSend_P(PSTR("# HELP last_usage_kWhtotal ???.")); + WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge")); + WSContentSend_P(PSTR("last_usage_kWhtotal %f"), (double)u.last_usage_kWhtotal); + + WSContentStop(); +} + +/*-------------------------------------------------------------------------------------------*/ + void HandleInformation(void) { if (!HttpCheckPriviledgedAccess()) { return; } From a0b77d873afb9ffc6d1d6342db8f9207686876e7 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 14 Dec 2019 15:28:59 +0100 Subject: [PATCH 2/6] Add newline characters for the Prometheus metrics page --- tasmota/xdrv_01_webserver.ino | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 386a5d0c8b8a..3327bb6d323e 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1972,24 +1972,24 @@ void HandleMetrics(void) WSContentStart_P(S_METRICS); EnergyUsage u = Settings.energy_usage; - WSContentSend_P(PSTR("# HELP usage1_kWhtotal Total kWh used (counter 1).")); - WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter")); - WSContentSend_P(PSTR("usage1_kWhtotal %f"), (double)u.usage1_kWhtotal); - WSContentSend_P(PSTR("# HELP usage2_kWhtotal Total kWh used (counter 2).")); - WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter")); - WSContentSend_P(PSTR("usage2_kWhtotal %f"), (double)u.usage2_kWhtotal); - WSContentSend_P(PSTR("# HELP return1_kWhtotal Total kWh returned (counter 1).")); - WSContentSend_P(PSTR("# TYPE return1_kWhtotal counter")); - WSContentSend_P(PSTR("return1_kWhtotal %f"), (double)u.return1_kWhtotal); - WSContentSend_P(PSTR("# HELP return2_kWhtotal Total kWh returned (counter 2).")); - WSContentSend_P(PSTR("# TYPE return2_kWhtotal counter")); - WSContentSend_P(PSTR("return2_kWhtota l%f"), (double)u.return2_kWhtotal); - WSContentSend_P(PSTR("# HELP last_return_kWhtotal ???.")); - WSContentSend_P(PSTR("# TYPE last_return_kWhtotal gauge")); - WSContentSend_P(PSTR("last_return_kWhtotal %f"), (double)u.last_return_kWhtotal); - WSContentSend_P(PSTR("# HELP last_usage_kWhtotal ???.")); - WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge")); - WSContentSend_P(PSTR("last_usage_kWhtotal %f"), (double)u.last_usage_kWhtotal); + WSContentSend_P(PSTR("# HELP usage1_kWhtotal Total kWh used (counter 1).\n")); + WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter\n")); + WSContentSend_P(PSTR("usage1_kWhtotal %f\n"), (double)u.usage1_kWhtotal); + WSContentSend_P(PSTR("# HELP usage2_kWhtotal Total kWh used (counter 2).\n")); + WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter\n")); + WSContentSend_P(PSTR("usage2_kWhtotal %f\n"), (double)u.usage2_kWhtotal); + WSContentSend_P(PSTR("# HELP return1_kWhtotal Total kWh returned (counter 1).\n")); + WSContentSend_P(PSTR("# TYPE return1_kWhtotal counter\n")); + WSContentSend_P(PSTR("return1_kWhtotal %f\n"), (double)u.return1_kWhtotal); + WSContentSend_P(PSTR("# HELP return2_kWhtotal Total kWh returned (counter 2).\n")); + WSContentSend_P(PSTR("# TYPE return2_kWhtotal counter\n")); + WSContentSend_P(PSTR("return2_kWhtota l%f\n"), (double)u.return2_kWhtotal); + WSContentSend_P(PSTR("# HELP last_return_kWhtotal ???.\n")); + WSContentSend_P(PSTR("# TYPE last_return_kWhtotal gauge\n")); + WSContentSend_P(PSTR("last_return_kWhtotal %f\n"), (double)u.last_return_kWhtotal); + WSContentSend_P(PSTR("# HELP last_usage_kWhtotal ???.\n")); + WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge\n")); + WSContentSend_P(PSTR("last_usage_kWhtotal %f\n"), (double)u.last_usage_kWhtotal); WSContentStop(); } From ce92091eb416f63a0e3728fe64d2fb797638cd47 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 21 Dec 2019 15:17:54 +0100 Subject: [PATCH 3/6] Add USE_PROMETHEUS define --- tasmota/my_user_config.h | 2 ++ tasmota/xdrv_01_webserver.ino | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 5ff6bb6a2777..7e9699d534f9 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -312,6 +312,8 @@ #define USE_EMULATION_HUE // Enable Hue Bridge emulation for Alexa (+14k code, +2k mem common) #define USE_EMULATION_WEMO // Enable Belkin WeMo emulation for Alexa (+6k code, +2k mem common) +//#define USE_PROMETHEUS // Export metrics for Prometheus (+1k code) + // -- mDNS ---------------------------------------- #define USE_DISCOVERY // Enable mDNS for the following services (+8k code or +23.5k code with core 2_5_x, +0.3k mem) #define WEBSERVER_ADVERTISE // Provide access to webserver by name .local/ diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 3327bb6d323e..0600e9ccd9cd 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -585,7 +585,9 @@ void StartWebserver(int type, IPAddress ipweb) WebServer->on("/rs", HandleRestoreConfiguration); WebServer->on("/rt", HandleResetConfiguration); WebServer->on("/in", HandleInformation); +#ifdef USE_PROMETHEUS WebServer->on("/metrics", HandleMetrics); +#endif // USE_PROMETHEUS XdrvCall(FUNC_WEB_ADD_HANDLER); XsnsCall(FUNC_WEB_ADD_HANDLER); #endif // Not FIRMWARE_MINIMAL @@ -1964,6 +1966,7 @@ void HandleRestoreConfiguration(void) /*-------------------------------------------------------------------------------------------*/ +#ifdef USE_PROMETHEUS void HandleMetrics(void) { if (!HttpCheckPriviledgedAccess()) { return; } @@ -1993,6 +1996,7 @@ void HandleMetrics(void) WSContentStop(); } +#endif // USE_PROMETHEUS /*-------------------------------------------------------------------------------------------*/ From 655cefe1eceb6beedc1a9ace09ccb5ac26df1df9 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 21 Dec 2019 15:19:21 +0100 Subject: [PATCH 4/6] Remove metrics HELP string --- tasmota/xdrv_01_webserver.ino | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 0600e9ccd9cd..161f2edfbc88 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1975,22 +1975,16 @@ void HandleMetrics(void) WSContentStart_P(S_METRICS); EnergyUsage u = Settings.energy_usage; - WSContentSend_P(PSTR("# HELP usage1_kWhtotal Total kWh used (counter 1).\n")); WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter\n")); WSContentSend_P(PSTR("usage1_kWhtotal %f\n"), (double)u.usage1_kWhtotal); - WSContentSend_P(PSTR("# HELP usage2_kWhtotal Total kWh used (counter 2).\n")); WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter\n")); WSContentSend_P(PSTR("usage2_kWhtotal %f\n"), (double)u.usage2_kWhtotal); - WSContentSend_P(PSTR("# HELP return1_kWhtotal Total kWh returned (counter 1).\n")); WSContentSend_P(PSTR("# TYPE return1_kWhtotal counter\n")); WSContentSend_P(PSTR("return1_kWhtotal %f\n"), (double)u.return1_kWhtotal); - WSContentSend_P(PSTR("# HELP return2_kWhtotal Total kWh returned (counter 2).\n")); WSContentSend_P(PSTR("# TYPE return2_kWhtotal counter\n")); WSContentSend_P(PSTR("return2_kWhtota l%f\n"), (double)u.return2_kWhtotal); - WSContentSend_P(PSTR("# HELP last_return_kWhtotal ???.\n")); WSContentSend_P(PSTR("# TYPE last_return_kWhtotal gauge\n")); WSContentSend_P(PSTR("last_return_kWhtotal %f\n"), (double)u.last_return_kWhtotal); - WSContentSend_P(PSTR("# HELP last_usage_kWhtotal ???.\n")); WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge\n")); WSContentSend_P(PSTR("last_usage_kWhtotal %f\n"), (double)u.last_usage_kWhtotal); From 801e29fe989d5630874d5eb52a923e15a3b6d081 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 21 Dec 2019 15:28:55 +0100 Subject: [PATCH 5/6] Use correct content begin/end functions --- tasmota/xdrv_01_webserver.ino | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 161f2edfbc88..1a652f944baf 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1973,8 +1973,10 @@ void HandleMetrics(void) AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_METRICS); - WSContentStart_P(S_METRICS); EnergyUsage u = Settings.energy_usage; + + WSContentBegin(200, CT_PLAIN); + WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter\n")); WSContentSend_P(PSTR("usage1_kWhtotal %f\n"), (double)u.usage1_kWhtotal); WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter\n")); @@ -1988,7 +1990,7 @@ void HandleMetrics(void) WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge\n")); WSContentSend_P(PSTR("last_usage_kWhtotal %f\n"), (double)u.last_usage_kWhtotal); - WSContentStop(); + WSContentEnd(); } #endif // USE_PROMETHEUS From 170816ddf1057a979d8245e379a841007e14f7a9 Mon Sep 17 00:00:00 2001 From: Marius Nuennerich Date: Sat, 21 Dec 2019 15:31:15 +0100 Subject: [PATCH 6/6] Export unsigned integers, not floats for Prometheus --- tasmota/xdrv_01_webserver.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 1a652f944baf..3d2bb22074fc 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -1978,17 +1978,17 @@ void HandleMetrics(void) WSContentBegin(200, CT_PLAIN); WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter\n")); - WSContentSend_P(PSTR("usage1_kWhtotal %f\n"), (double)u.usage1_kWhtotal); + WSContentSend_P(PSTR("usage1_kWhtotal %u\n"), u.usage1_kWhtotal); WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter\n")); - WSContentSend_P(PSTR("usage2_kWhtotal %f\n"), (double)u.usage2_kWhtotal); + WSContentSend_P(PSTR("usage2_kWhtotal %u\n"), u.usage2_kWhtotal); WSContentSend_P(PSTR("# TYPE return1_kWhtotal counter\n")); - WSContentSend_P(PSTR("return1_kWhtotal %f\n"), (double)u.return1_kWhtotal); + WSContentSend_P(PSTR("return1_kWhtotal %u\n"), u.return1_kWhtotal); WSContentSend_P(PSTR("# TYPE return2_kWhtotal counter\n")); - WSContentSend_P(PSTR("return2_kWhtota l%f\n"), (double)u.return2_kWhtotal); + WSContentSend_P(PSTR("return2_kWhtotal %u\n"), u.return2_kWhtotal); WSContentSend_P(PSTR("# TYPE last_return_kWhtotal gauge\n")); - WSContentSend_P(PSTR("last_return_kWhtotal %f\n"), (double)u.last_return_kWhtotal); + WSContentSend_P(PSTR("last_return_kWhtotal %u\n"), u.last_return_kWhtotal); WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge\n")); - WSContentSend_P(PSTR("last_usage_kWhtotal %f\n"), (double)u.last_usage_kWhtotal); + WSContentSend_P(PSTR("last_usage_kWhtotal %u\n"), u.last_usage_kWhtotal); WSContentEnd(); }