func containerCpuUsageHandler(params martini.Params) (int, string) { id := params["id"] containerCpu, err := cpu.GetUsage(id) if err != nil { return 200, err.Error() } containerCpuStr := strconv.FormatInt(containerCpu, 10) return 200, containerCpuStr }
func containerCpuUsageHandler(res http.ResponseWriter, req *http.Request, params martini.Params) { id := params["id"] containerCpuUsage, err := cpu.GetUsage(id) if err != nil { res.WriteHeader(500) res.Header().Set("Content-Type", "text/plain") fmt.Fprintf(res, err.Error()) return } res.WriteHeader(200) json.NewEncoder(res).Encode(&containerCpuUsage) }
func containerUsageHandler(res http.ResponseWriter, req *http.Request, params martini.Params) { id := params["id"] usage := client.Usage{} memUsage, err := mem.GetUsage(id) if err != nil { res.WriteHeader(500) res.Header().Set("Content-Type", "text/plain") fmt.Fprintf(res, err.Error()) return } usage.Memory = &memUsage.MemoryUsage cpuUsage, err := cpu.GetUsage(id) if err != nil { res.WriteHeader(500) res.Header().Set("Content-Type", "text/plain") fmt.Fprintf(res, err.Error()) return } usage.Cpu = (*client.CpuUsage)(&cpuUsage) if req.URL.Query().Get("net") == "true" { netUsage, err := net.GetUsage(id) if err != nil { res.WriteHeader(500) res.Header().Set("Content-Type", "text/plain") res.Write([]byte(err.Error())) return } usage.Net = (*client.NetUsage)(&netUsage) } res.WriteHeader(200) json.NewEncoder(res).Encode(&usage) }