Add optional support for Prometheus

Add optional support for Prometheus using file xsns_91_prometheus.ino (#7216)
This commit is contained in:
Theo Arends 2020-01-01 17:17:10 +01:00
parent 3c491a8434
commit 01b5df9651
3 changed files with 87 additions and 0 deletions

View File

@ -58,6 +58,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging
- Fix commands ``Display`` and ``Counter`` from overruling command processing (#7322)
- Fix ``White`` added to light status (#7142)
- Fix Improved fade linearity with gamma correction
- Fix LCD line and column positioning (#7387)
- Fix Display handling of hexadecimal escape characters (#7387)
- Add command ``SetOption79 0/1`` to enable reset of counters at teleperiod time by Andre Thomas (#7355)
@ -66,3 +67,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add support for DS1624, DS1621 Temperature sensor by Leonid Myravjev
- Add Zigbee attribute decoder for Xiaomi Aqara Cube
- Add support for ``AdcParam`` parameters to control ADC0 Current Transformer Apparent Power formula by Jodi Dillon (#7100)
- Add optional support for Prometheus using file xsns_91_prometheus.ino (#7216)

View File

@ -3,6 +3,7 @@
### 8.1.0.2 20191230
- Add support for ``AdcParam`` parameters to control ADC0 Current Transformer Apparent Power formula by Jodi Dillon (#7100)
- Add optional support for Prometheus using file xsns_91_prometheus.ino (#7216)
- Fix LCD line and column positioning (#7387)
- Fix Display handling of hexadecimal escape characters (#7387)
- Fix Improved fade linearity with gamma correction

View File

@ -0,0 +1,84 @@
/*
xsns_91_prometheus.ino - Web based information for Tasmota
Copyright (C) 2020 Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//#define USE_PROMETHEUS // Enable retrieval of metrics
#ifdef USE_PROMETHEUS
/*********************************************************************************************\
* Prometheus support
\*********************************************************************************************/
#define XSNS_91 91
void HandleMetrics(void)
{
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR("Prometheus"));
WSContentBegin(200, CT_PLAIN);
char parameter[FLOATSZ];
if (global_temperature != 9999) {
dtostrfd(global_temperature, Settings.flag2.temperature_resolution, parameter);
WSContentSend_P(PSTR("# TYPE global_temperature gauge\nglobal_temperature %s\n"), parameter);
}
if (global_humidity != 0) {
dtostrfd(global_humidity, Settings.flag2.humidity_resolution, parameter);
WSContentSend_P(PSTR("# TYPE global_humidity gauge\nglobal_humidity %s\n"), parameter);
}
if (global_pressure != 0) {
dtostrfd(global_pressure, Settings.flag2.pressure_resolution, parameter);
WSContentSend_P(PSTR("# TYPE global_pressure gauge\nglobal_pressure %s\n"), parameter);
}
#ifdef USE_ENERGY_SENSOR
dtostrfd(Energy.voltage[0], Settings.flag2.voltage_resolution, parameter);
WSContentSend_P(PSTR("# TYPE voltage gauge\nvoltage %s\n"), parameter);
dtostrfd(Energy.current[0], Settings.flag2.current_resolution, parameter);
WSContentSend_P(PSTR("# TYPE current gauge\ncurrent %s\n"), parameter);
dtostrfd(Energy.active_power[0], Settings.flag2.wattage_resolution, parameter);
WSContentSend_P(PSTR("# TYPE active_power guage\nactive_power %s\n"), parameter);
dtostrfd(Energy.daily, Settings.flag2.energy_resolution, parameter);
WSContentSend_P(PSTR("# TYPE energy_daily counter\nenergy_daily %s\n"), parameter);
dtostrfd(Energy.total, Settings.flag2.energy_resolution, parameter);
WSContentSend_P(PSTR("# TYPE energy_total counter\nenergy_total %s\n"), parameter);
#endif
WSContentEnd();
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns91(uint8_t function)
{
bool result = false;
switch (function) {
case FUNC_WEB_ADD_HANDLER:
WebServer->on("/metrics", HandleMetrics);
break;
}
return result;
}
#endif // USE_PROMETHEUS