解決Prometheus時區問題,改成本地時間上海的時區


 

官方Prometheus鏡像,使用的不是咱們上海的時區,我們可以用上海時區文件創建一個configmap,然后掛載到啟動的Prometheus容器里:

kubectl create configmap prometheus-time-zone --from-file=/usr/share/zoneinfo/Asia/Shanghai
然后掛載:

volumeMounts:
- name: prometheus-time-zone
mountPath: /etc/localtime
subPath: Shanghai



然后可以把容器里的時區改成上海時區,東八區


用date 驗證時間是本地時間了

 

但這個只是改了Prometheus容器得本地時區文件而已。centos系統 就是/etc/localtime   Ubuntu是/etc/timezone   

但是Prometheus 是在代碼里,統一做得UTC轉換

類似這樣:

 

所以機器上(容器里)的時區並不起作用。

 

至於為什么這么做,官方給了說明:

Can I change the timezone? Why is everything in UTC?

To avoid any kind of timezone confusion, especially when the so-called daylight saving time is involved, we decided to exclusively use Unix time internally and UTC for display purposes in all components of Prometheus. A carefully done timezone selection could be introduced into the UI. Contributions are welcome. See issue #500 for the current state of this effort.

 

github  討論:

https://github.com/prometheus/prometheus/issues/500

 

所以想做時間本地化,就直接在外部程序做好了。

其實官方也是這樣做的:

 

這里的use local time 就是輸出后,前端js做了一次轉換。

 


免責聲明!

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



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