This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
main.go
55 lines (47 loc) · 1.34 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
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/grafana/metrictank/logger"
"github.com/grafana/metrictank/mdata/notifierKafka"
"github.com/grafana/metrictank/stats"
log "github.com/sirupsen/logrus"
)
func main() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "mt-kafka-persist-sniff")
fmt.Fprintln(os.Stderr, "Print what's flowing through kafka metric persist topic")
fmt.Fprintf(os.Stderr, "\nFlags:\n\n")
flag.PrintDefaults()
notifierKafka.FlagSet.PrintDefaults()
}
formatter := &logger.TextFormatter{}
formatter.TimestampFormat = "2006-01-02 15:04:05.000"
log.SetFormatter(formatter)
log.SetLevel(log.InfoLevel)
instance := "mt-kafka-persist-sniff" + strconv.Itoa(rand.Int())
notifierKafka.FlagSet.Usage = flag.Usage
notifierKafka.FlagSet.Parse(os.Args[1:])
// config may have had it disabled
notifierKafka.Enabled = true
stats.NewDevnull() // make sure metrics don't pile up without getting discarded
notifierKafka.ConfigProcess(instance)
done := make(chan struct{})
go func() {
notifierKafka.New(instance, NewPrintNotifierHandler())
close(done)
}()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
select {
case sig := <-sigChan:
log.Infof("Received signal %q. Shutting down", sig)
case <-done:
}
// notifierKafka.Stop()
}