示例#1
0
文件: api.go 项目: gtfierro/giles2
func (a *Archiver) prepareDataParams(params *common.DataParams) (err error) {
	// parse and evaluate the where clause if we need to
	if len(params.Where) > 0 {
		params.UUIDs, err = a.mdStore.GetUUIDs(params.Where.ToBson())
		if err != nil {
			return err
		}
	}

	// apply the streamlimit if it exists
	if params.StreamLimit > 0 && len(params.UUIDs) > params.StreamLimit {
		params.UUIDs = params.UUIDs[:params.StreamLimit]
	}

	// make sure that Begin/End are both in nanoseconds
	if begin_uot := common.GuessTimeUnit(params.Begin); begin_uot != common.UOT_NS {
		params.Begin, err = common.ConvertTime(params.Begin, begin_uot, common.UOT_NS)
		if err != nil {
			return err
		}
	}
	if end_uot := common.GuessTimeUnit(params.End); end_uot != common.UOT_NS {
		params.End, err = common.ConvertTime(params.End, end_uot, common.UOT_NS)
		if err != nil {
			return err
		}
	}
	return nil
}
示例#2
0
func (msg Statistics) ToReadings() []common.Reading {
	lesserLength := int(math.Min(float64(len(msg.Times)), float64(len(msg.Count))))
	var res = make([]common.Reading, lesserLength)
	for idx := 0; idx < lesserLength; idx++ {
		res[idx] = &common.StatisticalNumberReading{Time: msg.Times[idx], UoT: common.GuessTimeUnit(msg.Times[idx]), Count: msg.Count[idx], Min: msg.Min[idx], Max: msg.Max[idx], Mean: msg.Mean[idx]}
	}
	return res
}
示例#3
0
// Takes an incoming common.SmapMessage object (from a client) and does the following:
//  - Checks the incoming message against the ApiKey to verify it is valid to write
//  - Saves the attached metadata (if any) to the metadata store
//  - Reevaluates any dynamic subscriptions and pushes to republish clients
//  - Saves the attached readings (if any) to the timeseries database
func (a *Archiver) AddData(msg *common.SmapMessage) (err error) {
	// save metadata
	err = a.mdStore.SaveTags(msg)
	if err != nil {
		return err
	}

	// fix inconsistencies
	var (
		uot common.UnitOfTime
		uom string
	)
	if uot, err = a.mdStore.GetUnitOfTime(msg.UUID); uot == 0 && err == nil {
		if len(msg.Readings) > 0 {
			uot = common.GuessTimeUnit(msg.Readings[0].GetTime())
		}
	} else if err != nil {
		return err
	}
	for _, rdg := range msg.Readings {
		rdg.SetUOT(uot)
	}

	if uom, err = a.mdStore.GetUnitOfMeasure(msg.UUID); uom == "" && err == nil {
		if msg.Properties == nil {
			msg.Properties = &common.SmapProperties{StreamType: common.NUMERIC_STREAM}
		}
		msg.Properties.UnitOfMeasure = "n/a"
		err = a.mdStore.SaveTags(msg)
		if err != nil {
			return err
		}
	} else if err != nil {
		return err
	}

	//save timeseries data
	a.metrics["adds"].Mark(1)
	a.tsStore.AddMessage(msg)
	a.broker.HandleMessage(msg)
	return err
}
示例#4
0
func (msg Timeseries) ToReadings() []common.Reading {
	lesserLength := int(math.Min(float64(len(msg.Times)), float64(len(msg.Values))))
	var res = make([]common.Reading, lesserLength)
	for idx := 0; idx < lesserLength; idx++ {
		res[idx] = &common.SmapNumberReading{Time: msg.Times[idx], Value: msg.Values[idx], UoT: common.GuessTimeUnit(msg.Times[idx])}
	}
	return res
}