diff --git a/Schema/lancom-throughput-query.sql b/Schema/lancom-throughput-query.sql new file mode 100644 index 0000000..d236a40 --- /dev/null +++ b/Schema/lancom-throughput-query.sql @@ -0,0 +1,25 @@ +select + UNIX_TIMESTAMP(g1.ts) as time_sec, + g1.description as metric, + non_negative_value( + ((g1.value - (select g2.value from grafana_v g2 where g2.ts < g1.ts and g2.description = metric order by ts desc limit 1)) / (UNIX_TIMESTAMP(g1.ts) - UNIX_TIMESTAMP((select g3.ts from grafana_v g3 where g3.ts < g1.ts and g3.description = metric order by ts desc limit 1)))), + ((4294967296 + g1.value - (select g2.value from grafana_v g2 where g2.ts < g1.ts and g2.description = metric order by ts desc limit 1)) / (UNIX_TIMESTAMP(g1.ts) - UNIX_TIMESTAMP((select g3.ts from grafana_v g3 where g3.ts < g1.ts and g3.description = metric order by ts desc limit 1)))) + ) as value +from grafana_v g1 +where g1.description = 'VDSL In-gateway' +order by g1.ts asc; + + + +delimiter // +create or replace function non_negative_value(a double, b double) returns double +begin + if (a >= 0) then + return a; + else + return b; + end if; +end// +delimiter ; + +grant execute on function statsdb.non_negative_value to 'grafana'@'%'; diff --git a/Schema/view.sql b/Schema/view.sql index af583d6..3f1d9ca 100644 --- a/Schema/view.sql +++ b/Schema/view.sql @@ -11,3 +11,18 @@ create or replace view grafana_v as di.id = ddi.dataitem and da.devicedataitem = ddi.id; + +create or replace view grafana_plain_v as + select concat(di.description, '-', de.description) as description, + da.ts as ts, + da.value as value, + de.description as device + from device_t de, + dataitem_t di, + devicedataitem_t ddi, + collecteddata_t da + where de.id = ddi.device and + di.id = ddi.dataitem and + da.devicedataitem = ddi.id; + +