Пример #1
0
// MockBatchPoints returns a mock BatchPoints object for using in unit tests
// of telegraf output sinks.
func MockBatchPoints() client.BatchPoints {
	var bp client.BatchPoints
	bp.Time = time.Now()
	bp.Tags = map[string]string{"tag1": "value1"}
	bp.Points = []client.Point{
		{
			Fields: map[string]interface{}{"value": 1.0},
		},
	}
	return bp
}
Пример #2
0
// Choose a random server in the cluster to write to until a successful write
// occurs, logging each unsuccessful. If all servers fail, return error.
func (i *InfluxDB) Write(bp client.BatchPoints) error {
	bp.Database = i.Database

	// This will get set to nil if a successful write occurs
	err := errors.New("Could not write to any InfluxDB server in cluster")

	p := rand.Perm(len(i.conns))
	for _, n := range p {
		if _, e := i.conns[n].Write(bp); e != nil {
			log.Println("ERROR: " + e.Error())
		} else {
			err = nil
			break
		}
	}
	return err
}