コード例 #1
0
ファイル: server.go プロジェクト: godeep/go-batsd
func (c *Client) SendValuesFromHbase(keyname string, retentionInterval int64, start_ts float64, end_ts float64, operation string) {
	start := time.Now().UnixNano()
	hbaseClient := hbasePool.GetConnection().(*goh.HClient)

	var result []*Hbase.TCell
	var err error
	if keyname[0] == 'g' { //this is a gauge, so no way to know how many of them there are. get a  bunch
		result, err = hbaseClient.GetVerTs(gobatsd.Config.HbaseTable, []byte(keyname), fmt.Sprintf("interval%v:%v", retentionInterval, operation), int64(end_ts), 1000000, nil)
	} else {
		result, err = hbaseClient.GetVerTs(gobatsd.Config.HbaseTable, []byte(keyname), fmt.Sprintf("interval%v:%v", retentionInterval, operation), int64(end_ts), int32(int64(end_ts-start_ts)/retentionInterval), nil)
	}
	if err != nil {
		fmt.Printf("%v\n", err)
	}
	values := make([]map[string]string, 0)
	for i := range result {

		decodedVal, err := gobatsd.DecodeFloat64(result[i].Value)
		if err == nil {
			values = append(values, map[string]string{"Timestamp": strconv.FormatInt(result[i].Timestamp, 10), "Value": strconv.FormatFloat(decodedVal, 'f', -1, 64)})
		}
	}
	fmt.Printf("Hbase completed request in %v ms, retrieved %v records\n", (time.Now().UnixNano()-start)/int64(time.Millisecond), len(values))

	json := gobatsd.ArtisinallyMarshallDatapointJSON(values)
	c.Write(append(json, '\n'))
	hbasePool.ReleaseConnection(hbaseClient)
	fmt.Printf("Total time to respond to client: %v ms\n", (time.Now().UnixNano()-start)/int64(time.Millisecond))
}
コード例 #2
0
ファイル: server.go プロジェクト: godeep/go-batsd
func (c *Client) SendValuesFromDisk(datatype string, path string, start_ts float64, end_ts float64,
	version string, operation string) {
	file, err := os.Open(path)
	values := make([]map[string]string, 0)
	if err == nil {
		reader := bufio.NewReader(file)
		linesRead := 0
		for {
			line, err := reader.ReadString('\n')
			linesRead += 1
			if err != nil && err != io.EOF {
				panic(err)
			}
			if err != nil && err == io.EOF {
				break
			}
			//skip the header in v2 files
			if linesRead == 1 && version == ":2" {
				continue
			}

			parts := strings.Split(strings.TrimSpace(line), " ")
			ts, _ := strconv.ParseFloat(parts[0], 64)
			if ts >= start_ts && ts <= end_ts {
				if datatype == "gauge" || datatype == "counter" {
					values = append(values, map[string]string{"Timestamp": parts[0], "Value": parts[1]})
				} else if datatype == "timer" {
					if headerIndex, ok := timerHeader[operation]; ok {
						values = append(values, map[string]string{"Timestamp": parts[0], "Value": strings.Split(parts[1], "/")[headerIndex]})
					}
				}
			}
			if ts > end_ts {
				break
			}
		}
	} else {
		fmt.Printf("%v\n", err)
	}
	json := gobatsd.ArtisinallyMarshallDatapointJSON(values)
	c.Write(append(json, '\n'))

}
コード例 #3
0
ファイル: server.go プロジェクト: godeep/go-batsd
func (c *Client) SendValuesFromRedis(datatype string, keyname string, start_ts float64, end_ts float64,
	version string, operation string) {

	values := make([]map[string]string, 0)
	v, redisErr := c.redis.Do("ZRANGEBYSCORE", keyname, start_ts, end_ts)
	if redisErr == nil {
		stringValues, _ := redis.Strings(v, redisErr)
		for i := range stringValues {
			parts := strings.Split(stringValues[i], "<X>")
			if datatype == "counter" {
				values = append(values, map[string]string{"Timestamp": parts[0], "Value": parts[1]})
			} else if datatype == "timer" {
				if headerIndex, ok := timerHeader[operation]; ok {
					values = append(values, map[string]string{"Timestamp": parts[0], "Value": strings.Split(parts[1], "/")[headerIndex]})
				}
			}

		}
	} else {
		fmt.Printf("%v\n", redisErr)
	}
	json := gobatsd.ArtisinallyMarshallDatapointJSON(values)
	c.Write(append(json, '\n'))
}