github.com/kubewharf/katalyst-core@v0.5.3/pkg/metaserver/agent/metric/helper/device.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package helper 18 19 import ( 20 "github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/types" 21 "github.com/kubewharf/katalyst-core/pkg/metrics" 22 "github.com/kubewharf/katalyst-core/pkg/util/general" 23 metricutil "github.com/kubewharf/katalyst-core/pkg/util/metric" 24 ) 25 26 func GetDeviceMetricWithTime(metricsFetcher types.MetricsFetcher, emitter metrics.MetricEmitter, metricName string, devName string) (metricutil.MetricData, error) { 27 metricData, err := metricsFetcher.GetDeviceMetric(devName, metricName) 28 if err != nil { 29 general.Errorf(errMsgGetDeviceMetrics, metricName, devName, err) 30 return metricutil.MetricData{}, err 31 } 32 _ = emitter.StoreFloat64(metricsNameDeviceMetric, metricData.Value, metrics.MetricTypeNameRaw, 33 metrics.ConvertMapToTags(map[string]string{ 34 metricsTagKeyDeviceName: devName, 35 metricsTagKeyMetricName: metricName, 36 })...) 37 return metricData, nil 38 } 39 40 func GetDeviceMetric(metricsFetcher types.MetricsFetcher, emitter metrics.MetricEmitter, metricName string, devName string) (float64, error) { 41 metricWithTime, err := GetDeviceMetricWithTime(metricsFetcher, emitter, metricName, devName) 42 if err != nil { 43 return 0, err 44 } 45 return metricWithTime.Value, err 46 }