From ced20d7fc3ee98005ea8a2d09d2a0d99361ff0a4 Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Thu, 18 Sep 2014 18:01:01 +0200 Subject: add /api/list --- datastore-leveldb/data/_placeholder | 0 datastore-leveldb/src/db.cpp | 18 ++++ datastore-leveldb/src/db.h | 3 + datastore-leveldb/src/server.cpp | 3 + datastore-leveldb/src/web.cpp | 22 ++++ datastore-leveldb/src/web.h | 3 + datastore-leveldb/wwwroot_ebus/css/stylesheet.css | 10 +- datastore-leveldb/wwwroot_ebus/src/ebus.js | 123 +++++++++------------- 8 files changed, 104 insertions(+), 78 deletions(-) delete mode 100644 datastore-leveldb/data/_placeholder diff --git a/datastore-leveldb/data/_placeholder b/datastore-leveldb/data/_placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/datastore-leveldb/src/db.cpp b/datastore-leveldb/src/db.cpp index e307535..ce57772 100644 --- a/datastore-leveldb/src/db.cpp +++ b/datastore-leveldb/src/db.cpp @@ -5,6 +5,10 @@ #include #include #include +extern "C" { +#include +} + static std::unordered_map dbs; static std::mutex getDBmutex; @@ -72,3 +76,17 @@ void db_close() { std::cout << std::endl; } +std::list * db_list() { + std::list * list = new std::list(); + struct dirent * dp; + DIR* dirp = opendir("data"); + if (dirp != NULL) { + while ((dp = readdir(dirp)) != NULL) { + if (dp->d_name[0] != '.') + list->push_back(std::string(dp->d_name)); + } + (void)closedir(dirp); + } + return list; +} + diff --git a/datastore-leveldb/src/db.h b/datastore-leveldb/src/db.h index 5e31b00..ed03d4b 100644 --- a/datastore-leveldb/src/db.h +++ b/datastore-leveldb/src/db.h @@ -2,6 +2,7 @@ #define HAVE_DB_H #include +#include leveldb::DB *db_get(std::string& name); @@ -9,6 +10,8 @@ bool db_insert(std::string& name, const uint64_t timestamp, std::string& value); void db_close(); +std::list * db_list(); + std::string db_make_key(const uint64_t timestamp); #endif /*HAVE_DB_H*/ diff --git a/datastore-leveldb/src/server.cpp b/datastore-leveldb/src/server.cpp index 83f4cdb..3fc0181 100644 --- a/datastore-leveldb/src/server.cpp +++ b/datastore-leveldb/src/server.cpp @@ -95,6 +95,9 @@ int main(int argc, char **argv) { web_handler.push_front(std::make_pair( web_handle_api_range_size_R, web_handle_api_range_size)); + web_handler.push_front(std::make_pair( + web_handle_api_list_R, + web_handle_api_list)); // Signals: handle C-c struct sigaction action; diff --git a/datastore-leveldb/src/web.cpp b/datastore-leveldb/src/web.cpp index 503e3aa..3485539 100644 --- a/datastore-leveldb/src/web.cpp +++ b/datastore-leveldb/src/web.cpp @@ -177,3 +177,25 @@ void web_handle_api_range_size(const boost::cmatch &match, struct mg_connection mg_write(conn, outbuf.str().c_str(), outbuf.tellp()); delete it; } + + +const boost::regex web_handle_api_list_R( + "/api/list"); +void web_handle_api_list(const boost::cmatch &match, struct mg_connection *conn) { + reply_header(conn, true, "OK", "Content-Type: application/json\r\n\r\n"); + mg_write(conn, "[", 1); + + std::list * list = db_list(); + for (std::list::iterator it = list->begin(); + it != list->end(); ++it) { + if (it != list->begin()) { + mg_write(conn, ",\"", 2); + } else { + mg_write(conn, "\"", 1); + } + mg_write(conn, (*it).c_str(), (*it).size()); + mg_write(conn, "\"\n", 2); + } + delete(list); + mg_write(conn, "]", 1); +} diff --git a/datastore-leveldb/src/web.h b/datastore-leveldb/src/web.h index a9d4593..9ee2cdd 100644 --- a/datastore-leveldb/src/web.h +++ b/datastore-leveldb/src/web.h @@ -18,4 +18,7 @@ void web_handle_api_range(const boost::cmatch &match, struct mg_connection *conn extern const boost::regex web_handle_api_range_size_R; void web_handle_api_range_size(const boost::cmatch &match, struct mg_connection *conn); +extern const boost::regex web_handle_api_list_R; +void web_handle_api_list(const boost::cmatch &match, struct mg_connection *conn); + #endif/*HAVE_WEB_H*/ diff --git a/datastore-leveldb/wwwroot_ebus/css/stylesheet.css b/datastore-leveldb/wwwroot_ebus/css/stylesheet.css index 1031054..9166d34 100644 --- a/datastore-leveldb/wwwroot_ebus/css/stylesheet.css +++ b/datastore-leveldb/wwwroot_ebus/css/stylesheet.css @@ -6,19 +6,23 @@ body { position: absolute; height: calc(100% - 160px); top: 2px; - left: 5px; - right: 30px; + left: 10px; + right: 45px; } #legend { position: absolute; height: 150px; overflow-y: scroll; - right: 10px; + left: 40px; top: 10px; background: rgba(240,240,240,0.55); } +#legend select { + width: 160px; +} + #overview { position: absolute; top: calc(100% - 150px); diff --git a/datastore-leveldb/wwwroot_ebus/src/ebus.js b/datastore-leveldb/wwwroot_ebus/src/ebus.js index a76c62e..fae08cd 100644 --- a/datastore-leveldb/wwwroot_ebus/src/ebus.js +++ b/datastore-leveldb/wwwroot_ebus/src/ebus.js @@ -17,7 +17,7 @@ $(document).ready(function(){ var to = d.now; var fromOverview = d.now - 1.5 * d.month; var toOverview = d.now; - var numberOfValues = jQuery("#ebusgraph").width(); + var numberOfValues = function() { return jQuery("#ebusgraph").width(); }; var datasetDetail = []; var datasetOverview = []; @@ -25,11 +25,11 @@ $(document).ready(function(){ var plotOverview = null; var plotDetail = null; var indexFound = null; - var sensorConfigList = [ + var defaultSensorConfigList = [ { "name":"heizkreisregler10.betriebsdatenRegler1.kesselTemperatur", "description":"Kessel Temperatur", - "values":Math.ceil(jQuery("#ebusgraph").width()/8), + "values":Math.ceil(jQuery("#ebusgraph").width()/6), "lines":{fill: true, lineWidth: 1, fillColor: "rgba(80,40,100, 0.05)"}, "show":true, "color":"rgb(80,40,100)" @@ -50,14 +50,6 @@ $(document).ready(function(){ "show":false, "color":"rgba(252,133,34,0.5)" }, -{ - "name":"feuerungsautomat1.betriebsdatenRegler1.aussenTemperatur", - "description":"Aussentemperatur (ebus)", - "values":Math.ceil(jQuery("#ebusgraph").width()/4), - "show":false, - "lines":{fill: true, fillColor: "rgba(250, 250, 0, 0.2)"}, - "color":"rgb(250,250,0)" -}, { "name":"heizkreisregler10.betriebsdatenRegler1.boilerTemperatur", "description":"Boilertemperatur", @@ -69,42 +61,10 @@ $(document).ready(function(){ "name":"de.wettermichel.temperature", "description":"Temperatur (Celsius) (wettermichel)", "show":false, - "values":Math.ceil(jQuery("#ebusgraph").width()/16), + "values":Math.ceil(jQuery("#ebusgraph").width()/4), "lines":{fill: true, fillColor: "rgba(132, 181, 0, 0.2)"}, "color":"#84b500" }, -{ - "name":"de.wettermichel.rainToday", - "description": "Regen heute (mm) (wettermichel)", - "show":false, - "values":Math.ceil(jQuery("#ebusgraph").width()/16), - "lines":{fill: true, fillColor: "rgba(10, 18, 250, 0.2)"}, - "color":"blue" -}, -{ - "name":"de.wettermichel.humidity", - "description": "Luftfeuchtigkeit (%) (wettermichel)", - "show": false, - "values":Math.ceil(jQuery("#ebusgraph").width()/8), - "lines":{fill: false, lineWidth:1}, - "color":"rgb(100,100,200)" -}, -{ - "name":"adsl.in.percent", - "description": "ADSL In/Download", - "show":false, - "values":Math.ceil(jQuery("#ebusgraph").width()/8), - "lines":{fill: false, lineWidth:1}, - "color":"black", -}, -{ - "name":"adsl.out.percent", - "description": "ADSL Out/Upload", - "show":false, - "values":Math.ceil(jQuery("#ebusgraph").width()/8), - "lines":{fill: false, lineWidth:1}, - "color":"gray", -}, { "name":"dockstar.load5", "description":"System Load (5m, *10)", @@ -113,20 +73,6 @@ $(document).ready(function(){ "color":"blue", "mapFunc":function(d){return [d[0],d[1]*10]} }, -{ - "name":"dockstar.fs.ROOT", - "description":"Filesystem / Free (%)", - "lines":{lineWidth:1}, - "show":false, - "color":"black", -}, -{ - "name":"yves.laserjet.tonerstatus", - "description":"Yves Tonerstatus (%)", - "lines":{lineWidth:1}, - "show":false, - "color":"black", -}, { "name":"dockstar.internet.latency_ns", "description":"Internet latency in ms", @@ -136,6 +82,7 @@ $(document).ready(function(){ "mapFunc":function(d){return [d[0],d[1]/1000/1000]} }, ]; + var sensorConfigList = JSON.parse(window.localStorage.getItem("ebusConfig")) || defaultSensorConfigList; var pickSensorConfig = function(sensorname) { var sensorConfigFound; @@ -155,7 +102,7 @@ var replot = function() { plotDetail.draw(); } -var insertLegend = function() { +var redrawLegend = function() { $("#legend").children().remove(); var table = jQuery(""); for (var i = 0; i < sensorConfigList.length; i++) { @@ -182,6 +129,32 @@ var insertLegend = function() { table.append(row); } + $("#legend").append($("