func (m *MetricStorage) getNodeMetrics(node string) *metrics.NodeMetrics { batch := m.metricSink.GetLatestDataBatch() if batch == nil { return nil } ms, found := batch.MetricSets[core.NodeKey(node)] if !found { return nil } usage, err := util.ParseResourceList(ms) if err != nil { return nil } return &metrics.NodeMetrics{ ObjectMeta: api.ObjectMeta{ Name: node, CreationTimestamp: unversioned.NewTime(time.Now()), }, Timestamp: unversioned.NewTime(batch.Timestamp), Window: unversioned.Duration{Duration: time.Minute}, Usage: usage, } }
func (m *MetricStorage) getPodMetrics(pod *api.Pod) *metrics.PodMetrics { batch := m.metricSink.GetLatestDataBatch() if batch == nil { return nil } res := &metrics.PodMetrics{ ObjectMeta: api.ObjectMeta{ Name: pod.Name, Namespace: pod.Namespace, CreationTimestamp: unversioned.NewTime(time.Now()), }, Timestamp: unversioned.NewTime(batch.Timestamp), Window: unversioned.Duration{Duration: time.Minute}, Containers: make([]metrics.ContainerMetrics, 0), } for _, c := range pod.Spec.Containers { ms, found := batch.MetricSets[core.PodContainerKey(pod.Namespace, pod.Name, c.Name)] if !found { glog.Infof("No metrics for container %s in pod %s/%s", c.Name, pod.Namespace, pod.Name) return nil } usage, err := util.ParseResourceList(ms) if err != nil { return nil } res.Containers = append(res.Containers, metrics.ContainerMetrics{Name: c.Name, Usage: usage}) } return res }