github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/metrics/processors/node_aggregator.go (about) 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 processors 16 17 import ( 18 "github.com/golang/glog" 19 "k8s.io/heapster/metrics/core" 20 ) 21 22 // Does not add any nodes. 23 type NodeAggregator struct { 24 MetricsToAggregate []string 25 } 26 27 func (this *NodeAggregator) Name() string { 28 return "node_aggregator" 29 } 30 31 func (this *NodeAggregator) Process(batch *core.DataBatch) (*core.DataBatch, error) { 32 for key, metricSet := range batch.MetricSets { 33 if metricSetType, found := metricSet.Labels[core.LabelMetricSetType.Key]; found && metricSetType == core.MetricSetTypePod { 34 // Aggregating pods 35 nodeName, found := metricSet.Labels[core.LabelNodename.Key] 36 if nodeName == "" { 37 glog.V(8).Infof("Skipping pod %s: no node info", key) 38 continue 39 } 40 if found { 41 nodeKey := core.NodeKey(nodeName) 42 node, found := batch.MetricSets[nodeKey] 43 if !found { 44 glog.Warningf("Failed to find node: %s", nodeKey) 45 } else if err := aggregate(metricSet, node, this.MetricsToAggregate); err != nil { 46 return nil, err 47 } 48 } else { 49 glog.Errorf("No node info in pod %s: %v", key, metricSet.Labels) 50 } 51 } 52 } 53 return batch, nil 54 }