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

[Proof on Concept] Add initial support to export metrics for Prometheus #7216

Closed
wants to merge 6 commits into from
Closed
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
1 change: 1 addition & 0 deletions tasmota/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tasmota/language/bg-BG.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Потвърдете рестартирането"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/cs-CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/el-GR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Επιβεβαίωση επανεκκίνησης"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/es-ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/he-HE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "אישור הפעלה מחדש"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/hu-HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ko-KO.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "재시작"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/nl-NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pl-PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pt-BR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/pt-PT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/ru-RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Подтвердить перезагрузку"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/sk-SK.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/sv-SE.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/tr-TR.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/uk-UK.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "Підтвердити перезавантаження"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "确认重启"
Expand Down
1 change: 1 addition & 0 deletions tasmota/language/zh-TW.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "確認重啟"
Expand Down
2 changes: 2 additions & 0 deletions tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Hostname>.local/
Expand Down
33 changes: 33 additions & 0 deletions tasmota/xdrv_01_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +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
Expand Down Expand Up @@ -1963,6 +1966,36 @@ void HandleRestoreConfiguration(void)

/*-------------------------------------------------------------------------------------------*/

#ifdef USE_PROMETHEUS
void HandleMetrics(void)
{
if (!HttpCheckPriviledgedAccess()) { return; }

AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_METRICS);

EnergyUsage u = Settings.energy_usage;

WSContentBegin(200, CT_PLAIN);

WSContentSend_P(PSTR("# TYPE usage1_kWhtotal counter\n"));
WSContentSend_P(PSTR("usage1_kWhtotal %u\n"), u.usage1_kWhtotal);
WSContentSend_P(PSTR("# TYPE usage2_kWhtotal counter\n"));
WSContentSend_P(PSTR("usage2_kWhtotal %u\n"), u.usage2_kWhtotal);
WSContentSend_P(PSTR("# TYPE return1_kWhtotal counter\n"));
WSContentSend_P(PSTR("return1_kWhtotal %u\n"), u.return1_kWhtotal);
WSContentSend_P(PSTR("# TYPE return2_kWhtotal counter\n"));
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 %u\n"), u.last_return_kWhtotal);
WSContentSend_P(PSTR("# TYPE last_usage_kWhtotal gauge\n"));
WSContentSend_P(PSTR("last_usage_kWhtotal %u\n"), u.last_usage_kWhtotal);

WSContentEnd();
}
#endif // USE_PROMETHEUS

/*-------------------------------------------------------------------------------------------*/

void HandleInformation(void)
{
if (!HttpCheckPriviledgedAccess()) { return; }
Expand Down