我有有关写入 InfluxDB 的错误的数据(示例已简化)。
time | error | some_unique_data
--------|---------|--------------------
<time> | hello 1 | some unique data...
<time> | hello 2 | some unique data...
<time> | hello 2 | some unique data...
<time> | hello 3 | some unique data...
Run Code Online (Sandbox Code Playgroud)
我可以编写以下查询来查看 Grafana 中最常见错误的排序列表:
SELECT COUNT("some_unique_data") FROM "my_measument" WHERE $timeFilter GROUP BY error
Run Code Online (Sandbox Code Playgroud)
这使:
| error | count
|---------|-------
| hello 2 | 2
| hello 1 | 1
| hello 3 | 1
Run Code Online (Sandbox Code Playgroud)
我缺少的是向我显示每个错误的影响的列,如下所示:
| error | count | impact
|---------|----------------
| hello 2 | 2 | 50%
| hello 1 | 1 | 25%
| hello 3 | 1 | 25%
Run Code Online (Sandbox Code Playgroud)
我应该在查询中添加什么才能使该impact
字段正常工作?
Here is a useful answer, but unfortunately it doesn't solve your issue.
In your example:
| error | count
|---------|-------
| hello 2 | 2
| hello 1 | 1
| hello 3 | 1
Run Code Online (Sandbox Code Playgroud)
you've used GROUP BY "error"
to get the count of each error
, so once you did this you don't have access to the full count anymore, so you must do it before GROUP BY
.
Run Code Online (Sandbox Code Playgroud)SELECT COUNT(*) AS full_count, "some_unique_data" FROM "my_measument" WHERE $timeFilter
in order to get the full number of records because you can't use SELECT COUNT(), "field_name" FROM ...
So, getting the full count before doing GROUP BY
isn't possible.
SELECT "fields_count" / SUM("fields_count") AS not_able_to_use_SUM_with_field , "error" FROM (
SELECT COUNT("some_unique_data") AS fields_count AS fields_sum FROM "my_measument" WHERE $timeFilter GROUP BY "error"
)
Run Code Online (Sandbox Code Playgroud)
This previous query isn't working apparently. Then what to do?
Sorry, You can do Nothing :/
Here is another link to the documentation.
归档时间: |
|
查看次数: |
4380 次 |
最近记录: |