web: prometheus metrics support (#2332)

- (experimental) provide generic way to read magnitude values
- expose /api/metrics with values formatted specifically for prometheus, with relay and sensor data
- small tweaks to sensor init

Example config:
```
scrape_configs:
  - job_name: 'espurna'
    metrics_path: '/api/metrics'
    params:
      apikey: ['apikeyapikey']
    static_configs:
      - targets: ['espurna-blabla.lan:80']
```
Where ESPurna side has
```
apiKey => "apikeyapikey"
apiEnabled => "1"
```
This commit is contained in:
Max Prokhorov
2020-08-30 15:26:16 +03:00
committed by GitHub
parent ee58fa6511
commit a496308d97
13 changed files with 212 additions and 82 deletions

View File

@@ -469,10 +469,11 @@ void _onRequest(AsyncWebServerRequest *request){
if (!_onAPModeRequest(request)) return;
// Send request to subscribers
for (unsigned char i = 0; i < _web_request_callbacks.size(); i++) {
bool response = (_web_request_callbacks[i])(request);
if (response) return;
// Send request to subscribers, break when request is 'handled' by the callback
for (auto& callback : _web_request_callbacks) {
if (callback(request)) {
return;
}
}
// No subscriber handled the request, return a 404 with implicit "Connection: close"