65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 Grafana 和 MS SQL 生成饼图

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2018年6月7日

CPOL
viewsIcon

15183

如何使用 Grafana 和 MS SQL 生成饼图。

我为此苦恼了一段时间,希望对某人有所帮助。

在 Grafana 中,如果我们将可视化效果基于 MS SQL 查询,并且将格式设置为时间序列,以便用于图表面板等,那么查询必须返回一个名为“time”的列。

如果我们需要生成图表,例如饼图,而不需要像条形图那样的时间可视化,这可能会使事情变得困难。

一种解决方法是返回一个聚合的 'time' 列,如下所示

SELECT sum(exceptionCounts.hasException), exceptionCounts.title as metric, _
       count(exceptionCounts.time) as time
FROM
(
SELECT sessionnumber, 
        operationResult, 
        startdatetime as time
  FROM  foobarDatabase.dbo.fullSessionLog
  where operationResult like '%xception%' 
    AND $__timeFilter(customDateTimeStamp)
  group by sessionnumber, operationResult
) as exceptionCounts
group by exceptionCounts.title

在上面的例子中,我们执行一个内部查询,返回一个时间戳。在外部查询中,我们可以聚合 - 'count' - 该时间戳。然后饼图应该可以正常工作。

我花了一些时间才弄清楚这一点。希望对您有所帮助!

© . All rights reserved.