-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (51 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
63 lines (51 loc) · 1.29 KB
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
package main
import (
"flag"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"sync"
"time"
)
// Config section for each site
type Config struct {
Interval time.Duration
}
// Result contains result of the one/last check
type Result struct {
StatusCode int
Length int
Duration time.Duration
Hash uint64
Time time.Time
}
// Site contains configuration and results
type Site struct {
Config Config
LastResult Result
Mutex sync.Mutex
}
// Sitest has main parameters and attributes
type Sitest struct {
ConfigFile string
ListenAddress string
Sites map[string]*Site
Metrics PromCollectors
StartTime time.Time
}
func main() {
sitest := Sitest{StartTime: time.Now()}
flag.StringVar(&sitest.ConfigFile, "config_file", "/etc/sitest/sitest.yaml", "path to config-file")
flag.StringVar(&sitest.ListenAddress, "listen_addr", "0.0.0.0:8080", "listen address")
flag.Parse()
sitest.LoadConfig()
sitest.Metrics.Register(prometheus.DefaultRegisterer)
log.Printf("Start querying sites...")
for site := range sitest.Sites {
go sitest.Run(site)
}
http.Handle("/", sitest)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(sitest.ListenAddress, nil))
}