-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
73 lines (59 loc) · 1.57 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/blockassets/bwpool_exporter/bwpool"
"github.com/jpillora/overseer"
"github.com/jpillora/overseer/fetcher"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
// Makefile build
version = ""
config *string
timeout *time.Duration
)
const (
ghUser = "blockassets"
ghRepo = "bwpool_exporter"
twiceADay = 12 * time.Hour
)
func main() {
config = flag.String("config", "./bwpool.json", "Path to a file that has the API keys in it.")
timeout = flag.Duration("timeout", 10*time.Second, "The amount of time to wait for bwpool to return.")
port := flag.String("port", "5551", "The address to listen on for /metrics HTTP requests.")
noUpdate := flag.Bool("no-update", false, "Never do any updates. Example: -no-update=true")
flag.Parse()
portStr := fmt.Sprintf(":%s", *port)
if *noUpdate {
prog(overseer.State{Address: portStr})
} else {
overseerRun(portStr, twiceADay)
}
}
func overseerRun(port string, interval time.Duration) {
overseer.Run(overseer.Config{
Program: prog,
Address: port,
Fetcher: &fetcher.Github{
User: ghUser,
Repo: ghRepo,
Interval: interval,
},
})
}
func prog(state overseer.State) {
log.Printf("%s %s on port %s\n", os.Args[0], version, state.Address)
poolConfig, err := bwpool.ReadConfig(*config)
if err != nil {
log.Fatal(err)
}
prometheus.MustRegister(NewExporter(poolConfig, *timeout))
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.Serve(state.Listener, nil))
}