-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (82 loc) · 2.41 KB
/
Copy pathmain.go
File metadata and controls
98 lines (82 loc) · 2.41 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"context"
"flag"
"fmt"
"job-exporter/overseer"
"log"
"net/http"
"net/http/pprof"
_ "net/http/pprof"
"net/url"
"os"
"os/signal"
"syscall"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
const (
timeout = time.Duration(30000 * time.Millisecond)
)
var (
addr string
endpoint *url.URL
port int
yarns string
storms string
memlimit uint64
isdebug bool
dummy bool
)
func prog(state overseer.State) {
log.Println("yarn-storm-exporter v2.1 by chinhnc. Build: 19092019")
flag.IntVar(&port, "port", 9653, "The port to serve the endpoint from.")
flag.StringVar(&yarns, "yarn.servers", "", "Comma separated list of yarn yarnServers in the format http://host:port")
flag.StringVar(&storms, "storm.servers", "", "Comma separated list of storm yarnServers in the format http://host:port")
flag.Uint64Var(&memlimit, "mem.limit", 419430400, "Memory limit in bytes, default: 400MB") //default 400MB
flag.BoolVar(&isdebug, "debug", false, "Enable/disable debug mode")
flag.BoolVar(&dummy, "job-exporter-slave", true, "Just a dummy flag")
flag.Parse()
client := &http.Client{
Timeout: timeout,
}
c := YarnCollector(client, yarns, storms)
prometheus.MustRegister(c)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
if isdebug == true {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
srv := &http.Server{
Addr: fmt.Sprintf(":%v", port),
Handler: mux,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
}
go func() {
_ = <-sigs
log.Println("main: received SIGINT or SIGTERM, shutting down")
context, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if err := srv.Shutdown(context); err != nil {
log.Printf("main: failed to shutdown endpoint with err=%#v\n", err)
}
}()
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Printf("main: failure while serving endpoint, err=%#v\n", err)
}
}
func main() {
overseer.Run(overseer.Config{
Program: prog,
Debug: true,
NoRestart: false,
})
}