Change metering exported format to csv.
Signed-off-by: Rao Yunkun <yunkunrao@yunify.com>
This commit is contained in:
@@ -9,6 +9,16 @@ type PriceInfo struct {
|
||||
PvcPerGigabytesPerHour float64 `json:"pvc_per_gigabytes_per_hour,omitempty" description:"pvc price"`
|
||||
}
|
||||
|
||||
// currently init method fill illegal value to hint that metering config file was not mounted yet
|
||||
func (p *PriceInfo) Init() {
|
||||
p.Currency = ""
|
||||
p.CpuPerCorePerHour = -1
|
||||
p.MemPerGigabytesPerHour = -1
|
||||
p.IngressNetworkTrafficPerGiagabytesPerHour = -1
|
||||
p.EgressNetworkTrafficPerGiagabytesPerHour = -1
|
||||
p.PvcPerGigabytesPerHour = -1
|
||||
}
|
||||
|
||||
type PodStatistic struct {
|
||||
CPUUsage float64 `json:"cpu_usage" description:"cpu_usage"`
|
||||
MemoryUsageWoCache float64 `json:"memory_usage_wo_cache" description:"memory_usage_wo_cache"`
|
||||
|
||||
@@ -19,6 +19,14 @@ const (
|
||||
meteringConfig = "/etc/kubesphere/metering/ks-metering.yaml"
|
||||
)
|
||||
|
||||
var meterResourceUnitMap = map[int]string{
|
||||
METER_RESOURCE_TYPE_CPU: "cores",
|
||||
METER_RESOURCE_TYPE_MEM: "bytes",
|
||||
METER_RESOURCE_TYPE_NET_INGRESS: "bytes",
|
||||
METER_RESOURCE_TYPE_NET_EGRESS: "bytes",
|
||||
METER_RESOURCE_TYPE_PVC: "bytes",
|
||||
}
|
||||
|
||||
var MeterResourceMap = map[string]int{
|
||||
"meter_cluster_cpu_usage": METER_RESOURCE_TYPE_CPU,
|
||||
"meter_cluster_memory_usage": METER_RESOURCE_TYPE_MEM,
|
||||
@@ -67,6 +75,7 @@ type PriceInfo struct {
|
||||
IngressNetworkTrafficPerGiagabytesPerHour float64 `json:"ingressNetworkTrafficPerGiagabytesPerHour" yaml:"ingressNetworkTrafficPerGiagabytesPerHour"`
|
||||
EgressNetworkTrafficPerGigabytesPerHour float64 `json:"egressNetworkTrafficPerGigabytesPerHour" yaml:"egressNetworkTrafficPerGigabytesPerHour"`
|
||||
PvcPerGigabytesPerHour float64 `json:"pvcPerGigabytesPerHour" yaml:"pvcPerGigabytesPerHour"`
|
||||
CurrencyUnit string `json:"currencyUnit" yaml:"currencyUnit"`
|
||||
}
|
||||
|
||||
type Billing struct {
|
||||
@@ -143,6 +152,25 @@ func getAvgPointValue(points []monitoring.Point) float64 {
|
||||
return getSumPointValue(points) / float64(len(points))
|
||||
}
|
||||
|
||||
func getCurrencyUnit() string {
|
||||
meterConfig, err := LoadYaml()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return meterConfig.GetPriceInfo().CurrencyUnit
|
||||
}
|
||||
|
||||
func getResourceUnit(meterName string) string {
|
||||
if resourceType, ok := MeterResourceMap[meterName]; !ok {
|
||||
klog.Errorf("invlaid meter %v", meterName)
|
||||
return ""
|
||||
} else {
|
||||
return meterResourceUnitMap[resourceType]
|
||||
}
|
||||
}
|
||||
|
||||
func getFeeWithMeterName(meterName string, sum float64) float64 {
|
||||
|
||||
meterConfig, err := LoadYaml()
|
||||
@@ -216,6 +244,8 @@ func updateMetricStatData(metric monitoring.Metric, scalingMap map[string]float6
|
||||
metricData.MetricValues[index].SumValue = sum
|
||||
metricData.MetricValues[index].Fee = getFeeWithMeterName(metricName, sum)
|
||||
}
|
||||
metricData.MetricValues[index].CurrencyUnit = getCurrencyUnit()
|
||||
metricData.MetricValues[index].ResourceUnit = getResourceUnit(metricName)
|
||||
|
||||
}
|
||||
return metricData
|
||||
|
||||
Reference in New Issue
Block a user