-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (66 loc) · 1.67 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"time"
"github.com/gin-gonic/gin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
ginprometheus "github.com/zsais/go-gin-prometheus"
)
var addr = flag.String("listen-address", ":8081", "The address to listen on for HTTP requests.")
var (
c = promauto.NewCounter(prometheus.CounterOpts{
Name: "skeleton_app_sample_metric",
Help: "Sample metric for skeleton",
})
h = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "skeleton_app_sample_histogram",
Help: "Sample histogram for skeleton",
})
d = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "skeleton_app_sample_devices",
Help: "Sample counter opts devices for skeleton"}, []string{"device"})
e = promauto.NewCounter(prometheus.CounterOpts{
Name: "skeleton_app_push_metric",
Help: "Sample metric for Pushgateway",
})
)
func main() {
rand.Seed(time.Now().UnixNano())
r := gin.New()
p := ginprometheus.NewPrometheus("http")
p.Use(r)
r.GET("/", func(c *gin.Context) {
time.Sleep(time.Duration(rand.Intn(500)) * time.Millisecond)
switch rand.Intn(6) {
case 0:
c.JSON(200, "Hello world!")
case 1:
c.JSON(404, "Not Found!")
case 2:
c.JSON(500, "Oops!")
case 3:
c.JSON(401, "Unauthorized!")
case 4:
c.JSON(403, "Forbidden!")
case 5:
c.JSON(408, "Timeout!")
default:
c.JSON(200, "Hello world!")
}
})
go func() {
for {
rand.Seed(time.Now().UnixNano())
h.Observe(float64(rand.Intn(100-0+1) + 0))
d.With(prometheus.Labels{"device": "/dev/sda"}).Inc()
c.Inc()
fmt.Print(".")
time.Sleep(1 * time.Second)
}
}()
log.Fatal(r.Run(*addr))
}