]> mj.ucw.cz Git - home-hw.git/commitdiff
Prometheus: Power meter delivered via MQTT
authorMartin Mares <mj@ucw.cz>
Tue, 16 Jul 2019 21:55:04 +0000 (23:55 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 16 Jul 2019 21:55:04 +0000 (23:55 +0200)
prometheus/burrow-prometheus.c

index ced7e4c06b2e99f8741cc1c063471a08571a54d1..2e9bd07b6de250d3bb64e838216f0c65da67399f 100644 (file)
@@ -139,6 +139,66 @@ static const struct attr attr_table[] = {
                .type = "gauge",
                .topic = "burrow/air/fan-pwm"
        },
+       {
+               // Common heading for all voltages
+               .metric = "pm_voltage",
+               .help = "Voltage between phases and neutral [V]",
+               .type = "gauge",
+       },
+       {
+               .metric = "pm_voltage{phase=\"L1N\"}",
+               .topic = "burrow/power/voltage/l1n",
+       },
+       {
+               .metric = "pm_voltage{phase=\"L2N\"}",
+               .topic = "burrow/power/voltage/l2n",
+       },
+       {
+               .metric = "pm_voltage{phase=\"L3N\"}",
+               .topic = "burrow/power/voltage/l3n",
+       },
+       {
+               // Common heading for all currents
+               .metric = "pm_current",
+               .help = "Current through phases [A]",
+               .type = "gauge",
+       },
+       {
+               .metric = "pm_current{phase=\"L1\"}",
+               .topic = "burrow/power/current/l1",
+       },
+       {
+               .metric = "pm_current{phase=\"L2\"}",
+               .topic = "burrow/power/current/l2",
+       },
+       {
+               .metric = "pm_current{phase=\"L3\"}",
+               .topic = "burrow/power/current/l3",
+       },
+       {
+               .metric = "pm_power",
+               .help = "Total power [W]",
+               .type = "gauge",
+               .topic = "burrow/power/power",
+       },
+       {
+               .metric = "pm_energy",
+               .help = "Total energy [kWh]",
+               .type = "gauge",
+               .topic = "burrow/power/energy",
+       },
+       {
+               .metric = "pm_reactive_power",
+               .help = "Total reactive power [VAr]",
+               .type = "gauge",
+               .topic = "burrow/power/reactive/power",
+       },
+       {
+               .metric = "pm_reactive_energy",
+               .help = "Total reactive energy [kVArh]",
+               .type = "gauge",
+               .topic = "burrow/power/reactive/energy",
+       },
 };
 
 static char *attr_values[ARRAY_SIZE(attr_table)];
@@ -300,6 +360,11 @@ static void http_answer(struct fastbuf *fb)
                snprintf(val, sizeof(val), "%s", attr_values[i] ? : "");
                pthread_mutex_unlock(&attr_mutex);
 
+               if (a->help)
+                       bprintf(fb, "# HELP %s %s\n", a->metric, a->help);
+               if (a->type)
+                       bprintf(fb, "# TYPE %s %s\n", a->metric, a->type);
+
                if (!val[0])
                        continue;
                int fields = str_wordsplit(val, w, ARRAY_SIZE(w));
@@ -311,17 +376,15 @@ static void http_answer(struct fastbuf *fb)
                                continue;
                }
 
-               if (a->help)
-                       bprintf(fb, "# HELP %s %s\n", a->metric, a->help);
-               if (a->type)
-                       bprintf(fb, "# TYPE %s %s\n", a->metric, a->type);
-               bprintf(fb, "%s %s", a->metric, val);
+               if (a->topic) {
+                       bprintf(fb, "%s %s", a->metric, val);
 #if 0
-               // Prometheus does not like our timestamps -- why?
-               if (fields >= 2)
-                       bprintf(fb, " %s", w[1]);
+                       // Prometheus does not like our timestamps -- why?
+                       if (fields >= 2)
+                               bprintf(fb, " %s", w[1]);
 #endif
-               bputc(fb, '\n');
+                       bputc(fb, '\n');
+               }
        }
 }