Example #1
0
func calcMetrics() {
	tck := time.NewTicker(time.Duration(10) * time.Second)
	for {
		select {
		case <-tck.C:
			kubismus.Note("Goroutines", fmt.Sprintf("%d", runtime.NumGoroutine()))
			go func() {
				v := kubismus.GetMetrics("Requests", kubismus.SUM)
				defer kubismus.ReleaseMetrics(v)
				c := kubismus.GetMetrics("Requests", kubismus.COUNT)
				defer kubismus.ReleaseMetrics(c)
				sz := len(c)
				T := 0.0
				C := 0.0
				for i := sz - 60; i < sz; i++ {
					C += c[i]
					T += v[i]
				}
				A := 0.0
				if C > 0.0 {
					A = T / C
				}
				kubismus.Note("Last One Minute", fmt.Sprintf("%.0f Requests, %.0f Average Size, %0.f Bytes", C, A, T))
			}()
		}
	}
}
Example #2
0
func main() {

	// Register the first service
	floatSvc := new(math.FloatService)
	floatSvc.SvcObj = new(impl.FloatServiceImpl)
	babel.Register(floatSvc)

	// Register the second service
	fractSvc := new(math.FractionService)
	fractSvc.SvcObj = new(impl.FractionServiceImpl)
	babel.Register(fractSvc)

	// Set some info for the monitoring page
	kubismus.Setup("Math Service", "")
	kubismus.Note("Babel base path", "http://localhost:9999"+babel.DefaultHttpPath)
	kubismus.Note("Monitoring path", "http://localhost:9999"+kubismus.DefaultPath)
	kubismus.Note("Test harness path", "http://localhost:9999/test/")
	kubismus.Define("Requests", kubismus.COUNT, "Requests/sec")

	// Set up Babel HTTP handlers and serve HTTP
	http.Handle(babel.DefaultHttpPath, kubismus.HttpRequestMetric("Requests", babel.DefaultServer))
	kubismus.HandleHTTP()
	http.HandleFunc("/test/", harness.ServeHTTP)
	http.HandleFunc("/", frame)
	log.Fatal(http.ListenAndServe(":9999", nil))
}
Example #3
0
func main() {
	// Parse flags from command-line
	flag.Parse()

	// Parser flags from config
	flagcfg.AddDefaults()
	flagcfg.Parse()

	// Parse flags from environment (using github.com/facebookgo/flagenv)
	flagenv.Prefix = "RANDFILES_"
	flagenv.Parse()

	if help {
		showHelp()
		return
	}

	// setup number of CPUs
	runtime.GOMAXPROCS(cpus)

	name, _ := os.Hostname()

	http.Handle("/", http.HandlerFunc(kubismus.ServeHTTP))

	kubismus.Setup("randfiles", "")
	kubismus.Note("Host Name", name)
	kubismus.Note("CPUs", fmt.Sprintf("%d of %d", runtime.GOMAXPROCS(0), runtime.NumCPU()))
	kubismus.Note("Delay", delay.String())
	kubismus.Note("Writer threads", fmt.Sprintf("%d", threads))
	kubismus.Note("File size", fmt.Sprintf("%d to %d bytes", minSize, maxSize))
	kubismus.Note("File extension", ext)
	kubismus.Define("Data", kubismus.COUNT, "Files/second")
	kubismus.Define("Data", kubismus.SUM, "Bytes/second")

	// switch to working dir
	if workingDir != "" {
		err := os.Chdir(workingDir)
		if err != nil {
			log.Fatal(err)
		}
	}
	wd, err := os.Getwd()
	if err == nil {
		kubismus.Note("Working Directory", wd)
	}

	rand.Seed(time.Now().UnixNano())
	for i := 0; i < threads; i++ {
		go writeFiles(minSize, maxSize, delay, ext)
	}
	go calcMetrics()

	log.Fatal(http.ListenAndServe(addr, nil))
}
Example #4
0
func main() {
	// Parse flags from command-line
	flag.Parse()

	// Parser flags from config
	flagcfg.AddDefaults()
	flagcfg.Parse()

	// Parse flags from environment (using github.com/facebookgo/flagenv)
	flagenv.Prefix = "WEBNULL_"
	flagenv.Parse()

	if help {
		showHelp()
		return
	}

	// setup number of CPUs
	runtime.GOMAXPROCS(cpus)

	name, _ := os.Hostname()

	http.Handle("/status/", http.StripPrefix("/status", http.HandlerFunc(kubismus.ServeHTTP)))
	http.Handle("/", kubismus.HttpRequestMetric("Requests", handleRequest()))
	http.HandleFunc("/media/", ServeHTTP)

	kubismus.Setup("/web/null", "/media/null.png")
	kubismus.Note("Host Name", name)
	kubismus.Note("CPUs", fmt.Sprintf("%d of %d", runtime.GOMAXPROCS(0), runtime.NumCPU()))
	kubismus.Define("Requests", kubismus.COUNT, "Requests/second")
	kubismus.Define("Requests", kubismus.SUM, "Bytes/second")

	go calcMetrics()

	log.Fatal(http.ListenAndServe(addr, nil))
}
Example #5
0
func loopCount(ctx context.Context, count int) <-chan L {
	done := ctx.Done()
	ch := make(chan L)
	looper := func(loopCount int) {
		defer close(ch)
		for i := 1; i <= loopCount; i++ {
			select {
			case <-done:
				return
			case ch <- L{LoopNum: i}:
				kubismus.Note("Loops", fmt.Sprintf("%d of %d", i, loopCount))
			}
		}
	}
	go looper(count)
	return ch
}
Example #6
0
func main() {
	// Parse flags from command-line
	flag.Parse()

	// Parser flags from config
	flagcfg.AddDefaults()
	flagcfg.Parse()

	// Parse flags from environment (using github.com/facebookgo/flagenv)
	flagenv.Prefix = "HURL_"
	flagenv.Parse()

	if help {
		showHelp()
		return
	}

	if version {
		showVersion()
		return
	}

	if flag.NArg() < 1 {
		fmt.Fprintf(os.Stderr, "Please provide a URL to fetch.\n")
		return
	}

	err := parseHeaders()
	if err != nil {
		log.Fatal(err)
	}
	// log.Printf("%#v", headers)

	// setup number of CPUs
	runtime.GOMAXPROCS(cpus)

	// setup cpu profiling if desired
	if cpuProfile != "" {
		f, err := os.Create(cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer func() {
			log.Print("Writing CPU profile to ", cpuProfile)
			pprof.StopCPUProfile()
			f.Close()
		}()
	}

	// create HTTP transport and client
	transport = &http.Transport{DisableKeepAlives: noKeepAlive, MaxIdleConnsPerHost: conns, DisableCompression: noCompress, ResponseHeaderTimeout: timeout}
	client = &http.Client{Transport: transport, Timeout: timeout}

	// setup Kubismus
	kubismus.Setup("hURL", "/media/logo36.png")
	kubismus.Define("Sent", kubismus.COUNT, "HTTP Posts")
	kubismus.Define("Sent", kubismus.SUM, "Bytes Sent")
	kubismus.Define("Received", kubismus.SUM, "Bytes Received")
	kubismus.Define("Received100", kubismus.COUNT, "1xx Responses")
	kubismus.Define("Received200", kubismus.COUNT, "2xx Responses")
	kubismus.Define("Received300", kubismus.COUNT, "3xx Responses")
	kubismus.Define("Received400", kubismus.COUNT, "4xx Responses")
	kubismus.Define("Received500", kubismus.COUNT, "5xx Responses")
	kubismus.Define("Error", kubismus.COUNT, "Communication Errors")
	kubismus.Define("ResponseTime", kubismus.AVERAGE, "Average Time (s)")
	kubismus.Note("Concurrent Connections", strconv.Itoa(conns))
	kubismus.Note("HTTP Method", method)
	kubismus.Note("Timeout", timeout.String())
	kubismus.Note("Processors", fmt.Sprintf("%d of %d", runtime.GOMAXPROCS(0), runtime.NumCPU()))
	kubismus.Note("Data files", strings.Join(strings.Split(filesPat, ","), "\n"))
	kubismus.Note("URLs", strings.Join(flag.Args(), "\n"))
	kubismus.Note("Discard files", strconv.FormatBool(discard))
	http.Handle("/", http.HandlerFunc(kubismus.ServeHTTP))
	http.HandleFunc("/media/", ServeHTTP)

	// switch to working dir
	if workingDir != "" {
		err := os.Chdir(workingDir)
		if err != nil {
			log.Fatal(err)
		}
	}
	wd, err := os.Getwd()
	if err == nil {
		kubismus.Note("Working Directory", wd)
	}

	// setup the thread context
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// spawn a function that updates the number of goroutines shown in the status page
	go func() {
		done := ctx.Done()
		t := time.NewTicker(5 * time.Second)
		defer t.Stop()
		for {
			select {
			case <-done:
				return
			case <-t.C:
				kubismus.Note("Goroutines", fmt.Sprintf("%d", runtime.NumGoroutine()))
			}
		}
	}()

	// spawn the status web site
	go func() {
		log.Fatal(http.ListenAndServe(addr, nil))
	}()

	// handle kill signals
	go func() {
		// Set up channel on which to send signal notifications.
		// We must use a buffered channel or risk missing the signal
		// if we're not ready to receive when the signal is sent.
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, os.Kill)

		// Block until a signal is received.
		s := <-c
		log.Print("Got signal ", s, ", canceling work")
		cancel()
	}()

	// Build pipeline
	var patList []string
	if filesPat != "" {
		patList = strings.Split(filesPat, ",")
	}
	ch1 := loopCount(ctx, loop)
	ch2 := loopUrls(ctx, method, flag.Args(), ch1)
	ch3 := loopFiles(ctx, patList, ch2)
	doHttp(ctx, conns, ch3)

	// write memory profile if configured
	if memProfile != "" {
		f, err := os.Create(memProfile)
		if err != nil {
			log.Print(err)
		} else {
			log.Print("Writing memory profile to ", memProfile)
			pprof.WriteHeapProfile(f)
			f.Close()
		}
	}
}
Example #7
0
func main() {
	// Parse flags from command-line
	flag.Parse()

	// Parser flags from config
	flagcfg.AddDefaults()
	flagcfg.Parse()

	// Parse flags from environment (using github.com/facebookgo/flagenv)
	flagenv.Prefix = "AUTOHURL_"
	flagenv.Parse()

	if help {
		showHelp()
		return
	}

	if version {
		showVersion()
		return
	}

	// parse default headers - make sure they work
	var err error
	err = defaultCfg.ParseHeaders()
	if err != nil {
		log.Fatal(err)
	}
	// log.Printf("%#v", headers)

	// setup number of CPUs
	runtime.GOMAXPROCS(cpus)

	// setup cpu profiling if desired
	if cpuProfile != "" {
		f, err := os.Create(cpuProfile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer func() {
			log.Print("Writing CPU profile to ", cpuProfile)
			pprof.StopCPUProfile()
			f.Close()
		}()
	}

	// setup Kubismus
	kubismus.Setup("autohURL", "/media/logo36.png")
	kubismus.Note("Processors", fmt.Sprintf("%d of %d", runtime.GOMAXPROCS(0), runtime.NumCPU()))
	http.Handle("/", http.HandlerFunc(kubismus.ServeHTTP))
	http.HandleFunc("/media/", ServeHTTP)

	// switch to working dir
	if workingDir != "" {
		err := os.Chdir(workingDir)
		if err != nil {
			log.Fatal(err)
		}
	}
	wd, err := os.Getwd()
	if err == nil {
		kubismus.Note("Working Directory", wd)
	}

	// Print settings
	fmt.Printf("addr = \"%s\"\n", addr)
	fmt.Printf("cpu = %d\n", cpus)
	fmt.Printf("wd = \"%s\"\n", workingDir)
	fmt.Printf("cpuprofile = \"%s\"\n", cpuProfile)
	fmt.Printf("memprofile = \"%s\"\n", memProfile)
	fmt.Println()

	// Print default folder settings
	fmt.Printf("[folders.*]\n%s\n", defaultCfg.String())

	// read folders
	var cfg map[string]*FolderCfg
	cfg, err = readConfig(flagcfg.Filename())
	if err != nil {
		log.Fatal(err)
	}
	if len(cfg) == 0 {
		log.Fatal("No folders configured to watch")
	}
	// set up default settings
	for i, _ := range cfg {
		cfg[i].SetDefaults(&defaultCfg)
		err = cfg[i].ParseHeaders()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("[folders.%s]\n%s\n", i, cfg[i].String())
		kubismus.Note("folders."+i, cfg[i].String())
		kubismus.Define(i+"_Errors", kubismus.COUNT, i+": Errors")
		kubismus.Define(i+"_Sent", kubismus.COUNT, i+": HTTP Posts")
		kubismus.Define(i+"_Sent", kubismus.SUM, i+": Bytes Sent")
		kubismus.Define(i+"_Received", kubismus.SUM, i+": Bytes Received")
		kubismus.Define(i+"_ResponseTime", kubismus.AVERAGE, i+": Average Time (s)")
	}

	// setup the thread context
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// spawn a function that updates the number of goroutines shown in the status page
	go func() {
		done := ctx.Done()
		t := time.NewTicker(5 * time.Second)
		defer t.Stop()
		for {
			select {
			case <-done:
				return
			case <-t.C:
				kubismus.Note("Goroutines", fmt.Sprintf("%d", runtime.NumGoroutine()))
			}
		}
	}()

	// handle kill signals
	go func() {
		// Set up channel on which to send signal notifications.
		// We must use a buffered channel or risk missing the signal
		// if we're not ready to receive when the signal is sent.
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, os.Kill)

		// Block until a signal is received.
		s := <-c
		log.Print("Got signal ", s, ", canceling work")
		cancel()
	}()

	// Build pipeline
	for name, fldr := range cfg {
		ch1 := readDir(ctx, name, fldr)
		go doHttp(ctx, name, fldr, ch1)
	}

	// write memory profile if configured
	if memProfile != "" {
		defer func() {
			f, err := os.Create(memProfile)
			if err != nil {
				log.Print(err)
			} else {
				log.Print("Writing memory profile to ", memProfile)
				pprof.WriteHeapProfile(f)
				f.Close()
			}
		}()
	}

	// status web site
	log.Fatal(http.ListenAndServe(addr, nil))
}
Example #8
0
// doWork does the work of the service
func (i *svcImpl) doWork() {
	// setup kubismus status
	kubismus.Setup("babelproxy", addSlash(conf.MediaPath)+"/logo36.png")
	kubismus.Define("Requests", kubismus.COUNT, "HTTP Requests")
	kubismus.Note("Processors", fmt.Sprintf("%d of %d", runtime.GOMAXPROCS(0), runtime.NumCPU()))
	kubismus.Note("Version", BABELPROXY_VERSION)
	kubismus.Note("REST Service Proxy", "http://"+conf.PubAddr+addSlash(conf.RestPath))
	kubismus.Note("Babel Service Proxy", "http://"+conf.PubAddr+addSlash(conf.BabelPath))
	kubismus.Note("Destination Babel Service", conf.BabelProto+"://"+conf.BabelAddr+addSlash(conf.BabelPath))
	kubismus.Note("Swagger UI (REST)", "http://"+conf.PubAddr+addSlash(conf.SwaggerPath)+"?url=/rest.json")
	kubismus.Note("Swagger UI (Babel)", "http://"+conf.PubAddr+addSlash(conf.SwaggerPath)+"?url=/babel.json")

	mux := http.NewServeMux()
	mux.Handle(addSlash(conf.StatusPath), switchPrefix(addSlash(conf.StatusPath), "/", http.HandlerFunc(kubismus.ServeHTTP)))
	mux.Handle(addSlash(conf.MediaPath), switchPrefix(addSlash(conf.MediaPath), "/media/", http.HandlerFunc(ServeHTTP)))

	// initialize HTTP settings for posting
	i.cancel = initHttp()

	// spawn a function that updates the number of goroutines shown in the status page
	go func() {
		t := time.NewTicker(5 * time.Second)
		defer t.Stop()
		for {
			select {
			case <-t.C:
				kubismus.Note("Goroutines", fmt.Sprintf("%d", runtime.NumGoroutine()))
			}
		}
	}()

	// status site
	go http.ListenAndServe(conf.StatusAddr, mux)

	// read files
	midl, err := loadBabelFiles(conf.Args)
	if err != nil {
		log.Fatal(err)
	}

	// handle swagger UI and JSON generator
	router := httprouter.New()
	router.Handler("GET", addSlash(conf.SwaggerPath)+"*path", switchPrefix(addSlash(conf.SwaggerPath), "/swagger/", http.HandlerFunc(ServeHTTP)))
	err = handleSwagger(router)
	if err != nil {
		log.Fatal(err)
	}
	err = handleBabel(router)
	if err != nil {
		log.Fatal(err)
	}

	// add handlers
	err = addHandlers(router, midl)
	if err != nil {
		log.Fatal(err)
	}

	// listen up!
	log.Fatal(http.ListenAndServe(conf.RestAddr, router))
}