解决Prometheus时区问题,改成本地时间上海的时区
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
解决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 for the current state of this effort.
github 讨论:
https:///prometheus/prometheus/issues/500
所以想做时间本地化,就直接在外部程序做好了。
其实官⽅也是这样做的:
这⾥的use local time 就是输出后,前端js做了⼀次转换。