API changes for custom metrics
This commit is contained in:
parent
d580ecfc53
commit
b197771668
@ -39,6 +39,7 @@ const (
|
||||
attributesApi = "attributes"
|
||||
versionApi = "version"
|
||||
psApi = "ps"
|
||||
customMetricsApi = "appmetrics"
|
||||
)
|
||||
|
||||
// Interface for a cAdvisor API version
|
||||
@ -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 {
|
||||
@ -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)
|
||||
@ -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
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"`
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user