コード例 #1
0
ファイル: noodle_test.go プロジェクト: jessereynolds/coco
// Test data can be fetched from noodle
func TestFetch(t *testing.T) {
	go MockVisage()

	// Setup Fetch
	fetchConfig := coco.FetchConfig{
		Bind:         "127.0.0.1:26082",
		ProxyTimeout: *new(coco.Duration),
		RemotePort:   "29292",
	}
	fetchConfig.ProxyTimeout.UnmarshalText([]byte("3s"))

	tierConfig := make(map[string]coco.TierConfig)
	tierConfig["a"] = coco.TierConfig{Targets: []string{"127.0.0.1:25887"}}
	tierConfig["b"] = coco.TierConfig{Targets: []string{"127.0.0.1:25888"}}
	tierConfig["c"] = coco.TierConfig{Targets: []string{"127.0.0.1:25889"}}

	var tiers []coco.Tier
	for k, v := range tierConfig {
		tier := coco.Tier{Name: k, Targets: v.Targets}
		tiers = append(tiers, tier)
	}

	go noodle.Fetch(fetchConfig, &tiers)

	poll(t, fetchConfig.Bind)

	// Test
	params := visage.Params{
		Endpoint: fetchConfig.Bind,
		Host:     "highest",
		Plugin:   "load",
		Instance: "load",
		Ds:       "value",
		Window:   3 * time.Hour,
	}

	window, err := visage.Fetch(params)
	if err != nil {
		t.Fatalf("Error when fetching Visage data: %s\n", err)
	}

	for i, v := range window {
		if v != 0.0 {
			t.Errorf("Unexpected value: expected %f got %f at %d", 0.0, v, i)
		}
	}
}
コード例 #2
0
ファイル: noodle_test.go プロジェクト: jessereynolds/coco
// Test a bad fetch results in an error
func TestFetchWithFailure(t *testing.T) {
	go MockVisage()

	// Setup Fetch
	fetchConfig := coco.FetchConfig{
		Bind:         "127.0.0.1:26083",
		ProxyTimeout: *new(coco.Duration),
		RemotePort:   "29293",
	}
	fetchConfig.ProxyTimeout.UnmarshalText([]byte("3s"))

	tierConfig := make(map[string]coco.TierConfig)
	tierConfig["a"] = coco.TierConfig{Targets: []string{"127.0.0.1:25887"}}
	tierConfig["b"] = coco.TierConfig{Targets: []string{"127.0.0.1:25888"}}
	tierConfig["c"] = coco.TierConfig{Targets: []string{"127.0.0.1:25889"}}

	var tiers []coco.Tier
	for k, v := range tierConfig {
		tier := coco.Tier{Name: k, Targets: v.Targets}
		tiers = append(tiers, tier)
	}

	go noodle.Fetch(fetchConfig, &tiers)

	poll(t, fetchConfig.Bind)

	// Test
	params := visage.Params{
		Endpoint: fetchConfig.Bind,
		Host:     "highest",
		Plugin:   "load",
		Instance: "load",
		Ds:       "value",
		Window:   3 * time.Hour,
	}

	body, err := visage.Fetch(params)
	if err == nil {
		t.Fatalf("Expected error when fetching Visage data, got: %+v\n", body)
	}
}
コード例 #3
0
func main() {
	kingpin.Version("1.0.0")
	kingpin.Parse()

	if *debug {
		fmt.Println("Host:", *host)
		fmt.Println("Target:", *target)
		fmt.Println("Endpoint:", *endpoint)
		fmt.Printf("Maximum deviation: %.1f\n", *deviation)
		fmt.Println("Window:", *window)
		fmt.Println("Debug:", *debug)
	}

	// Global error handling
	defer handleErrors()

	// Fetch a window of metrics
	params := visage.Params{
		Endpoint: *endpoint,
		Host:     *host,
		Plugin:   "curl_json-coco",
		Instance: "operations-send-" + *target + ":25826",
		Ds:       "value",
		Window:   *window,
		Debug:    *debug,
	}
	window, err := visage.Fetch(params)
	if err != nil {
		fmt.Printf("UNKNOWN: Unable to fetch Visage JSON: %s\n", err)
		os.Exit(3)
	}

	if len(window) < 20 {
		fmt.Printf("UNKNOWN: Expected > %d datapoints, got %d. Coco running?\n", 20, len(window))
		os.Exit(3)
	}

	// Bisect the window into two equal length windows.
	window1, window2 := ks.BisectAndSortWindow(window)
	// Find the D-statistic
	max, maxIndex := ks.FindMaxDeviation(window1, window2)

	if *debug {
		fmt.Println("Window 1:")
		fmt.Println(window1)
		fmt.Println("Window 2:")
		fmt.Println(window2)
		fmt.Println("Max, max index:")
		fmt.Println(max, maxIndex)
		fmt.Printf("Window sizes: window 1: %d, window 2: %d\n", len(window1), len(window2))
	}

	// Plot the data on the console
	ks.Plot(window1, window2, max, maxIndex)

	if max > *deviation {
		fmt.Printf("CRITICAL: Deviation (%.2f) is greater than maximum allowed (%.2f)\n", max, *deviation)
		os.Exit(2)
	} else {
		fmt.Printf("OK: Deviation (%.2f) is within tolerances (%.2f)\n", max, *deviation)
		os.Exit(0)
	}
}