Skip to content

Commit

Permalink
API changes for custom metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
anushree-n committed Jul 20, 2015
1 parent d580ecf commit b197771
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
37 changes: 30 additions & 7 deletions api/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
attributesApi = "attributes"
versionApi = "version"
psApi = "ps"
customMetricsApi = "appmetrics"
)

// Interface for a cAdvisor API version
Expand Down Expand Up @@ -305,7 +306,7 @@ func (self *version2_0) Version() string {
}

func (self *version2_0) SupportedRequestTypes() []string {
return []string{versionApi, attributesApi, eventsApi, machineApi, summaryApi, statsApi, specApi, storageApi, psApi}
return []string{versionApi, attributesApi, eventsApi, machineApi, summaryApi, statsApi, specApi, storageApi, psApi, customMetricsApi}
}

func (self *version2_0) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
Expand Down Expand Up @@ -364,6 +365,24 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
contStats[name] = convertStats(cont)
}
return writeResult(contStats, w)
case customMetricsApi:
containerName := getContainerName(request)
glog.V(4).Infof("Api - Custom Metrics: Looking for metrics for container %q, options %+v", containerName, opt)
conts, err := m.GetRequestedContainersInfo(containerName, opt)
if err != nil {
return err
}
contMetrics := make(map[string][][]info.Metric, 0)
metrics := [][]info.Metric{}
for _, cont := range conts {
contStats := convertStats(cont)
for _, contStat := range contStats {
metric := contStat.CustomMetrics
metrics = append(metrics, metric)
}
contMetrics[containerName] = metrics
}
return writeResult(contMetrics, w)
case specApi:
containerName := getContainerName(request)
glog.V(4).Infof("Api - Spec for container %q, options %+v", containerName, opt)
Expand Down Expand Up @@ -412,12 +431,13 @@ func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
stats := []v2.ContainerStats{}
for _, val := range cont.Stats {
stat := v2.ContainerStats{
Timestamp: val.Timestamp,
HasCpu: cont.Spec.HasCpu,
HasMemory: cont.Spec.HasMemory,
HasNetwork: cont.Spec.HasNetwork,
HasFilesystem: cont.Spec.HasFilesystem,
HasDiskIo: cont.Spec.HasDiskIo,
Timestamp: val.Timestamp,
HasCpu: cont.Spec.HasCpu,
HasMemory: cont.Spec.HasMemory,
HasNetwork: cont.Spec.HasNetwork,
HasFilesystem: cont.Spec.HasFilesystem,
HasDiskIo: cont.Spec.HasDiskIo,
HasCustomMetrics: cont.Spec.HasCustomMetrics,
}
if stat.HasCpu {
stat.Cpu = val.Cpu
Expand All @@ -434,6 +454,9 @@ func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
if stat.HasDiskIo {
stat.DiskIo = val.DiskIo
}
if stat.HasCustomMetrics {
stat.CustomMetrics = val.CustomMetrics
}
// TODO(rjnagal): Handle load stats.
stats = append(stats, stat)
}
Expand Down
5 changes: 5 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type ContainerSpec struct {

// HasDiskIo when true, indicates that DiskIo stats will be available.
HasDiskIo bool `json:"has_diskio"`

HasCustomMetrics bool `json:"has_custom_metrics"`
}

// Container reference contains enough information to uniquely identify a container
Expand Down Expand Up @@ -190,6 +192,9 @@ func (self *ContainerSpec) Eq(b *ContainerSpec) bool {
if self.HasDiskIo != b.HasDiskIo {
return false
}
if self.HasCustomMetrics != b.HasCustomMetrics {
return false
}
return true
}

Expand Down
5 changes: 5 additions & 0 deletions info/v2/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ type ContainerSpec struct {
HasMemory bool `json:"has_memory"`
Memory MemorySpec `json:"memory,omitempty"`

HasCustomMetrics bool `json:"has_custom_metrics"`

// Following resources have no associated spec, but are being isolated.
HasNetwork bool `json:"has_network"`
HasFilesystem bool `json:"has_filesystem"`
Expand Down Expand Up @@ -100,6 +102,9 @@ type ContainerStats struct {
// Task load statistics
HasLoad bool `json:"has_load"`
Load v1.LoadStats `json:"load_stats,omitempty"`
//Custom statistics
HasCustomMetrics bool `json:"has_custom_metrics"`
CustomMetrics []v1.Metric `json:"custom_metrics,omitempty"`
}

type Percentiles struct {
Expand Down

0 comments on commit b197771

Please sign in to comment.