-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus.go
68 lines (58 loc) · 1.54 KB
/
prometheus.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
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
tentaReqeusts = promauto.NewCounter(prometheus.CounterOpts{
Name: "tenta_requests_received",
Help: "The total number of requests",
})
tentaHits = promauto.NewCounter(prometheus.CounterOpts{
Name: "tenta_hits",
Help: "The total number of cached requests",
})
tentaMisses = promauto.NewCounter(prometheus.CounterOpts{
Name: "tenta_misses",
Help: "The total number of uncached requests",
})
tentaFiles = promauto.NewGauge(prometheus.GaugeOpts{
Name: "tenta_files",
Help: "The number of files in the cache",
})
tentaSize = promauto.NewGauge(prometheus.GaugeOpts{
Name: "tenta_size",
Help: "The size of the cache",
})
)
func StartMetrics() {
go func() {
port := fmt.Sprintf(":%d", 2112)
if args.debug {
log.Println("Repopulating prometheus metrics from data directory")
}
tmpfiles, err := ioutil.ReadDir(args.dataDir)
if err != nil {
log.Fatalf("Error reading data dir %s: %s", args.dataDir, err)
}
for _, file := range tmpfiles {
tentaFiles.Inc()
tentaSize.Add(float64(file.Size()))
}
log.Printf("Starting metrics server on %s", port)
s := &http.Server{
Addr: port,
Handler: promhttp.Handler(),
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}()
}