diff --git a/console/line.go b/console/line.go index 52275d16..ccdc9aad 100644 --- a/console/line.go +++ b/console/line.go @@ -134,16 +134,18 @@ func (input graphLineHandlerInput) toSQL1(axis int, options toSQL1Options) strin dimensionsInterpolate = "emptyArrayString()" } + // With withStr := "" if !options.skipWithClause { with := []string{fmt.Sprintf("source AS (%s)", input.sourceSelect())} if len(dimensions) > 0 { with = append(with, fmt.Sprintf( - "rows AS (SELECT %s FROM source WHERE %s GROUP BY %s ORDER BY SUM(Bytes) DESC LIMIT %d)", + "rows AS (SELECT %s FROM source WHERE %s GROUP BY %s ORDER BY SUM(%s) DESC LIMIT %d)", strings.Join(dimensions, ", "), where, strings.Join(dimensions, ", "), + metricForTopSort(input.Units), input.Limit)) } if len(with) > 0 { diff --git a/console/query.go b/console/query.go index 2647d8b4..769f009a 100644 --- a/console/query.go +++ b/console/query.go @@ -32,3 +32,13 @@ func (c *Component) fixQueryColumnName(name string) string { } return "" } + + +func metricForTopSort(inputUnit string) string { + switch inputUnit { + case "pps": + return "Packets" + default: + return "Bytes" + } +} \ No newline at end of file diff --git a/console/sankey.go b/console/sankey.go index e844ce57..e2af3a0e 100644 --- a/console/sankey.go +++ b/console/sankey.go @@ -59,10 +59,11 @@ func (input graphSankeyHandlerInput) toSQL() (string, error) { fmt.Sprintf("source AS (%s)", input.sourceSelect()), fmt.Sprintf(`(SELECT MAX(TimeReceived) - MIN(TimeReceived) FROM source WHERE %s) AS range`, where), fmt.Sprintf( - "rows AS (SELECT %s FROM source WHERE %s GROUP BY %s ORDER BY SUM(Bytes) DESC LIMIT %d)", + "rows AS (SELECT %s FROM source WHERE %s GROUP BY %s ORDER BY SUM(%s) DESC LIMIT %d)", strings.Join(dimensions, ", "), where, strings.Join(dimensions, ", "), + metricForTopSort(input.Units), input.Limit), } diff --git a/console/sankey_test.go b/console/sankey_test.go index 913667db..2defdbe7 100644 --- a/console/sankey_test.go +++ b/console/sankey_test.go @@ -107,7 +107,7 @@ ORDER BY xps DESC WITH source AS (SELECT * FROM {{ .Table }} SETTINGS asterisk_include_alias_columns = 1), (SELECT MAX(TimeReceived) - MIN(TimeReceived) FROM source WHERE {{ .Timefilter }}) AS range, - rows AS (SELECT SrcAS, ExporterName FROM source WHERE {{ .Timefilter }} GROUP BY SrcAS, ExporterName ORDER BY SUM(Bytes) DESC LIMIT 5) + rows AS (SELECT SrcAS, ExporterName FROM source WHERE {{ .Timefilter }} GROUP BY SrcAS, ExporterName ORDER BY SUM(Packets) DESC LIMIT 5) SELECT {{ .Units }}/range AS xps, [if(SrcAS IN (SELECT SrcAS FROM rows), concat(toString(SrcAS), ': ', dictGetOrDefault('asns', 'name', SrcAS, '???')), 'Other'),