Skip to content

Commit 9df3ea7

Browse files
committed
Add /machine endpoint for 2.0
Only difference from v1 /machine is that both h/w and s/w state is included.
1 parent 588b149 commit 9df3ea7

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

api/versions.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const (
3737
specApi = "spec"
3838
eventsApi = "events"
3939
storageApi = "storage"
40+
attributesApi = "attributes"
41+
versionApi = "version"
4042
typeName = "name"
4143
typeDocker = "docker"
4244
)
@@ -309,6 +311,35 @@ func (self *version2_0) SupportedRequestTypes() []string {
309311

310312
func (self *version2_0) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
311313
switch requestType {
314+
case versionApi:
315+
glog.V(2).Infof("Api - Version")
316+
versionInfo, err := m.GetVersionInfo()
317+
if err != nil {
318+
return err
319+
}
320+
return writeResult(versionInfo.CadvisorVersion, w)
321+
case attributesApi:
322+
glog.V(2).Info("Api - Attributes")
323+
324+
machineInfo, err := m.GetMachineInfo()
325+
if err != nil {
326+
return err
327+
}
328+
versionInfo, err := m.GetVersionInfo()
329+
if err != nil {
330+
return err
331+
}
332+
info := v2.GetAttributes(machineInfo, versionInfo)
333+
return writeResult(info, w)
334+
case machineApi:
335+
glog.V(2).Info("Api - Machine")
336+
337+
// TODO(rjnagal): Move machineInfo from v1.
338+
machineInfo, err := m.GetMachineInfo()
339+
if err != nil {
340+
return err
341+
}
342+
return writeResult(machineInfo, w)
312343
case summaryApi:
313344
containerName := getContainerName(request)
314345
glog.V(2).Infof("Api - Summary(%v)", containerName)

info/v2/machine.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2015 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v2
16+
17+
import (
18+
// TODO(rjnagal): Move structs from v1.
19+
"github.com/google/cadvisor/info/v1"
20+
)
21+
22+
type Attributes struct {
23+
// Kernel version.
24+
KernelVersion string `json:"kernel_version"`
25+
26+
// OS image being used for cadvisor container, or host image if running on host directly.
27+
ContainerOsVersion string `json:"container_os_version"`
28+
29+
// Docker version.
30+
DockerVersion string `json:"docker_version"`
31+
32+
// cAdvisor version.
33+
CadvisorVersion string `json:"cadvisor_version"`
34+
35+
// The number of cores in this machine.
36+
NumCores int `json:"num_cores"`
37+
38+
// Maximum clock speed for the cores, in KHz.
39+
CpuFrequency uint64 `json:"cpu_frequency_khz"`
40+
41+
// The amount of memory (in bytes) in this machine
42+
MemoryCapacity int64 `json:"memory_capacity"`
43+
44+
// The machine id
45+
MachineID string `json:"machine_id"`
46+
47+
// The system uuid
48+
SystemUUID string `json:"system_uuid"`
49+
50+
// Filesystems on this machine.
51+
Filesystems []v1.FsInfo `json:"filesystems"`
52+
53+
// Disk map
54+
DiskMap map[string]v1.DiskInfo `json:"disk_map"`
55+
56+
// Network devices
57+
NetworkDevices []v1.NetInfo `json:"network_devices"`
58+
59+
// Machine Topology
60+
// Describes cpu/memory layout and hierarchy.
61+
Topology []v1.Node `json:"topology"`
62+
}
63+
64+
func GetAttributes(mi *v1.MachineInfo, vi *v1.VersionInfo) Attributes {
65+
return Attributes{
66+
KernelVersion: vi.KernelVersion,
67+
ContainerOsVersion: vi.ContainerOsVersion,
68+
DockerVersion: vi.DockerVersion,
69+
CadvisorVersion: vi.CadvisorVersion,
70+
NumCores: mi.NumCores,
71+
CpuFrequency: mi.CpuFrequency,
72+
MemoryCapacity: mi.MemoryCapacity,
73+
MachineID: mi.MachineID,
74+
SystemUUID: mi.SystemUUID,
75+
Filesystems: mi.Filesystems,
76+
DiskMap: mi.DiskMap,
77+
NetworkDevices: mi.NetworkDevices,
78+
Topology: mi.Topology,
79+
}
80+
}

0 commit comments

Comments
 (0)