func init() { sarama.Logger = kafkaLogger{} reg := metrics.NewPrefixedRegistry("libbeat.kafka.") // Note: registers /debug/metrics handler for displaying all expvar counters exp.Exp(reg) kafkaMetricsRegistryInstance = reg outputs.RegisterOutputPlugin("kafka", New) }
func main() { log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds) log.Printf("ogrt-server %s", VERSION) if _, err := toml.DecodeFile("ogrt.conf", &config); err != nil { log.Fatal(err) } /* expose metrics as HTTP endpoint */ if config.DebugEndpoint == true { exp.Exp(metrics.DefaultRegistry) go http.ListenAndServe(":8080", nil) log.Printf("Instantiated DebugEndpoint at Port 8080") } // Listen for incoming connections. listen_string := fmt.Sprintf("%s:%d", config.Address, config.Port) listener, err := net.Listen("tcp", listen_string) if err != nil { log.Fatal("Error listening:", err.Error()) } // Close the listener when the application closes. defer listener.Close() outputs = make(map[string][]Output) output_channels = make(map[string]chan interface{}) /* instantiate all outputs */ for name, out := range config.Outputs { output_channels[name] = make(chan interface{}) for i := 0; i < config.Outputs[name].Workers; i++ { var output_gosucks Output switch out.Type { case "JsonOverTcp": output_gosucks.Writer = new(output.JsonOverTcpOutput) case "JsonElasticSearch": output_gosucks.Writer = new(output.JsonElasticSearchOutput) case "JsonFile": output_gosucks.Writer = new(output.JsonFileOutput) default: log.Fatal("Unkown output type: ", out.Type) } output_gosucks.Writer.Open(out.Params) outputs[name] = append(outputs[name], output_gosucks) go writeToOutput(name, i, output_channels[name]) defer output_gosucks.Writer.Close() } metrics.Register("output_"+name, metrics.NewTimer()) log.Printf("Instantiated output '%s' of type '%s' with parameters: '%s'", name, config.Outputs[name].Type, config.Outputs[name].Params) } /* Setup signal handler for SIGKILL and SIGTERM */ sigc := make(chan os.Signal, 1) signal.Notify(sigc, os.Interrupt, os.Kill, syscall.SIGTERM) go func(c chan os.Signal) { sig := <-c log.Printf("Caught signal %s: shutting down.\n", sig) listener.Close() for _, out := range config.Outputs { out.Writer.Close() } os.Exit(0) }(sigc) /* register timer for accept() */ accept_timer := metrics.NewTimer() metrics.Register("accept", accept_timer) /* output metrics every five seconds */ go metrics.LogScaled(metrics.DefaultRegistry, 5*time.Second, time.Millisecond, log.New(os.Stderr, "metrics: ", log.Lmicroseconds)) for { // Listen for an incoming connection. accept_timer.Time(func() { connection, err := listener.Accept() if err != nil { log.Fatal("Error accepting: ", err.Error()) os.Exit(1) } go handleRequest(connection) }) } }
func init() { // Tweak the authentication logic for the tracing endpoint. By default it's // open for localhost only, but with Docker we want to get there from // anywhere. We maintain the default behavior of only allowing access to // sensitive logs from localhost. // // TODO(mberhault): properly secure this once we require client certs. origAuthRequest := trace.AuthRequest trace.AuthRequest = func(req *http.Request) (bool, bool) { _, sensitive := origAuthRequest(req) return true, sensitive } debugServeMux.HandleFunc(debugEndpoint, func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != debugEndpoint { http.Redirect(w, r, debugEndpoint, http.StatusMovedPermanently) } // The explicit header is necessary or (at least Chrome) will try to // download a gzipped file (Content-type comes back application/x-gzip). w.Header().Add("Content-type", "text/html") fmt.Fprint(w, ` <html> <head> <style> table tr td { vertical-align: top; } </style> <title>Debug endpoints</title> </head> <body> <h1>Debug endpoints</h1> <table> <tr> <td>trace (local node only)</td> <td><a href="./requests">requests</a>, <a href="./events">events</a></td> </tr> <tr> <td>stopper</td> <td><a href="./stopper">active tasks</a></td> </tr> <tr> <td>metrics</td> <td><a href="./metrics">variables</a></td> </tr> <tr> <td>node status</td> <td> <a href="/_status/gossip/local">gossip</a><br /> <a href="/_status/ranges/local">ranges</a><br /> </td> </tr> <tr> <td>raft</td> <td><a href="/_status/raft">raft</a></td> </tr> <tr> <td>pprof</td> <td> <!-- cribbed from the /debug/pprof endpoint --> <a href="./pprof/block?debug=1">block</a><br /> <a href="./pprof/goroutine?debug=1">goroutine</a> (<a href="./pprof/goroutine?debug=2">all</a>)<br /> <a href="./pprof/heap?debug=1">heap</a><br /> <a href="./pprof/threadcreate?debug=1">threadcreate</a><br /> </td> </tr> </table> </body></html> `) }) // This registers a superset of the variables exposed through the /debug/vars endpoint // onto the /debug/metrics endpoint. It includes all expvars registered globally and // all metrics registered on the DefaultRegistry. exp.Exp(metrics.DefaultRegistry) }
func init() { metrics.Register("numbers", h) metrics.Register("timer", timer) exp.Exp(metrics.DefaultRegistry) }