mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
Use unit for sorting topX instead of always using bytes
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user