github.com/jonaz/heapster@v1.3.0-beta.0.0.20170208112634-cd3c15ca3d29/metrics/storage/util/util.go (about) 1 // Copyright 2016 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 util 16 17 import ( 18 "fmt" 19 20 "k8s.io/heapster/metrics/core" 21 "k8s.io/kubernetes/pkg/api" 22 "k8s.io/kubernetes/pkg/api/resource" 23 ) 24 25 func ParseResourceList(ms *core.MetricSet) (api.ResourceList, error) { 26 cpu, found := ms.MetricValues[core.MetricCpuUsageRate.MetricDescriptor.Name] 27 if !found { 28 return api.ResourceList{}, fmt.Errorf("cpu not found") 29 } 30 mem, found := ms.MetricValues[core.MetricMemoryWorkingSet.MetricDescriptor.Name] 31 if !found { 32 return api.ResourceList{}, fmt.Errorf("memory not found") 33 } 34 35 return api.ResourceList{ 36 api.ResourceCPU: *resource.NewMilliQuantity( 37 cpu.IntValue, 38 resource.DecimalSI), 39 api.ResourceMemory: *resource.NewQuantity( 40 mem.IntValue, 41 resource.BinarySI), 42 }, nil 43 }