grafana dashboard 分享的幾種處理方法


prometheus+grafan 已經成為了大家進行系統監控的標配了,但是很多時候我們為了給予用戶一個方便的dashboard查看系統
的metrics 請求,可以會進行grafan dashboard 的分享,大家的解決方法可能很多,基於grafana 分享的(需要修改配置)也有
基於grafana 的script 的(官方不太推薦的),還有直接基於grafana 的auth_proxy 模式的,個人也比較推薦基於auth_proxy 的
因為我們會通過一個proxy 解決header 傳參,那么我們就可以方便的控制請求了,openresty 是一個很不錯的選擇,以下是一些
實踐以及擴展說明

一張參考圖

 

 

參考配置

  • grafana
    grafana.ini
 
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
;header_property = username
auto_sign_up = true
  • nginx 參考配置
location / {
            proxy_pass http://grafana:3000;
            proxy_set_header X-WEBAUTH-USER dalongrong;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;
            proxy_set_header   X-Forwarded-Proto $scheme;
}
 
 

擴展說明

默認上邊的很簡單,盡管用戶不需要輸入密碼了,但是沒有安全控制了(直接打開瀏覽器就能看dashboard)
盡管官方提供了enable_login_token 但是不是很靈活,一些解決方法

  • 基於openresty 的access_by_lua 階段進行用戶的認證以及請求資源的處理
    很多時候我們嵌入dashboard 的時候需要傳遞參數的,我們可以多附帶一個token的參數,在這個階段我們處理用戶的
    token 以及用戶的機器資源,這樣可以詳細的控制訪問(參考上圖),同時可以動態的進行proxy 以及設置用戶請求頭
  • 基於nginx 的auth_request 模塊
    原理上與openresty 的access_by_lua 類似,基於模塊進行權限的與機器資源的控制,但是從靈活性上不如openresty

說明

以上是grafana auth_proxy +openresty 的一些集成嘗試,實際上,prometheus 也暴露了rest api,我們也可以基於rest api +
charts 開發自己的dashboard 集成方案(更靈活,但是成本比較高了),chartjs-plugin-datasource-prometheus 是一個不錯的
選擇但是目前太簡單了,我們可以自己擴展下

參考資料

https://grafana.com/docs/grafana/latest/reference/scripting/
https://grafana.com/docs/grafana/latest/auth/auth-proxy/#auth-proxy-authentication
https://grafana.com/docs/grafana/latest/reference/share_dashboard/
https://github.com/samber/chartjs-plugin-datasource-prometheus
http://nginx.org/en/docs/http/ngx_http_auth_request_module.html
https://www.cnblogs.com/rongfengliang/p/13150413.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM