Exemplo n.º 1
0
func main() {
	flag.Parse()

	out, err := statstore.GetStorer(*outPath)
	if err != nil {
		log.Fatalf("Error creating storer: %v", err)
	}
	defer out.Close()

	client := connect()
	if client == nil {
		log.Fatalf("Error making first connection to couch")
	}
	defer client.Close()

	proto := map[string]interface{}{}
	if *protoFile != "" {
		f, err := os.Open(*protoFile)
		if err != nil {
			log.Fatalf("Error opening proto file:  %v", err)
		}
		err = json.NewDecoder(f).Decode(&proto)
		if err != nil {
			log.Fatalf("Error parsing proto: %v", err)
		}
	}

	gatherStats(client, out, proto)
}
Exemplo n.º 2
0
func MemcachedBinaryTargetStartIncoming(s MemcachedBinaryTarget, incoming chan []Request) {
	client, err := memcached.Connect("tcp", s.spec)
	if err != nil {
		log.Fatalf("error: memcached-binary connect failed: %s; err: %v", s.spec, err)
	}

	go func() {
		for reqs := range incoming {
			for _, req := range reqs {
				log.Printf("sending.....: %s; err: %v", s.spec, err)
				res, err := client.Send(req.Req)
				log.Printf("sending.done: %s; err: %v", s.spec, err)
				if err != nil {
					req.Res <- &gomemcached.MCResponse{
						Opcode: req.Req.Opcode,
						Status: gomemcached.EINVAL,
						Opaque: req.Req.Opaque,
					}
					log.Printf("warn: memcached-binary closing conn; saw error: %v", err)
					client.Close()
					client = Reconnect(s.spec, func(spec string) (interface{}, error) {
						return memcached.Connect("tcp", spec)
					}).(*memcached.Client)
				} else {
					req.Res <- res
				}
			}
		}
	}()
}