真正解决prometheus Error on ingesting samples that are too old or are too far into the future的问题

真正解决prometheus Error on ingesting samples that are too old or are too far into the future的问题

看了很多国内的论坛,完全在误导,不去看清问题真相

一、问题引出

突然有天就数据查询失败,异常如下

level=warn ts=2020-10-09T02:29:06.700Z caller=scrape.go:1216 component="scrape manager" scrape_pool=service.server target=http://192.168.1.22:9100/metrics msg="Error on ingesting samples that are too old or are too far into the future" num_dropped=929
level=warn ts=2020-10-09T02:29:06.700Z caller=scrape.go:987 component="scrape manager" scrape_pool=service.server target=http://192.168.1.22:9100/metrics msg="appending scrape report failed" err="out of bounds"

二、什么原因呢

ts=2020-10-09T02:29:06.700Z,有博客说可以看到日志的时间戳与当前时间戳提前了8个小时,其实并不是提前了8小时,看到个8就知道是时区问题,UTC时间就这样。
但是还必须得用UTC,什么原因官方说夏令时时间有误差,还是不太懂,反正就必须用UTC,但其实用了UTC也并不影响我们数据保存和读取
这里真正的原因是,可能你的系统有断电导致时间重置了,或者有往前改过系统时间,prometheus在同一时间点记录了不同的数据

三、如何解决?

那还能怎样?删数据呗,但我认为不能完全解决问题,等完美解决我再在下面更新!
具体就是删除prometheus底下的data目录里面的数据

昨天晚上发现是运维人员打包的时候,把其他服务器上的data目录下的数据也一并复制到了另一台服务器下,于是就发生了这类问题。所以还是老办法,删除data目录,以后再复现再回来分析i