API changes for custom metrics
This commit is contained in:
parent
d580ecfc53
commit
b197771668
@ -39,6 +39,7 @@ const (
|
|||||||
attributesApi = "attributes"
|
attributesApi = "attributes"
|
||||||
versionApi = "version"
|
versionApi = "version"
|
||||||
psApi = "ps"
|
psApi = "ps"
|
||||||
|
customMetricsApi = "appmetrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface for a cAdvisor API version
|
// Interface for a cAdvisor API version
|
||||||
@ -305,7 +306,7 @@ func (self *version2_0) Version() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *version2_0) SupportedRequestTypes() []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 {
|
func (self *version2_0) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
|
||||||
@ -364,6 +365,24 @@ func (self *version2_0) HandleRequest(requestType string, request []string, m ma
|
|||||||
contStats[name] = convertStats(cont)
|
contStats[name] = convertStats(cont)
|
||||||
}
|
}
|
||||||
return writeResult(contStats, w)
|
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:
|
case specApi:
|
||||||
containerName := getContainerName(request)
|
containerName := getContainerName(request)
|
||||||
glog.V(4).Infof("Api - Spec for container %q, options %+v", containerName, opt)
|
glog.V(4).Infof("Api - Spec for container %q, options %+v", containerName, opt)
|
||||||
@ -412,12 +431,13 @@ func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
|
|||||||
stats := []v2.ContainerStats{}
|
stats := []v2.ContainerStats{}
|
||||||
for _, val := range cont.Stats {
|
for _, val := range cont.Stats {
|
||||||
stat := v2.ContainerStats{
|
stat := v2.ContainerStats{
|
||||||
Timestamp: val.Timestamp,
|
Timestamp: val.Timestamp,
|
||||||
HasCpu: cont.Spec.HasCpu,
|
HasCpu: cont.Spec.HasCpu,
|
||||||
HasMemory: cont.Spec.HasMemory,
|
HasMemory: cont.Spec.HasMemory,
|
||||||
HasNetwork: cont.Spec.HasNetwork,
|
HasNetwork: cont.Spec.HasNetwork,
|
||||||
HasFilesystem: cont.Spec.HasFilesystem,
|
HasFilesystem: cont.Spec.HasFilesystem,
|
||||||
HasDiskIo: cont.Spec.HasDiskIo,
|
HasDiskIo: cont.Spec.HasDiskIo,
|
||||||
|
HasCustomMetrics: cont.Spec.HasCustomMetrics,
|
||||||
}
|
}
|
||||||
if stat.HasCpu {
|
if stat.HasCpu {
|
||||||
stat.Cpu = val.Cpu
|
stat.Cpu = val.Cpu
|
||||||
@ -434,6 +454,9 @@ func convertStats(cont *info.ContainerInfo) []v2.ContainerStats {
|
|||||||
if stat.HasDiskIo {
|
if stat.HasDiskIo {
|
||||||
stat.DiskIo = val.DiskIo
|
stat.DiskIo = val.DiskIo
|
||||||
}
|
}
|
||||||
|
if stat.HasCustomMetrics {
|
||||||
|
stat.CustomMetrics = val.CustomMetrics
|
||||||
|
}
|
||||||
// TODO(rjnagal): Handle load stats.
|
// TODO(rjnagal): Handle load stats.
|
||||||
stats = append(stats, stat)
|
stats = append(stats, stat)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,8 @@ type ContainerSpec struct {
|
|||||||
|
|
||||||
// HasDiskIo when true, indicates that DiskIo stats will be available.
|
// HasDiskIo when true, indicates that DiskIo stats will be available.
|
||||||
HasDiskIo bool `json:"has_diskio"`
|
HasDiskIo bool `json:"has_diskio"`
|
||||||
|
|
||||||
|
HasCustomMetrics bool `json:"has_custom_metrics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container reference contains enough information to uniquely identify a container
|
// Container reference contains enough information to uniquely identify a container
|
||||||
@ -190,6 +192,9 @@ func (self *ContainerSpec) Eq(b *ContainerSpec) bool {
|
|||||||
if self.HasDiskIo != b.HasDiskIo {
|
if self.HasDiskIo != b.HasDiskIo {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if self.HasCustomMetrics != b.HasCustomMetrics {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,8 @@ type ContainerSpec struct {
|
|||||||
HasMemory bool `json:"has_memory"`
|
HasMemory bool `json:"has_memory"`
|
||||||
Memory MemorySpec `json:"memory,omitempty"`
|
Memory MemorySpec `json:"memory,omitempty"`
|
||||||
|
|
||||||
|
HasCustomMetrics bool `json:"has_custom_metrics"`
|
||||||
|
|
||||||
// Following resources have no associated spec, but are being isolated.
|
// Following resources have no associated spec, but are being isolated.
|
||||||
HasNetwork bool `json:"has_network"`
|
HasNetwork bool `json:"has_network"`
|
||||||
HasFilesystem bool `json:"has_filesystem"`
|
HasFilesystem bool `json:"has_filesystem"`
|
||||||
@ -100,6 +102,9 @@ type ContainerStats struct {
|
|||||||
// Task load statistics
|
// Task load statistics
|
||||||
HasLoad bool `json:"has_load"`
|
HasLoad bool `json:"has_load"`
|
||||||
Load v1.LoadStats `json:"load_stats,omitempty"`
|
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 {
|
type Percentiles struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user