Exemple #1
0
func wsMemoryConsoHandler(ws *websocket.Conn) {
	for {
		memory := new(linuxproc.Memory)
		mf, _ := memory.MemFree()
		mt, _ := memory.MemTotal()
		// utiliser json.MArshal car là, c'est moche ...
		msg := fmt.Sprintf("[{\"name\":\"free\",\"y\":%.2f,\"color\":\"#D0FA58\"},{\"name\":\"occ\",\"y\":%.2f,\"color\":\"#F78181\"}]", float32(mf)*9.53674316406E-7, float32(mt)*9.53674316406E-7-float32(mf)*9.53674316406E-7)
		name := []byte(msg)
		ws.Write(name)
		time.Sleep(250 * time.Millisecond)
	}
}
Exemple #2
0
func mainHandler() http.Handler {

	type Data struct {
		Apps     []App
		MemTotal float32
		MemFree  float32
	}

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		tpl, err := template.ParseFiles("tpl/main.html")
		if err != nil {
			log.Printf("%s", err)
		}

		data := new(Data)
		memory := new(linuxproc.Memory)
		memFree, _ := memory.MemFree()
		data.MemFree = float32(memFree) * 9.53674316406E-7
		memTotal, _ := memory.MemTotal()
		data.MemTotal = float32(memTotal)*9.53674316406E-7 - data.MemFree
		data.Apps = listProcess()
		tpl.Execute(w, data)
	})
}