Esempio n. 1
0
// Parse command line args
func (self *app) parseFlags() error {
	configFile := flag.String("config", "", "Config file")
	showVersion := flag.Bool("version", false, "Show version")
	// Profiling stuff ... from http://blog.golang.org/profiling-go-programs
	cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")

	flag.Parse()

	// -version
	if *showVersion {
		fmt.Printf("Version: %v\n", program_version.GetVersion())
		os.Exit(1)
	}

	// -config "cfg.json"
	if *configFile != "" {
		f, err := os.Open(*configFile)
		if err != nil {
			return fmt.Errorf("Failed to open file '%s': %v", *configFile, err)
		}
		defer f.Close()
		if err := self.parseConfig(f); err != nil {
			return err
		}
	}

	// -cpuprofile "filename.prof"
	if *cpuprofile != "" {
		if err := self.startCpuProfile(*cpuprofile); err != nil {
			return err
		}
	}

	return nil
}
Esempio n. 2
0
func CreateXMLStatusHandler() http.Handler {
	m := martini.Classic()

	var mu sync.Mutex
	var data = make(map[string]float64)
	hmetrics2.AddHook(func(newData map[string]float64) {
		mu.Lock()
		defer mu.Unlock()
		data = make(map[string]float64)
		for k, v := range newData {
			if !math.IsNaN(v) && !math.IsInf(v, 0) {
				data[k] = v
			}
		}
	})

	var logger xmlstatusLogger
	m.Map(stdlog.New(&logger, "[martini] ", stdlog.LstdFlags))

	m.Get("/mon", func() string {
		return servicestatus.GetString()
	})

	m.Get("/version", func() string {
		return program_version.GetVersion()
	})

	m.Get("/config", func(w http.ResponseWriter) {
		w.Header().Add("Content-type", "application/json")
		w.Write([]byte(App.Config()))
	})

	m.Get("/stat", func(w http.ResponseWriter) {
		mu.Lock()
		defer mu.Unlock()
		w.Header().Add("Content-type", "application/xml")
		w.Write([]byte(xml.Header))
		w.Write([]byte(fmt.Sprintf("<stat:document xmlns:stat=\"http://xml.sputnik.ru/stat\" name=\"%v\" version=\"%v\">\n", os.Args[0], program_version.GetVersion())))
		w.Write([]byte(fmt.Sprintf("  <stat>\n    <start_time>%v</start_time>\n  </stat>\n", startTime)))
		w.Write([]byte("  <user>\n"))
		for k, v := range data {
			w.Write([]byte(fmt.Sprintf("    <%s>%v</%s>\n", k, v, k)))
		}
		w.Write([]byte("  </user>\n"))
		w.Write([]byte("</stat:document>\n"))
	})

	return m
}
Esempio n. 3
0
func (self *Service) Version() (r string, err error) {
	return program_version.GetVersion(), nil
}