Exemplo n.º 1
0
func (this *CardinalityOutput) handleHttpRequest(w http.ResponseWriter,
	req *http.Request, params map[string]interface{}) (interface{}, error) {
	vars := mux.Vars(req)
	key := vars["key"]
	globals := engine.Globals()
	if globals.Verbose {
		globals.Println(req.Method, key)
	}

	output := make(map[string]interface{})
	switch req.Method {
	case "GET":
		if key == "all" {
			for _, c := range this.counters.Categories() {
				output[c] = fmt.Sprintf("[%v] %d",
					bjtime.TsToString(int(this.counters.StartedAt(c).Unix())),
					this.counters.Count(c))
			}
		} else {
			output[key] = this.counters.Count(key)
		}

	case "PUT":
		this.counters.Reset(key)
		output["msg"] = "ok"
	}

	return output, nil
}
Exemplo n.º 2
0
func (this *alarmWorker) printWindowTitle(head, tail int, title string) {
	this.colorPrintfLn(false, "(%s  ~  %s) %s", bjtime.TsToString(head),
		bjtime.TsToString(tail), title)
}