mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 13:16:32 +00:00
Update xsns_75_prometheus.ino
added comments
This commit is contained in:
parent
732e3c7c2c
commit
d7e8614dbb
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#define XSNS_75 75
|
#define XSNS_75 75
|
||||||
|
|
||||||
const char *UnitfromType(const char *type)
|
const char *UnitfromType(const char *type) // find unit for measurment type
|
||||||
{
|
{
|
||||||
if (strcmp(type, "time") == 0)
|
if (strcmp(type, "time") == 0)
|
||||||
{
|
{
|
||||||
@ -61,14 +61,14 @@ const char *UnitfromType(const char *type)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *FormatMetricName(const char *metric)
|
const char *FormatMetricName(const char *metric) // cleanup spaces and uppercases for Prmetheus metrics conventions
|
||||||
{
|
{
|
||||||
char *formated = (char *)malloc(strlen(metric)+1);
|
char *formated = (char *)malloc(strlen(metric)+1);
|
||||||
uint32_t cnt = 0;
|
uint32_t cnt = 0;
|
||||||
for (cnt; cnt < strlen(metric)+1; cnt++)
|
for (cnt; cnt < strlen(metric)+1; cnt++)
|
||||||
{
|
{
|
||||||
if (metric[cnt] == ' ')
|
if (metric[cnt] == ' ')
|
||||||
{ //replace space with
|
{
|
||||||
formated[cnt] = '_';
|
formated[cnt] = '_';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -136,7 +136,7 @@ void HandleMetrics(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResponseClear();
|
ResponseClear();
|
||||||
MqttShowSensor();
|
MqttShowSensor(); //Pull sensor data
|
||||||
char json[strlen(TasmotaGlobal.mqtt_data)+1];
|
char json[strlen(TasmotaGlobal.mqtt_data)+1];
|
||||||
snprintf_P(json, sizeof(json), TasmotaGlobal.mqtt_data);
|
snprintf_P(json, sizeof(json), TasmotaGlobal.mqtt_data);
|
||||||
String jsonStr = json;
|
String jsonStr = json;
|
||||||
@ -184,8 +184,8 @@ void HandleMetrics(void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *value = value1.getStr(nullptr);
|
const char *value = value1.getStr(nullptr);
|
||||||
if (value != nullptr && isdigit(value[0] && strcmp(key1.getStr(), "Time") != 0))
|
if (value != nullptr && isdigit(value[0] && strcmp(key1.getStr(), "Time") != 0)) //remove false 'time' metric
|
||||||
{ //remove false 'time' metric
|
{
|
||||||
const char *sensor = FormatMetricName(key1.getStr());
|
const char *sensor = FormatMetricName(key1.getStr());
|
||||||
WSContentSend_P(PSTR("# TYPE tasmota_sensors_%s gauge\ntasmota_sensors{sensor=\"%s\"} %s\n"), sensor, sensor, value);
|
WSContentSend_P(PSTR("# TYPE tasmota_sensors_%s gauge\ntasmota_sensors{sensor=\"%s\"} %s\n"), sensor, sensor, value);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user