mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 05:06:32 +00:00
Update xsns_75_prometheus.ino
This commit is contained in:
parent
3d6dd8ff87
commit
732e3c7c2c
@ -22,7 +22,7 @@
|
|||||||
* Prometheus support
|
* Prometheus support
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XSNS_75 75
|
#define XSNS_75 75
|
||||||
|
|
||||||
const char *UnitfromType(const char *type)
|
const char *UnitfromType(const char *type)
|
||||||
{
|
{
|
||||||
@ -81,15 +81,13 @@ const char *FormatMetricName(const char *metric)
|
|||||||
|
|
||||||
void HandleMetrics(void)
|
void HandleMetrics(void)
|
||||||
{
|
{
|
||||||
if (!HttpCheckPriviledgedAccess())
|
if (!HttpCheckPriviledgedAccess()) { return; }
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP "Prometheus"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP "Prometheus"));
|
||||||
|
|
||||||
WSContentBegin(200, CT_PLAIN);
|
WSContentBegin(200, CT_PLAIN);
|
||||||
|
|
||||||
|
|
||||||
char parameter[FLOATSZ];
|
char parameter[FLOATSZ];
|
||||||
|
|
||||||
// Pseudo-metric providing metadata about the running firmware version.
|
// Pseudo-metric providing metadata about the running firmware version.
|
||||||
@ -99,24 +97,22 @@ void HandleMetrics(void)
|
|||||||
WSContentSend_P(PSTR("# TYPE tasmota_boot_count counter\ntasmota_boot_count %d\n"), Settings.bootcount);
|
WSContentSend_P(PSTR("# TYPE tasmota_boot_count counter\ntasmota_boot_count %d\n"), Settings.bootcount);
|
||||||
WSContentSend_P(PSTR("# TYPE tasmota_flash_writes_total counter\ntasmota_flash_writes_total %d\n"), Settings.save_flag);
|
WSContentSend_P(PSTR("# TYPE tasmota_flash_writes_total counter\ntasmota_flash_writes_total %d\n"), Settings.save_flag);
|
||||||
|
|
||||||
|
|
||||||
// Pseudo-metric providing metadata about the WiFi station.
|
// Pseudo-metric providing metadata about the WiFi station.
|
||||||
WSContentSend_P(PSTR("# TYPE tasmota_wifi_station_info gauge\ntasmota_wifi_station_info{bssid=\"%s\",ssid=\"%s\"} 1\n"), WiFi.BSSIDstr().c_str(), WiFi.SSID().c_str());
|
WSContentSend_P(PSTR("# TYPE tasmota_wifi_station_info gauge\ntasmota_wifi_station_info{bssid=\"%s\",ssid=\"%s\"} 1\n"), WiFi.BSSIDstr().c_str(), WiFi.SSID().c_str());
|
||||||
|
|
||||||
// Wi-Fi Signal strength
|
// Wi-Fi Signal strength
|
||||||
WSContentSend_P(PSTR("# TYPE tasmota_wifi_station_signal_dbm gauge\ntasmota_wifi_station_signal_dbm{mac_address=\"%s\"} %d\n"), WiFi.BSSIDstr().c_str(), WiFi.RSSI());
|
WSContentSend_P(PSTR("# TYPE tasmota_wifi_station_signal_dbm gauge\ntasmota_wifi_station_signal_dbm{mac_address=\"%s\"} %d\n"), WiFi.BSSIDstr().c_str(), WiFi.RSSI());
|
||||||
|
|
||||||
if (!isnan(TasmotaGlobal.temperature_celsius))
|
if (!isnan(TasmotaGlobal.temperature_celsius)) {
|
||||||
{
|
|
||||||
dtostrfd(TasmotaGlobal.temperature_celsius, Settings.flag2.temperature_resolution, parameter);
|
dtostrfd(TasmotaGlobal.temperature_celsius, Settings.flag2.temperature_resolution, parameter);
|
||||||
WSContentSend_P(PSTR("# TYPE tasmotaglobal_temperature_celsius gauge\ntasmotaglobal_temperature_celsius %s\n"), parameter);
|
WSContentSend_P(PSTR("# TYPE tasmotaglobal_temperature_celsius gauge\ntasmotaglobal_temperature_celsius %s\n"), parameter);
|
||||||
}
|
}
|
||||||
if (TasmotaGlobal.humidity != 0)
|
if (TasmotaGlobal.humidity != 0) {
|
||||||
{
|
|
||||||
dtostrfd(TasmotaGlobal.humidity, Settings.flag2.humidity_resolution, parameter);
|
dtostrfd(TasmotaGlobal.humidity, Settings.flag2.humidity_resolution, parameter);
|
||||||
WSContentSend_P(PSTR("# TYPE tasmotaglobal_humidity gauge\ntasmotaglobal_humidity %s\n"), parameter);
|
WSContentSend_P(PSTR("# TYPE tasmotaglobal_humidity gauge\ntasmotaglobal_humidity %s\n"), parameter);
|
||||||
}
|
}
|
||||||
if (TasmotaGlobal.pressure_hpa != 0)
|
if (TasmotaGlobal.pressure_hpa != 0) {
|
||||||
{
|
|
||||||
dtostrfd(TasmotaGlobal.pressure_hpa, Settings.flag2.pressure_resolution, parameter);
|
dtostrfd(TasmotaGlobal.pressure_hpa, Settings.flag2.pressure_resolution, parameter);
|
||||||
WSContentSend_P(PSTR("# TYPE tasmotaglobal_pressure_hpa gauge\ntasmotaglobal_pressure_hpa %s\n"), parameter);
|
WSContentSend_P(PSTR("# TYPE tasmotaglobal_pressure_hpa gauge\ntasmotaglobal_pressure_hpa %s\n"), parameter);
|
||||||
}
|
}
|
||||||
@ -134,10 +130,9 @@ void HandleMetrics(void)
|
|||||||
WSContentSend_P(PSTR("# TYPE energy_power_kilowatts_total counter\nenergy_power_kilowatts_total %s\n"), parameter);
|
WSContentSend_P(PSTR("# TYPE energy_power_kilowatts_total counter\nenergy_power_kilowatts_total %s\n"), parameter);
|
||||||
#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;
|
||||||
WSContentSend_P(PSTR("# TYPE relay%d_state gauge\nrelay%d_state %d\n"), device + 1, device + 1, (TasmotaGlobal.power & mask));
|
WSContentSend_P(PSTR("# TYPE relay%d_state gauge\nrelay%d_state %d\n"), device+1, device+1, (TasmotaGlobal.power & mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseClear();
|
ResponseClear();
|
||||||
@ -209,8 +204,7 @@ bool Xsns75(uint8_t function)
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function)
|
switch (function) {
|
||||||
{
|
|
||||||
case FUNC_WEB_ADD_HANDLER:
|
case FUNC_WEB_ADD_HANDLER:
|
||||||
WebServer_on(PSTR("/metrics"), HandleMetrics);
|
WebServer_on(PSTR("/metrics"), HandleMetrics);
|
||||||
break;
|
break;
|
||||||
@ -218,4 +212,4 @@ bool Xsns75(uint8_t function)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USE_PROMETHEUS
|
#endif // USE_PROMETHEUS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user