Merge pull request #12842 from hansmi/promchg1

Prometheus: Always use prefix and update changelog
This commit is contained in:
Theo Arends 2021-08-09 11:57:10 +02:00 committed by GitHub
commit b43779c601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file.
- Make Sonoff L1 MusicSync persistent (#12008) - Make Sonoff L1 MusicSync persistent (#12008)
- Relax NTP poll if no ntpserver can be resolved by DNS - Relax NTP poll if no ntpserver can be resolved by DNS
- Move firmware binaries to https://github.com/arendst/Tasmota-firmware/tree/main/release-firmware - Move firmware binaries to https://github.com/arendst/Tasmota-firmware/tree/main/release-firmware
- Prometheus: All metrics are prefixed with ``tasmota_``
memory metrics have been cleaned up to work consistently between ESP8266 and ESP32
the device name is reported as an info metric
- Default disable CORS for enhanced security and provide user compile option ``#define USE_CORS`` (#12827) - Default disable CORS for enhanced security and provide user compile option ``#define USE_CORS`` (#12827)
### Fixed ### Fixed

View File

@ -78,16 +78,15 @@ String FormatMetricName(const char *metric) {
} }
const uint8_t const uint8_t
kPromMetricNoPrefix = _BV(1), kPromMetricGauge = _BV(0),
kPromMetricGauge = _BV(2), kPromMetricCounter = _BV(1),
kPromMetricCounter = _BV(3),
kPromMetricTypeMask = kPromMetricGauge | kPromMetricCounter; kPromMetricTypeMask = kPromMetricGauge | kPromMetricCounter;
// Format and send a Prometheus metric to the client. Use flags to configure // Format and send a Prometheus metric to the client. Use flags to configure
// the type. Labels must be supplied in tuples of two character array pointers // the type. Labels must be supplied in tuples of two character array pointers
// and terminated by nullptr. // and terminated by nullptr.
void WritePromMetric(const char *name, uint8_t flags, const char *value, va_list labels) { void WritePromMetric(const char *name, uint8_t flags, const char *value, va_list labels) {
PGM_P const prefix = (flags & kPromMetricNoPrefix) ? PSTR("") : PSTR("tasmota_"); PGM_P const prefix = PSTR("tasmota_");
PGM_P tmp; PGM_P tmp;
String lval; String lval;
@ -258,29 +257,27 @@ void HandleMetrics(void) {
#endif #endif
#ifdef USE_ENERGY_SENSOR #ifdef USE_ENERGY_SENSOR
// TODO: Don't disable prefix on energy metrics
WritePromMetricDec(PSTR("energy_voltage_volts"), WritePromMetricDec(PSTR("energy_voltage_volts"),
kPromMetricGauge | kPromMetricNoPrefix, kPromMetricGauge,
Energy.voltage[0], Settings->flag2.voltage_resolution, nullptr); Energy.voltage[0], Settings->flag2.voltage_resolution, nullptr);
WritePromMetricDec(PSTR("energy_current_amperes"), WritePromMetricDec(PSTR("energy_current_amperes"),
kPromMetricGauge | kPromMetricNoPrefix, kPromMetricGauge,
Energy.current[0], Settings->flag2.current_resolution, nullptr); Energy.current[0], Settings->flag2.current_resolution, nullptr);
WritePromMetricDec(PSTR("energy_power_active_watts"), WritePromMetricDec(PSTR("energy_power_active_watts"),
kPromMetricGauge | kPromMetricNoPrefix, kPromMetricGauge,
Energy.active_power[0], Settings->flag2.wattage_resolution, nullptr); Energy.active_power[0], Settings->flag2.wattage_resolution, nullptr);
WritePromMetricDec(PSTR("energy_power_kilowatts_daily"), WritePromMetricDec(PSTR("energy_power_kilowatts_daily"),
kPromMetricCounter | kPromMetricNoPrefix, kPromMetricCounter,
Energy.daily, Settings->flag2.energy_resolution, nullptr); Energy.daily, Settings->flag2.energy_resolution, nullptr);
WritePromMetricDec(PSTR("energy_power_kilowatts_total"), WritePromMetricDec(PSTR("energy_power_kilowatts_total"),
kPromMetricCounter | kPromMetricNoPrefix, kPromMetricCounter,
Energy.total, Settings->flag2.energy_resolution, nullptr); Energy.total, Settings->flag2.energy_resolution, nullptr);
#endif #endif
for (uint32_t device = 0; device < TasmotaGlobal.devices_present; device++) { for (uint32_t device = 0; device < TasmotaGlobal.devices_present; device++) {
power_t mask = 1 << device; power_t mask = 1 << device;
// TODO: Don't disable prefix
snprintf_P(namebuf, sizeof(namebuf), PSTR("relay%d_state"), device + 1); snprintf_P(namebuf, sizeof(namebuf), PSTR("relay%d_state"), device + 1);
WritePromMetricInt32(namebuf, kPromMetricGauge | kPromMetricNoPrefix, WritePromMetricInt32(namebuf, kPromMetricGauge,
(TasmotaGlobal.power & mask), nullptr); (TasmotaGlobal.power & mask), nullptr);
} }