Add Prometheus timer.
This timer will periodically upload Prometheus information to the push gateway. By default, every `sensors.pushgateway_period` (10) seconds.
This commit is contained in:
1
mos.yml
1
mos.yml
@ -18,6 +18,7 @@ config_schema:
|
|||||||
- ["sensors", "o", {title: "Sensors settings"}]
|
- ["sensors", "o", {title: "Sensors settings"}]
|
||||||
- ["sensors.dht_gpio", "s", "13,12,14", {title: "Comma Separated list of GPIO pins to enable DHT22/AM2302 sensors on"}]
|
- ["sensors.dht_gpio", "s", "13,12,14", {title: "Comma Separated list of GPIO pins to enable DHT22/AM2302 sensors on"}]
|
||||||
- ["sensors.dht_period", "i", 3, {title: "Sample period in seconds for DHT sensors"}]
|
- ["sensors.dht_period", "i", 3, {title: "Sample period in seconds for DHT sensors"}]
|
||||||
|
- ["sensors.pushgateway_period", "i", 10, {title: "Period in seconds for Prometheus Pushgateway POSTs"}]
|
||||||
- ["prometheus.pushgateway", "prometheus.example.net:9091"]
|
- ["prometheus.pushgateway", "prometheus.example.net:9091"]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
#include "mgos_config.h"
|
#include "mgos_config.h"
|
||||||
|
#include "mgos_prometheus_metrics.h"
|
||||||
#include "mgos_prometheus_sensors.h"
|
#include "mgos_prometheus_sensors.h"
|
||||||
|
|
||||||
void dht_init();
|
void dht_init();
|
||||||
|
|
||||||
|
static void pushgateway_timer(void *user_data) {
|
||||||
|
mgos_prometheus_metrics_push(MGOS_APP, mgos_sys_config_get_device_id());
|
||||||
|
(void) user_data;
|
||||||
|
}
|
||||||
|
|
||||||
bool mgos_prometheus_sensors_init(void) {
|
bool mgos_prometheus_sensors_init(void) {
|
||||||
dht_init();
|
dht_init();
|
||||||
|
if (mgos_sys_config_get_sensors_pushgateway_period()>0)
|
||||||
|
mgos_set_timer(mgos_sys_config_get_sensors_pushgateway_period()*1000, true, pushgateway_timer, NULL);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user