Try   HackMD

Grafana 技巧 防止 Timestamp 與資料庫差8小時

明明 MySQL 資料庫裡的 timestamp 已經是GMT+8的時間了,但在 Grafana 裡又因為時區
而自動幫你+8小時,導致資料的 timestamp 有錯誤,對觀看者的體驗影響很大

1.我們將以下 SQL Query 分別輸入至 MySQL 跟 Grafana

SELECT dt as 'time', val FROM demo ORDER BY dt

在 MySQL 裡自己進行 Query 的結果 :

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

而在Grafana SQL 編輯器下 Query 的結果 :

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

可以發現 Grafana 會因時區自動變更 timestamp 的問題(+8小時)

2.我們將 Query 改為以下寫法 :

SELECT $__timeGroupAlias(dt,$__interval), val FROM demo ORDER BY $__timeGroup(dt,$__interval)

3.就會發現 timestamp 又恢復跟資料庫一樣了!

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

tags: Grafana tips timestamp