func (p *parser) handleHkRouter(t *tuple) error { if string(p.lr.Header().Procid) != routerPrefix { return nil } id := new(bucket.Id) id.Resolution = p.Resolution() id.Time = p.Time() id.User = p.User() id.Pass = p.Pass() id.Source = p.ld.Source() id.Units = t.Units() switch t.Name() { case "bytes": id.Name = p.Prefix("router.bytes") case "connect": id.Name = p.Prefix("router.connect") case "service": id.Name = p.Prefix("router.service") default: return nil } val, err := t.Float64() if err != nil { return err } p.out <- &bucket.Bucket{Id: id, Vals: []float64{val}} return nil }
func (p *parser) handleCounters(t *tuple) error { if !strings.HasPrefix(t.Name(), counterPrefix) { return nil } id := new(bucket.Id) p.buildId(id, t) id.Type = "counter" val, err := t.Float64() if err != nil { return err } p.out <- &bucket.Bucket{Id: id, Vals: []float64{val}} return nil }
func (p *parser) handleLegacyMeasurements(t *tuple) error { if !strings.HasPrefix(t.Name(), legacyPrefix) { return nil } id := new(bucket.Id) p.buildId(id, t) id.Type = "measurement" val, err := t.Float64() if err != nil { return err } p.out <- &bucket.Bucket{Id: id, Vals: []float64{val}} return nil }
func (s *RedisStore) putback(id *bucket.Id) error { defer utils.MeasureT("bucket.putback", time.Now()) rc := s.redisPool.Get() defer rc.Close() key := id.Encode() partition := s.bucketPartition([]byte(key)) rc.Send("MULTI") rc.Send("SADD", partition, key) rc.Send("EXPIRE", partition, 300) _, err := rc.Do("EXEC") if err != nil { return err } return nil }
func (s *RedisStore) Scan(schedule time.Time) (<-chan *bucket.Bucket, error) { retBuckets := make(chan *bucket.Bucket) p, err := s.lockPartition() if err != nil { return retBuckets, err } partition := partitionPrefix + "." + strconv.Itoa(int(p)) go func(out chan *bucket.Bucket) { rc := s.redisPool.Get() defer rc.Close() defer close(out) defer s.unlockPartition(p) rc.Send("MULTI") rc.Send("SMEMBERS", partition) rc.Send("DEL", partition) reply, err := redis.Values(rc.Do("EXEC")) if err != nil { fmt.Printf("at=%q error=%s\n", "bucket-store-scan", err) return } var delCount int64 var members []string redis.Scan(reply, &members, &delCount) for _, member := range members { id := new(bucket.Id) err := id.Decode(bytes.NewBufferString(member)) if err != nil { fmt.Printf("at=%q error=%s\n", "bucket-store-parse-key", err) continue } bucketReady := id.Time.Add(id.Resolution) if !bucketReady.After(schedule) { out <- &bucket.Bucket{Id: id} } else { if err := s.putback(id); err != nil { fmt.Printf("putback-error=%s\n", err) } } } }(retBuckets) return retBuckets, nil }
func testBucket(name, source, user, pass string, t time.Time, res time.Duration, vals []float64) *bucket.Bucket { id := new(bucket.Id) id.Name = name id.Source = source id.User = user id.Pass = pass id.Time = t.Truncate(res) id.Resolution = res return &bucket.Bucket{Id: id, Vals: vals} }
func (p *parser) buildId(id *bucket.Id, t *tuple) { id.Resolution = p.Resolution() id.Time = p.Time() id.Auth = p.Auth() id.ReadyAt = id.Time.Add(id.Resolution).Truncate(id.Resolution) id.Name = p.Prefix(t.Name()) id.Units = t.Units() id.Source = p.SourcePrefix(p.ld.Source()) return }
func (p *parser) buildId(id *bucket.Id, t *tuple) { id.Resolution = p.Resolution() id.Time = p.Time() id.User = p.User() id.Pass = p.Pass() id.Name = p.Prefix(t.Name()) id.Units = t.Units() id.Source = p.ld.Source() return }
func (p *parser) handleHkRouter(t *tuple) error { if string(p.lr.Header().Procid) != routerPrefix { return nil } id := new(bucket.Id) p.buildId(id, t) id.Type = "measurement" switch t.Name() { case "bytes": id.Name = p.Prefix("router.bytes") case "connect": id.Name = p.Prefix("router.connect") case "service": id.Name = p.Prefix("router.service") default: return nil } val, err := t.Float64() if err != nil { return err } p.out <- &bucket.Bucket{Id: id, Vals: []float64{val}} return nil }
func (p *parser) handlMeasurements(t *tuple) error { if !strings.HasPrefix(t.Name(), measurePrefix) { return nil } id := new(bucket.Id) id.Resolution = p.Resolution() id.Time = p.Time() id.User = p.User() id.Pass = p.Pass() id.Name = p.Prefix(t.Name()) id.Units = t.Units() id.Source = p.ld.Source() val, err := t.Float64() if err != nil { return err } p.out <- &bucket.Bucket{Id: id, Vals: []float64{val}} return nil }