mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-03 17:30:11 +00:00
Fix totals in aggregated timeseries
This commit is contained in:
parent
f8653aec87
commit
33a26d4ff5
1 changed files with 14 additions and 5 deletions
|
|
@ -430,12 +430,17 @@ function driver:query(schema, tstart, tend, tags, options)
|
|||
|
||||
if stats.total ~= nil then
|
||||
-- override total and average
|
||||
-- NOTE: using -1 to avoid overflowing into the next hour
|
||||
local stats_query = "(SELECT ".. table.concat(schema._metrics, " + ") .. ' AS value FROM ' .. query_schema ..
|
||||
' ' ..getWhereClause(tags, tstart, tend, ternary((data_type == ts_common.metrics.derivate), -1, unaligned_offset)) .. ")"
|
||||
' ' ..getWhereClause(tags, tstart, tend, ternary((data_type == ts_common.metrics.derivative), -1, unaligned_offset)) .. ")"
|
||||
if data_type == ts_common.metrics.counter then
|
||||
stats_query = "(SELECT NON_NEGATIVE_DIFFERENCE(value) as value FROM " .. stats_query .. ")"
|
||||
end
|
||||
stats_query = "SELECT SUM(value) FROM " .. stats_query
|
||||
stats_query = "SELECT SUM(value) as value FROM " .. stats_query
|
||||
|
||||
if data_type == ts_common.metrics.derivative then
|
||||
stats_query = "SELECT (value * ".. time_step ..") as value FROM (" .. stats_query .. ")"
|
||||
end
|
||||
|
||||
stats = table.merge(stats, self:_performStatsQuery(stats_query, tstart, tend))
|
||||
end
|
||||
|
|
@ -695,7 +700,7 @@ function driver:topk(schema, tags, tstart, tend, options, top_tags)
|
|||
if data_type == "counter" then
|
||||
derivate_metrics[idx] = 'NON_NEGATIVE_DIFFERENCE('.. metric .. ') as ' .. metric
|
||||
else -- derivative
|
||||
derivate_metrics[idx] = metric
|
||||
derivate_metrics[idx] = '('.. metric .. ' * '.. raw_step ..') as ' .. metric
|
||||
end
|
||||
sum_metrics[idx] = 'SUM('.. metric .. ') as ' .. metric
|
||||
end
|
||||
|
|
@ -712,12 +717,16 @@ function driver:topk(schema, tags, tstart, tend, options, top_tags)
|
|||
-- Aggregate into 1 metric and filter
|
||||
local base_query = '(SELECT '.. top_tag ..', (' .. table.concat(schema._metrics, " + ") ..') AS "value", '..
|
||||
all_metrics .. ' FROM '.. query_schema ..
|
||||
' '.. getWhereClause(tags, tstart, tend, unaligned_offset) ..')'
|
||||
' '.. getWhereClause(tags, tstart, tend, ternary((data_type == ts_common.metrics.derivative), -1, unaligned_offset)) ..')'
|
||||
|
||||
-- Calculate difference between counter values
|
||||
if data_type == "counter" then
|
||||
base_query = '(SELECT NON_NEGATIVE_DIFFERENCE(value) as value, '.. table.concat(derivate_metrics, ", ") ..
|
||||
' FROM ' .. base_query .. " GROUP BY ".. top_tag ..")"
|
||||
else
|
||||
-- derivative
|
||||
base_query = '(SELECT (value * '.. raw_step ..') as value, '.. table.concat(derivate_metrics, ", ") ..
|
||||
' FROM ' .. base_query .. " GROUP BY ".. top_tag ..")"
|
||||
end
|
||||
|
||||
-- Sum the traffic
|
||||
|
|
@ -1108,7 +1117,7 @@ local function getCqQuery(dbname, tags, schema, source, dest, step, dest_step, r
|
|||
CREATE CONTINUOUS QUERY "iface:packets__1h" ON ntopng
|
||||
RESAMPLE FOR 2h
|
||||
BEGIN
|
||||
SELECT SUM(packets) as packets
|
||||
SELECT (SUM(packets)/3600) as packets
|
||||
INTO "1h"."iface:packets" FROM (
|
||||
SELECT NON_NEGATIVE_DIFFERENCE(packets) as packets
|
||||
FROM "autogen"."iface:packets"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue