Example #1
0
func ClockSource(es eventsource.EventSource) {
	id := 1
	for {
		es.SendEventMessage(fmt.Sprintf("%d", es.ConsumersCount()), "consumer-count", "")
		es.SendEventMessage("tick", "tick-event", strconv.Itoa(id))
		id++
		time.Sleep(5 * time.Second)
	}
}
Example #2
0
func notifyClients(rediscommand_ch <-chan redis_protocol.RedisCommand, es eventsource.EventSource) {
	for {
		select {
		case command := <-rediscommand_ch:
			b, err := json.Marshal(command)
			if err != nil {
				fmt.Println("error:", err)
			} else {
				es.SendEventMessage(string(b), "", "")
			}
		}
	}
}
Example #3
0
func Add(conf *Conf, db database.Db, es eventsource.EventSource) http.Handler {
	return mux.Method{
		"GET": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			body := views.Add.RenderInLayout(views.Layout, ctx(conf, db, r, true))
			w.Header().Add("Content-Type", "text/html")
			fmt.Fprintf(w, body)
		}),
		"POST": http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			db.Save(time.Now(), r.PostFormValue("body"))
			es.SendEventMessage(r.PostFormValue("body"), "add-post", "")
			http.Redirect(w, r, "/", 301)
		}),
	}
}
Example #4
0
func parseAndSendMetrics(host string, buffer []byte, es eventsource.EventSource) {
	var m Metrics
	err := json.Unmarshal(buffer, &m)
	if err != nil {
		fmt.Println(err)
		return
	}
	//fmt.Println(host, m)
	es.SendEventMessage(fmt.Sprintf("{\"temp\":%f,\"freq\":%f}", m.CpuTemp, m.CpuFreq), fmt.Sprintf("%s-%s", host, "cpuphys"), "")
	usage, _ := json.Marshal(m.CoreUsage)
	es.SendEventMessage(fmt.Sprintf("{\"percent\":%f,\"cores\":%s}", m.CpuUsage, usage), fmt.Sprintf("%s-%s", host, "cpuusage"), "")
	es.SendEventMessage(fmt.Sprintf("{\"total\":%f,\"free\":%f,\"swaptotal\":%f,\"swapfree\":%f}",
		m.MemInfo.MemTotal, m.MemInfo.MemFree, m.MemInfo.SwapTotal, m.MemInfo.SwapFree), fmt.Sprintf("%s-%s", host, "memusage"), "")
}