Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to expose prometheus metrics #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/BrewPiLess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ extern "C" {

#define HUMIDITY_CONTROL_PATH "/rh"

#ifdef METRICS
#define METRICS_PATH "/metrics"
#endif

const char *public_list[]={
"/bwf.js",
"/brewing.json"
Expand Down Expand Up @@ -607,6 +611,22 @@ class BrewPiWebHandler: public AsyncWebHandler
+String("}");
request->send(200,"application/json",json);
}
#ifdef METRICS
else if (request->method() == HTTP_GET && request->url() == METRICS_PATH){
uint8_t mode, state;
float beerSet, beerTemp, fridgeTemp, fridgeSet, roomTemp;
brewPi.getAllStatus(&state, &mode, &beerTemp, &beerSet, &fridgeTemp, &fridgeSet, &roomTemp);
#define TEMPor0(a) (IS_FLOAT_TEMP_VALID(a)? String(a):String("0"))
String instance_string = String("{instance=\"" + String(syscfg->titlelabel) + "\"} ");
String body =
String("brewpi_beer_temp" + instance_string + TEMPor0(beerTemp) + "\n") +
String("brewpi_beer_set" + instance_string + TEMPor0(beerSet) + "\n") +
String("brewpi_fridge_temp" + instance_string + TEMPor0(fridgeTemp) + "\n") +
String("brewpi_fridge_set" + instance_string + TEMPor0(fridgeSet) + "\n") +
String("brewpi_room_temp" + instance_string + TEMPor0(roomTemp) + "\n");
request->send(200,"text/plain",body);
}
#endif
#ifdef ENABLE_LOGGING
else if (request->url() == LOGGING_PATH){
if(request->method() == HTTP_POST){
Expand Down Expand Up @@ -783,6 +803,9 @@ class BrewPiWebHandler: public AsyncWebHandler
|| request->url() == GETSTATUS_PATH
|| request->url() == BEER_PROFILE_PATH
|| request->url() == MQTT_PATH
#ifdef METRICS
|| request->url() == METRICS_PATH
#endif
#ifdef ENABLE_LOGGING
|| request->url() == LOGGING_PATH
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@
#define FileSystem SPIFFS
#endif

#ifndef METRICS
#define METRICS true
#endif

#if ESP32
// when read logs, ESP32, or AsyncTCP to be exact, would request 5623 bytes
Expand Down