解决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做了一次转换。

 

posted @   mmgithub123  阅读(10227)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示