Using grafana counter to visualize weather data

Issue

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?

Solution

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

Answered By – Sergio Santiago

Answer Checked By – Katrina (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.