Commit c156ea45 authored by Daniele Tafani's avatar Daniele Tafani
Browse files

Added smoothing to Grafana.

parent 16a940c8
smoother smt1 {
interval 10000
;smoother smt1 {
; interval 10000
; minValues 10
; duplicate false
; separator "-"
; exclude "/cpu[0-9]*/"
;
; output {
;
; sensor avg300 {
; mqttsuffix /avg300
; range 300000
; }
;
; sensor avg3600 {
; mqttsuffix /avg3600
; range 3600000
; }
; }
;}
;smoother grafanaFine {
; interval 1000
; minValues 10
; duplicate false
; separator "-"
; exclude "/cpu[0-9]*/"
;
; output {
;
; sensor avg10 {
; mqttsuffix /avg10
; range 10000
; }
;
; }
;}
smoother grafanaCoarse {
interval 1000
minValues 10
duplicate false
separator "-"
......@@ -8,9 +46,9 @@ smoother smt1 {
output {
sensor avg300 {
mqttsuffix /avg300
range 300000
}
mqttsuffix /avg300
range 300000
}
sensor avg3600 {
mqttsuffix /avg3600
......
......@@ -41,3 +41,13 @@ cassandra {
debugLog false
}
analytics {
filter "/test/"
}
operatorPlugins {
operatorPlugin smoothing {
config /Users/di34bap/Projects/dcdb-devel/dcdb/analytics/config/smoothing.conf
}
}
......@@ -29,22 +29,14 @@ restAPI {
}
plugins {
plugin perfevent {
path ./
config
}
plugin procfs {
path ./
config
}
plugin sysfs {
path ./
plugin tester {
config
}
}
operatorPlugins {
operatorPlugin smoothing {
config /Users/di34bap/Projects/dcdb-devel/dcdb/analytics/config/smoothing.conf
}
}
......@@ -3,7 +3,7 @@ global {
}
template_group def1 {
interval 1000
interval 10
minValues 3
startValue 0
}
......
......@@ -206,13 +206,38 @@ void::RestAPI::POST_query(endpointArgs) {
for(auto& sensorName : sensors) {
DCDB::Sensor sensor(_connection, sensorName);
std::list<DCDB::SensorDataStoreReading> results;
DCDB::SensorDataStore sensorDataStore(_connection);
_sensorConfig->getPublicSensorByName(ps,sensorName.c_str());
if(ps.interval && !ps.operations.empty()) {
//Estimate the number of requested datapoints, for all sensors' data plotted in the panel. The number is calculated assuming all sensors plotted on the same panel have the same sampling period. If we exceed the maximum, then apply smoothing.
uint64_t grafanaInterval = end.getRaw() - start.getRaw();
if((int)((grafanaInterval/ps.interval) * sensors.size()) > MAX_DATAPOINTS) {
//Choose a smoother
if(grafanaInterval/10000000000 < MAX_DATAPOINTS &&
ps.operations.find("-avg10") != ps.operations.end())
sensorName += "-avg10";
else if(grafanaInterval/300000000000 < MAX_DATAPOINTS &&
ps.operations.find("-avg300") != ps.operations.end())
sensorName += "-avg300";
else if(ps.operations.find("-avg3600") != ps.operations.end())
//Hourly averages should be fine for intervals of years.
sensorName += "-avg3600";
}
}
//We need the Sensor ID, since smoothed sensors are not published.
DCDB::SensorId sid(sensorName);
sid.setRsvd(start.getWeekstamp());
//Shoot the query for this sensor.
std::list<DCDB::SensorDataStoreReading> results;
sensor.query(results, start, end, DCDB::AGGREGATE_NONE);
sensorDataStore.query(results, sid, start, end, DCDB::AGGREGATE_NONE);
//Format the output for the response to Grafana.
std::string datapoints = "[";
for (auto& r : results)
......
......@@ -43,6 +43,8 @@
#include <boost/asio.hpp>
#define MAX_DATAPOINTS 100000
/**
* @brief Class providing a RESTful API to Grafana via network (HTTPs only).
*
......
......@@ -15,9 +15,9 @@ hierarchy {
restAPI {
address 127.0.0.1:8081
certificate ../../deps/openssl-1.1.1c/test/certs/ca-cert.pem
privateKey ../../deps/openssl-1.1.1c/test/certs/ca-key.pem
dhFile ../../deps/openssl-1.1.1c/crypto/dh/dh2048.pem
certificate /Users/di34bap/Projects/dcdb-devel/deps/openssl-1.1.1c/test/certs/ca-cert.pem
privateKey /Users/di34bap/Projects/dcdb-devel/deps/openssl-1.1.1c/test/certs/ca-key.pem
dhFile /Users/di34bap/Projects/dcdb-devel/deps/openssl-1.1.1c/crypto/dh/dh2048.pem
user user1 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment