-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync.go
53 lines (44 loc) · 987 Bytes
/
async.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func recordMetrics() {
for {
dat, err := getTempData()
if err != nil {
fmt.Println(err)
time.Sleep(2 * time.Second)
continue
}
if len(dat.Data.Timestep) == 0 {
continue
}
for _, interval := range dat.Data.Timestep[0].TempVal {
tempCelsius.Set(interval.Values.Temp)
}
opsProcessed.Inc()
time.Sleep(2 * time.Second)
}
}
var opsProcessed = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "processed_ops_total",
Help: "The total number of processed operations",
},
)
var tempCelsius = promauto.NewGauge(
prometheus.GaugeOpts{
Name: "current_temperature_api_celsius",
Help: "Current temperature",
},
)
func main() {
go recordMetrics()
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":2112", nil)
}