使用Grafana计数器来可视化天气数据

huangapple go评论94阅读模式
英文:

Using grafana counter to visualize weather data

问题

我正在尝试使用Grafana可视化我的天气数据。我已经完成了Prometheus部分,现在我面临一个问题已经困扰我很长时间。

我创建了一个计数器,每五分钟添加一次室内温度。

var tempIn = prometheus.NewCounter(prometheus.CounterOpts{
	Name: "tempin",
	Help: "Temperature indoor",
})

for {
   tempIn.Add(station.Body.Devices[0].DashboardData.Temperature)
   time.Sleep(time.Second*300)
}

我该如何可视化这些数据,以显示当前温度并将其存储无限长时间,以便我可以在1年后查看,就像正常的图表一样?

tempin{instance="localhost:9999"}只会显示累加的温度,对我来说没有用。我需要当前的温度,而不是累加的温度。我还尝试了rate(tempin{instance="localhost:9999"}[5m])

如何解决这个问题?

英文:

I'm trying to visualize my weather data using grafana. I've already made the prometheus part and now I face an issue that hunts me for quite a while.

I created an counter that adds temperature indoor every five minutes.

var tempIn = prometheus.NewCounter(prometheus.CounterOpts{
	Name: "tempin",
	Help: "Temperature indoor",
})

for {
   tempIn.Add(station.Body.Devices[0].DashboardData.Temperature)
   time.Sleep(time.Second*300)
}

How can I now visualize this data that it shows current temperature and stores it for unlimited time so I can look at it even 1 year later like an normal graph?

tempin{instance="localhost:9999"} will only display added up temperature so its useless for me. I need the current temperature not the added up one. I also tried rate(tempin{instance="localhost:9999"}[5m])

How to solve this issue?

答案1

得分: 1

虽然计数器不是这种用例的最佳解决方案,但你可以使用增加运算符。

Increase(tempin{instance="localhost:9999"}[5m])

这将告诉你计数器在过去的五分钟内增加了多少。

英文:

Although a counter is not the best solution for this use case, you can use the operator increase.

Increase(tempin{instance="localhost:9999"}[5m])

This will tell you how much the counter increased in the last five minutes

huangapple
  • 本文由 发表于 2022年4月24日 03:48:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/71983129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定