示例#1
0
func SendMetricsToRiak(address []string, metrics Sensors, hostname string) (err error) {
	started := time.Now()
	for _, m := range metrics {
		if err = db.Store(SENSORSBUCKET, m.Id, m); err != nil {
			log.Debugf(err.Error())
			continue
		}
	}
	log.Debugf("sent %d metrics in %.06f\n", len(metrics), time.Since(started).Seconds())
	return nil
}
示例#2
0
func (b *Balances) Deduct(bopts *BalanceOpts) error {
	b.CreatedAt = time.Now().Local().Format(time.RFC822)

	if avail, err := strconv.Atoi(b.Credit); err != nil {
		b.Credit = string(avail - bopts.Consumed)
	}

	if err := db.Store(BALANCESBUCKET, bopts.Id, b); err != nil {
		return err
	}
	return nil
}
示例#3
0
//update outputs in riak, nuke the matching keys available
func (a *Ambly) NukeAndSetOutputs(m map[string][]string) error {
	if len(m) > 0 {
		log.Debugf("nuke and set outputs in riak [%s]", m)
		a.Outputs.NukeAndSet(m) //just nuke the matching output key:
		if err := db.Store(ASSEMBLYBUCKET, a.Id, a); err != nil {
			return err
		}
	} else {
		return provision.ErrNoOutputsFound
	}
	return nil
}
示例#4
0
func (a *Ambly) SetStatus(status provision.Status) error {
	LastStatusUpdate := time.Now().Local().Format(time.RFC822)
	m := make(map[string][]string, 2)
	m["lastsuccessstatusupdate"] = []string{LastStatusUpdate}
	m["status"] = []string{status.String()}
	a.Inputs.NukeAndSet(m) //just nuke the matching output key:
	a.Status = status.String()

	if err := db.Store(ASSEMBLYBUCKET, a.Id, a); err != nil {
		fmt.Println(err)
		return err
	}
	return nil
}