Grafana 系列 (7):圖表是否可以数据追踪 (drill down)?(转)

文章出处:https://medium.com/@maiccaejfeng/grafana-%E7%B3%BB%E5%88%97-7-%E5%9C%96%E8%A1%A8%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5-drill-down-f5a831af6b6e

似乎目前沒有此效果,僅能連到 dashboard 連結,丟變數過去。


目標

需求是,例如有個長條圖,點了其中一個長條,例如點了 Chrome:

圖片來源:Highcharts (https://www.highcharts.com/demo/column-drilldown)

然後就會 drill down 變成 Chrome 細部資料的長條圖:

圖片來源:Highcharts (https://www.highcharts.com/demo/column-drilldown)

目標是看看 Grafana 的圖表 panel 是否可以做到這樣的效果。


Table 的 Render value as link 用法

根據這裡「How to add drill down/detail link to the metrics in Grafana」的討論(2017 年),是說 Grafana 官方沒有這功能的。只有加上 link,然後連結到別的地方這樣而已。

圖片來源:https://community.grafana.com/t/how-to-add-drill-down-detail-link-to-the-metrics-in-grafana/1568/2

實際來測試一下他說的加上 link 的功能。例如我有一個根據 Source_IP 欄位跟 Destination_IP 欄位分類的 table:

編輯 panel。在 Visualization 頁籤編輯 Source_IP 的 Column Styles 如下(https://www.google.com/search?q=${__cell}),可讓使用者點擊 Source_IP 的值之後,在新視窗顯示 google 搜尋該值的結果:

Source_IP 變成可點擊的超連結:

點擊後在新視窗顯示 google 搜尋該 Source_IP 值的結果:

很顯然的,超連結導到 google search 的頁面不符合需求。但是可以連結到另外一個 Grafana dashboard,例如把另外一個 Grafana dashboard 的連結貼上去,就可以連了:

根據這裡「Drill-down/Link to Another Panel, not Another Dashboard」的討論(2018 年),還是一樣沒有這功能,換成建議可以 Update current dashboard template variable via cell links(2017 年)。

實際的測試一下,將剛剛的設定修改成帶變數 $Filters 的設定(http://127.0.0.1:3000/d/4_mGHJjWz/填入儀表板名稱?orgId=1&var-Filters=Source_IP.keyword%7C%3D%7C${__cell}),主要是在 dashboard 的連結後面加上「var-Filters=Source_IP.keyword%7C%3D%7C${__cell}」,其中 Filters 是變數名稱,Source_IP.keyword 是欄位名稱,${__cell} 表示這個欄位的值:

那麼在點擊 Source_IP 是 192.168.70.5 這個超連結的時候,dashboard 畫面可以換成條件是 Source_IP 的值是 192.168.70.5 的畫面,如下面兩張圖:

 

結論

Grafana 看起來沒有如一開始目標所幻想的圖表 drill down 的功能,僅能透過連結到另外一個儀表板、然後丟變數過去、讓另外一個畫面呈現用該變數查詢後的結果。如下面兩張圖所示,點擊某個 Source_IP,連到另外一個資料是跟該 Source_IP 有關的 dashboard:

 

回到上一頁

那如果要「回到上一頁」,則可以使用 Text Panel,用 markdown 語法做一個「回到上一頁」的超連結,例如:「[回到上一頁](http://127.0.0.1:3000/d/rHElABCWk/source-ip-de-fen-lei?orgId=1)」這樣:

就可以點擊「回到上一頁」的超連結,回到上一頁了:

 

差不多就這樣:)

 

posted @ 2020-07-06 15:24  20988902  阅读(757)  评论(0编辑  收藏  举报