Exemple #1
0
func main() {
	servers := make([]*store.StoreServer, NUM_SHARDS)
	i := 0
	for i = 0; i < NUM_SHARDS; i++ {
		servers[i] = store.NewStoreServer()
	}
	//server := store.NewStoreServer()

	var e entry
	var firstTime uint64

	scanner := bufio.NewScanner(os.Stdin)
	c := 0
	n := 0
	for scanner.Scan() {
		err := json.Unmarshal([]byte(scanner.Text()), &e)
		if err != nil {
			n += 1
			continue
		}
		if firstTime == 0 {
			firstTime = e.Time
		}
		name := e.timeSeriesName()
		shard := adler32.Checksum([]byte(name)) % NUM_SHARDS
		servers[shard].Put(e.timeSeriesName(), uint32(e.Time/1000), e.Value)
		c += 1
	}

	fmt.Printf("first_time: %d  last_time: %d  delta: %d\n", firstTime/1000, e.Time/1000,
		(e.Time-firstTime)/1000)

	total_bytes, total_series := uint64(0), 0

	for i = 0; i < NUM_SHARDS; i++ {
		bytes_consumed := servers[i].BytesConsumed()
		num_time_series := servers[i].NumTimeSeries()
		fmt.Printf("%02d: bytes=%d #series=%d\n", i, bytes_consumed, num_time_series)
		total_bytes += uint64(bytes_consumed)
		total_series += num_time_series
	}

	fmt.Printf("total: bytes: %d  series: %d   count: %d\n", total_bytes, total_series, c)
	//router := mux.NewRouter().StrictSlash(true)
	//router.HandleFunc("/query", server.Query)
	//log.Fatal(http.ListenAndServe(":8080", router))
}
Exemple #2
0
func TestWalkingSkeleton(t *testing.T) {
	server := store.NewStoreServer()
	server.Put("test.foo.cpu", 60, 10)
	server.Put("test.bar.cpu", 60, 20)
	server.Put("test.bar.cpu", 70, 20)
	server.Put("test.baz.cpu", 60, 20)

	router := mux.NewRouter().StrictSlash(true)
	router.HandleFunc("/", server.Query)

	ts := httptest.NewServer(router)
	defer ts.Close()

	var requestBody struct {
		TimeSeries []string `json:"time_series"`
		Start      uint32   `json:"start"`
		End        uint32   `json:"end"`
	}

	requestBody.TimeSeries = []string{"test.foo.cpu", "test.bar.cpu"}
	requestBody.Start = 0
	requestBody.End = 10000

	var responseBody struct {
		TimeSeries map[string][]store.Point `json:"time_series"`
	}

	session := napping.Session{}
	session.Log = true

	res, _ := session.Post(ts.URL, &requestBody, &responseBody, nil)

	//fmt.Printf("%s\n", res.ResponseBody.Bytes())

	fmt.Printf("WHAT: %v\n", res)
	fmt.Printf("yes: %v\n", responseBody)
}