// Client represents the base URL for a cAdvisor client.typeClientstruct { baseUrl string}// NewClient returns a new v1.3 client with the specified base URL.funcNewClient(url string) (*Client, error) {if!strings.HasSuffix(url, "/") { url +="/" }return&Client{ baseUrl: fmt.Sprintf("%sapi/v1.3/", url), }, nil}
4.2.2. client方法
1)MachineInfo
// MachineInfo returns the JSON machine information for this client.// A non-nil error result indicates a problem with obtaining// the JSON machine information data.func (self *Client) MachineInfo() (minfo *v1.MachineInfo, err error) { u := self.machineInfoUrl() ret :=new(v1.MachineInfo)if err = self.httpGetJsonData(ret, nil, u, "machine info"); err !=nil {return } minfo = retreturn}
2)ContainerInfo
// ContainerInfo returns the JSON container information for the specified// container and request.func (self *Client) ContainerInfo(name string, query *v1.ContainerInfoRequest) (cinfo *v1.ContainerInfo, err error) { u := self.containerInfoUrl(name) ret :=new(v1.ContainerInfo)if err = self.httpGetJsonData(ret, query, u, fmt.Sprintf("container info for %q", name)); err !=nil {return } cinfo = retreturn}
3)DockerContainer
// Returns the JSON container information for the specified// Docker container and request.func (self *Client) DockerContainer(name string, query *v1.ContainerInfoRequest) (cinfo v1.ContainerInfo, err error) { u := self.dockerInfoUrl(name) ret :=make(map[string]v1.ContainerInfo)if err = self.httpGetJsonData(&ret, query, u, fmt.Sprintf("Docker container info for %q", name)); err !=nil {return }iflen(ret) !=1 { err = fmt.Errorf("expected to only receive 1 Docker container: %+v", ret)return }for _, cont :=range ret { cinfo = cont }return}
4)AllDockerContainers
// Returns the JSON container information for all Docker containers.func (self *Client) AllDockerContainers(query *v1.ContainerInfoRequest) (cinfo []v1.ContainerInfo, err error) { u := self.dockerInfoUrl("/") ret :=make(map[string]v1.ContainerInfo)if err = self.httpGetJsonData(&ret, query, u, "all Docker containers info"); err !=nil {return } cinfo =make([]v1.ContainerInfo, 0, len(ret))for _, cont :=range ret { cinfo =append(cinfo, cont) }return}
分类
字段
描述
cpu
cpu_usage_total
cpu_usage_system
cpu_usage_user
cpu_usage_per_cpu
load_average
Smoothed average of number of runnable threads x 1000