Now that mgos_prometheus_metrics_printf() allows for multiple lines with the same name, remove the hacks
This commit is contained in:
33
src/dht.c
33
src/dht.c
@ -19,36 +19,17 @@ struct dht_sensor {
|
|||||||
static struct dht_sensor *s_dht_sensor[MAX_DHT];
|
static struct dht_sensor *s_dht_sensor[MAX_DHT];
|
||||||
static int s_num_dht = 0;
|
static int s_num_dht = 0;
|
||||||
|
|
||||||
static void print_chunk(struct mg_connection *nc, char *name, char *fmt, ...) {
|
|
||||||
char chunk[500];
|
|
||||||
int chunklen=0;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
snprintf(chunk, sizeof(chunk), "%s%s", name, fmt[0]=='{' ? "" : " ");
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsnprintf(chunk+strlen(chunk), sizeof(chunk)-strlen(chunk), fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
strncat(chunk, "\n", sizeof(chunk));
|
|
||||||
chunklen=strlen(chunk);
|
|
||||||
LOG(LL_DEBUG, ("Chunk '%s' with length %d", chunk, chunklen));
|
|
||||||
mg_printf(nc, "%X\r\n%s\r\n", chunklen, chunk);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dht_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
static void dht_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// BUG -- repeated HELP and TYPE makes Prometheus parser bork :(
|
for (i=0; i<s_num_dht; i++) {
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"temperature", "Temperature in celcius",
|
"temperature", "Temperature in Celcius",
|
||||||
"{sensor=\"0\",type=\"DHT\"} %f", s_dht_sensor[0]->temp);
|
"{sensor=\"%d\",type=\"DHT\"} %f", i, s_dht_sensor[i]->temp);
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"humidity", "Relative humidity percentage",
|
"humidity", "Relative humidity percentage",
|
||||||
"{sensor=\"0\",type=\"DHT\"} %f", s_dht_sensor[0]->humidity);
|
"{sensor=\"%d\",type=\"DHT\"} %f", i, s_dht_sensor[i]->humidity);
|
||||||
|
|
||||||
for (i=1; i<s_num_dht; i++) {
|
|
||||||
print_chunk(nc, "temperature", "{sensor=\"%d\",type=\"DHT\"} %f", i, s_dht_sensor[i]->temp);
|
|
||||||
print_chunk(nc, "humidity", "{sensor=\"%d\",type=\"DHT\"} %f", i, s_dht_sensor[i]->humidity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) user_data;
|
(void) user_data;
|
||||||
|
@ -8,28 +8,13 @@
|
|||||||
|
|
||||||
static struct mgos_veml6075 *s_veml6075;
|
static struct mgos_veml6075 *s_veml6075;
|
||||||
|
|
||||||
static void print_chunk(struct mg_connection *nc, char *name, char *fmt, ...) {
|
|
||||||
char chunk[500];
|
|
||||||
int chunklen=0;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
snprintf(chunk, sizeof(chunk), "%s%s", name, fmt[0]=='{' ? "" : " ");
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsnprintf(chunk+strlen(chunk), sizeof(chunk)-strlen(chunk), fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
strncat(chunk, "\n", sizeof(chunk));
|
|
||||||
chunklen=strlen(chunk);
|
|
||||||
// LOG(LL_DEBUG, ("Chunk '%s' with length %d", chunk, chunklen));
|
|
||||||
mg_printf(nc, "%X\r\n%s\r\n", chunklen, chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void veml6075_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
static void veml6075_prometheus_metrics(struct mg_connection *nc, void *user_data) {
|
||||||
// BUG -- repeated HELP and TYPE makes Prometheus parser bork :(
|
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"UV", "Ultra Violet light intensity, in sensor counts",
|
"UV", "Ultra Violet light intensity, in sensor counts",
|
||||||
"{band=\"UVA\",type=\"VEML6075\", sensor=\"0\"} %f", mgos_veml6075_getUVA(s_veml6075));
|
"{band=\"UVA\",type=\"VEML6075\", sensor=\"0\"} %f", mgos_veml6075_getUVA(s_veml6075));
|
||||||
print_chunk(nc, "UV", "{band=\"UVB\",type=\"VEML6075\", sensor=\"0\"} %f", mgos_veml6075_getUVB(s_veml6075));
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
|
"UV", "Ultra Violet light intensity, in sensor counts",
|
||||||
|
"{band=\"UVB\",type=\"VEML6075\", sensor=\"0\"} %f", mgos_veml6075_getUVB(s_veml6075));
|
||||||
mgos_prometheus_metrics_printf(nc, GAUGE,
|
mgos_prometheus_metrics_printf(nc, GAUGE,
|
||||||
"UVIndex", "2: Low, 5.5 Moderate, 7.5 High, 10.5 Very High, else Extreme",
|
"UVIndex", "2: Low, 5.5 Moderate, 7.5 High, 10.5 Very High, else Extreme",
|
||||||
"{sensor=\"0\",type=\"VEML6075\"} %f", mgos_veml6075_getUVIndex(s_veml6075));
|
"{sensor=\"0\",type=\"VEML6075\"} %f", mgos_veml6075_getUVIndex(s_veml6075));
|
||||||
|
Reference in New Issue
Block a user