forked from cloudfoundry-attic/datadog-firehose-nozzle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (59 loc) · 1.73 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
74
75
76
package main
import (
"flag"
"io"
"log"
"net/http"
"os"
"os/signal"
"runtime/pprof"
"syscall"
"github.com/evoila/influxdb-firehose-nozzle/influxdbfirehosenozzle"
"github.com/evoila/influxdb-firehose-nozzle/nozzleconfig"
"github.com/evoila/influxdb-firehose-nozzle/uaatokenfetcher"
)
func main() {
configFilePath := flag.String("config", "config/influxdb-firehose-nozzle.json", "Location of the nozzle config json file")
flag.Parse()
config, err := nozzleconfig.Parse(*configFilePath)
if err != nil {
log.Fatalf("Error parsing config: %s", err.Error())
}
tokenFetcher := &uaatokenfetcher.UAATokenFetcher{
UaaUrl: config.UAAURL,
Username: config.Username,
Password: config.Password,
InsecureSSLSkipVerify: config.InsecureSSLSkipVerify,
}
threadDumpChan := registerGoRoutineDumpSignalChannel()
defer close(threadDumpChan)
go dumpGoRoutine(threadDumpChan)
influxDbNozzle := influxdbfirehosenozzle.NewInfluxDbFirehoseNozzle(config, tokenFetcher)
influxDbNozzle.Start()
runServer()
}
func defaultResponse(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "{ \"status\" : \"running\" }")
}
func runServer() {
port := os.Getenv("PORT")
if port == "" {
port = "8000"
}
log.Print("Starting server with port: " + port)
http.HandleFunc("/", defaultResponse)
http.ListenAndServe(":"+port, nil)
}
func registerGoRoutineDumpSignalChannel() chan os.Signal {
threadDumpChan := make(chan os.Signal, 1)
signal.Notify(threadDumpChan, syscall.SIGUSR1)
return threadDumpChan
}
func dumpGoRoutine(dumpChan chan os.Signal) {
for range dumpChan {
goRoutineProfiles := pprof.Lookup("goroutine")
if goRoutineProfiles != nil {
goRoutineProfiles.WriteTo(os.Stdout, 2)
}
}
}