-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (45 loc) · 1.01 KB
/
main.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
54
55
56
57
58
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const banner = "elder-kettle 0.0"
var (
guyRandom = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "guy_random",
Help: "guy random value",
},
)
)
func getRoot(ww http.ResponseWriter, rr *http.Request) {
log.Println("get root")
ww.Header().Set("Content-Type", "text/html")
ww.WriteHeader(http.StatusOK)
fmt.Fprintf(ww, banner)
}
func updateMetrics() {
go func() {
prometheus.MustRegister(guyRandom)
for {
log.Println("update metrics")
guyRandom.Set(rand.NormFloat64())
time.Sleep(3 * time.Second)
}
}()
}
func main() {
log.Println(banner)
rand.New(rand.NewSource(time.Now().UnixNano()))
updateMetrics()
router := mux.NewRouter()
router.HandleFunc("/", getRoot).Methods("GET")
router.Path("/metrics").Handler(promhttp.Handler())
log.Fatal(http.ListenAndServe(":80", router))
}