コード例 #1
0
ファイル: pixel.go プロジェクト: tgres/tgres
func pixelAggHandler(r *http.Request, w http.ResponseWriter, rcvr *receiver.Receiver, cmd aggregator.AggCmd) {
	defer func() {
		if rc := recover(); rc != nil {
			log.Printf("pixelAggHandler: Recovered (this request is dropped): %v", rc)
		}
	}()

	sendPixel(w)

	err := r.ParseForm()
	if err != nil {
		log.Printf("pixelAggHandler: error from ParseForm(): %v", err)
		return
	}

	for name, vals := range r.Form {

		// foo.bar.baz=12.345

		for _, valStr := range vals {

			var val float64
			n, _ := fmt.Sscanf(valStr, "%f", &val)
			if n < 1 {
				log.Printf("PixelAddHandler: error parsing %q", valStr)
				return
			}

			rcvr.QueueAggregatorCommand(aggregator.NewCommand(cmd, misc.SanitizeName(name), val))
		}
	}

}
コード例 #2
0
ファイル: services.go プロジェクト: tgres/tgres
// TODO isn't this identical to handleGraphiteTextProtocol?
func handleStatsdTextProtocol(rcvr *receiver.Receiver, conn net.Conn, timeout int) {
	defer conn.Close() // decrements graceful.TcpWg

	if timeout != 0 {
		conn.SetDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
	}

	// We use the Scanner, becase it has a MaxScanTokenSize of 64K

	connbuf := bufio.NewScanner(conn)

	for connbuf.Scan() {
		if stat, err := statsd.ParseStatsdPacket(connbuf.Text()); err == nil {
			rcvr.QueueAggregatorCommand(stat.AggregatorCmd())
		} else {
			log.Printf("parseStatsdPacket(): %v", err)
		}

		if timeout != 0 {
			conn.SetDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
		}
	}

	if err := connbuf.Err(); err != nil {
		if !strings.Contains(err.Error(), "use of closed") {
			log.Println("handleStatsdTextProtocol(): Error reading: %v", err)
		}
	}
}