github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/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 continue 35 } 36 // Aggregating pods 37 nodeName, found := metricSet.Labels[core.LabelNodename.Key] 38 if nodeName == "" { 39 glog.V(8).Infof("Skipping pod %s: no node info", key) 40 continue 41 } 42 if !found { 43 glog.Errorf("No node info in pod %s: %v", key, metricSet.Labels) 44 continue 45 } 46 nodeKey := core.NodeKey(nodeName) 47 node, found := batch.MetricSets[nodeKey] 48 if !found { 49 glog.V(1).Infof("No metric for node %s, cannot perform node level aggregation.", nodeKey) 50 } else if err := aggregate(metricSet, node, this.MetricsToAggregate); err != nil { 51 return nil, err 52 } 53 54 } 55 return batch, nil 56 }