func containerNetUsageHandler(params martini.Params, res http.ResponseWriter) { id := params["id"] containerNet, err := net.GetUsage(id) if err != nil { res.Write([]byte(err.Error())) return } res.WriteHeader(200) json.NewEncoder(res).Encode(&containerNet) }
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) }