コード例 #1
0
ファイル: quasarProvider.go プロジェクト: gtfierro/giles2
func (q *quasarDB) receiveStats(conn *tsConn) (common.StatisticalNumbersResponse, error) {
	var sr = common.StatisticalNumbersResponse{}
	seg, err := capn.ReadFromStream(conn, nil)
	if err != nil {
		conn.Close()
		log.Errorf("Error receiving data from Quasar %v", err)
		return sr, err
	}
	resp := qsr.ReadRootResponse(seg)

	//log.Debug("qsr resp %v", resp.Which())
	//log.Debug("status code %v", resp.StatusCode())
	switch resp.Which() {
	case qsr.RESPONSE_VOID:
		if resp.StatusCode() != qsr.STATUSCODE_OK {
			return sr, fmt.Errorf("Received error status code when writing: %v", resp.StatusCode())
		}
	case qsr.RESPONSE_RECORDS:
		if resp.StatusCode() != 0 {
			return sr, fmt.Errorf("Error when reading from Quasar: %v", resp.StatusCode().String())
		}
		sr.Readings = []*common.StatisticalNumberReading{}
		for _, rec := range resp.StatisticalRecords().Values().ToArray() {
			sr.Readings = append(sr.Readings, &common.StatisticalNumberReading{
				Time: uint64(rec.Time()), Count: rec.Count(),
				Min: rec.Min(), Mean: rec.Mean(), Max: rec.Max(),
				UoT: common.UOT_NS})
		}
		return sr, nil
	default:
		return sr, fmt.Errorf("Got unexpected Quasar Error code (%v)", resp.StatusCode().String())
	}
	return sr, nil

}
コード例 #2
0
ファイル: btrdbProvider.go プロジェクト: gtfierro/giles2
func (bdb *btrIface) statisticalResponseFromChan(c chan btrdb.StatisticalValue) common.StatisticalNumbersResponse {
	var sr = common.StatisticalNumbersResponse{
		Readings: []*common.StatisticalNumberReading{},
	}
	for val := range c {
		sr.Readings = append(sr.Readings, &common.StatisticalNumberReading{Time: uint64(val.Time), Count: val.Count, Min: val.Min, Max: val.Max, Mean: val.Mean, UoT: common.UOT_NS})
	}
	return sr
}