예제 #1
0
파일: render.go 프로젝트: kuba--/yag
// GET: /render?target=my.key&from=-1h[&to=...&jsonp=...]
func (h *RenderHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case "GET":
		glog.Infof("%v\n", r.URL)
		err := h.parseQuery(r)
		if err != nil {
			glog.Warningln(err)
			http.Error(w, err.Error(), http.StatusBadRequest)
			return
		}
		h.jsonResponse(w, api.Eval(h.target, h.from, h.to, &metrics.Api{h.maxDataPoints}))
		glog.Flush()

	default:
		http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
	}
}
예제 #2
0
파일: listener.go 프로젝트: kuba--/yag
// Handle TCP Connections
func handle(conn net.Conn) {
	glog.Infof("Connection: %s -> %s\n", conn.RemoteAddr(), conn.LocalAddr())
	defer func() {
		glog.Infof("Closing connection: %s\n", conn.RemoteAddr())
		conn.Close()
		glog.Flush()
	}()

	scanner := bufio.NewScanner(conn)
	for scanner.Scan() {
		if m := strings.Split(scanner.Text(), " "); len(m) > 2 {
			if ts, err := strconv.ParseInt(m[2], 10, 0); err != nil {
				glog.Warningln(err)
				continue
			} else {
				metrics.Add(m[0], m[1], ts)
			}
		}
	}

	if err := scanner.Err(); err != nil {
		glog.Errorln(err)
	}
}