-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (43 loc) · 1.19 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
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/xerrors"
)
var (
// buildVersion = "unknown"
buildRef = "unknown"
buildTime = "unknown"
)
type Config struct {
Addr string `envconfig:"ADDR" default:":8000"`
Tokens []string `envconfig:"TOKENS" required:"true"`
}
func main() {
ctx := context.Background()
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
defer cancel()
log.Printf("start exporter build %s, builded at %s", buildRef, buildTime)
if err := run(ctx); err != nil {
log.Printf("run error: %v", err)
defer os.Exit(1)
}
}
func run(ctx context.Context) error {
var cfg Config
err := envconfig.Process("exporter", &cfg)
if err != nil {
return xerrors.Errorf("parse config: %w", err)
}
registry := prometheus.NewRegistry()
log.Printf("create exporter with %d bots", len(cfg.Tokens))
exporter := NewExporter(ctx, cfg.Tokens)
registry.MustRegister(exporter)
log.Printf("start server at %s", cfg.Addr)
return runServer(ctx, cfg.Addr, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
}