func main() { if config.Pprof.Cpu != "" { // Start Profiler f, err := os.Create(config.Pprof.Cpu) if err != nil { glog.Fatal(err) } defer f.Close() pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } http.HandleFunc("/render", render.Handler) glog.Infoln("ListenAndServe", config.Cfg.Webserver.Addr) go func() { glog.Fatal(http.ListenAndServe(config.Cfg.Webserver.Addr, nil)) }() // Handle SIGINT and SIGTERM. sig := make(chan os.Signal) signal.Notify(sig, os.Interrupt, os.Kill) glog.Errorf("Syscall: %v - Exit\n", <-sig) if config.Pprof.Mem != "" { // Start Mem Profiler f, err := os.Create(config.Pprof.Mem) if err != nil { glog.Fatal(err) } pprof.WriteHeapProfile(f) f.Close() } }
func (api *IntApi) Value(name string, from int64, to int64) interface{} { if i, err := strconv.Atoi(name); err == nil { return i } else { glog.Fatal(err) } return nil }
func main() { if config.Pprof.Cpu != "" { // Start Cpu Profiler f, err := os.Create(config.Pprof.Cpu) if err != nil { glog.Fatal(err) } defer f.Close() pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } ln, err := net.Listen("tcp", config.Cfg.Listener.Addr) if err != nil { glog.Fatalln(err) } glog.Infoln("ListenAndServe", config.Cfg.Listener.Addr) go func() { for { conn, err := ln.Accept() if err != nil { glog.Errorln(err) continue } go handle(conn) } }() // Handle SIGINT and SIGTERM. sig := make(chan os.Signal) signal.Notify(sig, os.Interrupt, os.Kill) glog.Errorf("Syscall: %v - Exit\n", <-sig) if config.Pprof.Mem != "" { // Start Mem Profiler f, err := os.Create(config.Pprof.Mem) if err != nil { glog.Fatal(err) } pprof.WriteHeapProfile(f) f.Close() } }
func init() { // Max log file size - rotate log file if exceed 10MB glog.MaxSize = 10 * 1024 * 1024 var f = flag.String("f", "config.json", "read configuration from file") flag.StringVar(&Pprof.Cpu, "cpuprofile", "", "write cpu profile to file") flag.StringVar(&Pprof.Mem, "memprofile", "", "write memory profile to this file") flag.Parse() if cfg, err := ioutil.ReadFile(*f); err != nil { glog.Errorln(err) return } else { if err := json.Unmarshal(cfg, &Cfg); err != nil { glog.Fatal(err) } glog.Infof("%v", string(cfg)) } dir := filepath.Dir(*f) + "/" if script, err := ioutil.ReadFile(dir + Cfg.Metrics.AddScript); err != nil { glog.Errorln(err) Cfg.Metrics.AddScript = "" } else { Cfg.Metrics.AddScript = string(script) } if script, err := ioutil.ReadFile(dir + Cfg.Metrics.GetScript); err != nil { glog.Errorln(err) Cfg.Metrics.GetScript = "" } else { Cfg.Metrics.GetScript = string(script) } if script, err := ioutil.ReadFile(dir + Cfg.Metrics.TtlScript); err != nil { glog.Errorln(err) Cfg.Metrics.TtlScript = "" } else { Cfg.Metrics.TtlScript = string(script) } }