diff --git a/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 User Guide 01.pdf b/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 User Guide 01.pdf index aa26f1e..a7a5cf1 100644 Binary files a/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 User Guide 01.pdf and b/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 User Guide 01.pdf differ diff --git "a/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 \347\224\250\346\210\267\346\214\207\345\215\227 01.pdf" "b/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 \347\224\250\346\210\267\346\214\207\345\215\227 01.pdf" index 961ecdd..b9cb52e 100644 Binary files "a/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 \347\224\250\346\210\267\346\214\207\345\215\227 01.pdf" and "b/docs/eSDK Huawei Storage Kubernetes CSM Plugins V2.1.0 \347\224\250\346\210\267\346\214\207\345\215\227 01.pdf" differ diff --git a/provider/collect/types.go b/provider/collect/types.go index d48fc1e..11aad1b 100644 --- a/provider/collect/types.go +++ b/provider/collect/types.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,5 +74,6 @@ type FileSystemObject struct { Name string `json:"NAME" metrics:"NAME"` Capacity string `json:"CAPACITY" metrics:"CAPACITY"` AllocCapacity string `json:"ALLOCCAPACITY" metrics:"ALLOCCAPACITY"` + AllocatedPoolQuota string `json:"allocatedPoolQuota" metrics:"allocatedPoolQuota"` AvailableAndAllocCapacityRatio string `json:"AVAILABLEANDALLOCCAPACITYRATIO" metrics:"AVAILABLEANDALLOCCAPACITYRATIO"` } diff --git a/server/prometheus-exporter/collector/collector_parse_func.go b/server/prometheus-exporter/collector/collector_parse_func.go index ae41990..6fce4c8 100644 --- a/server/prometheus-exporter/collector/collector_parse_func.go +++ b/server/prometheus-exporter/collector/collector_parse_func.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,9 @@ const ( runningStatusToPrometheus = "running_status" runningStatusFromStorage = "RUNNINGSTATUS" sectorsTOGb = 1024 * 1024 * 2 - capacityKey = "CAPACITY" - allocCapacityKey = "ALLOCCAPACITY" calculatePercentage = 100 bitSize = 64 + unlimitedPrecision = -1 precisionOfTwo = 2 precisionOfFour = 4 ) @@ -91,18 +90,3 @@ func parseLabelListToLabelValueSlice(labelKeys []string, } return labelValueSlice } - -func parseCapacityUsage(inDataKey, metricsName string, inData map[string]string) string { - if len(inData) == 0 { - return "" - } - capacity, err := strconv.ParseFloat(inData[capacityKey], bitSize) - if err != nil || capacity == 0 { - return "" - } - allocCapacity, err := strconv.ParseFloat(inData[allocCapacityKey], bitSize) - if err != nil { - return "" - } - return strconv.FormatFloat(allocCapacity/capacity*calculatePercentage, 'f', precisionOfTwo, bitSize) -} diff --git a/server/prometheus-exporter/collector/filesystem_collector.go b/server/prometheus-exporter/collector/filesystem_collector.go index 246e04a..1ded6a9 100644 --- a/server/prometheus-exporter/collector/filesystem_collector.go +++ b/server/prometheus-exporter/collector/filesystem_collector.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package collector import ( "fmt" + "strconv" "github.com/prometheus/client_golang/prometheus" @@ -29,6 +30,11 @@ func init() { RegisterCollector("filesystem", NewFilesystemCollector) } +const ( + filesystemCapacityKey = "CAPACITY" + filesystemUsedCapacityKey = "allocatedPoolQuota" +) + var filesystemBuildMap = map[string]collectorInitFunc{ "object": buildObjectFilesystemCollector, "performance": buildPerformanceFilesystemCollector, @@ -45,7 +51,7 @@ var filesystemObjectMetricsHelpMap = map[string]string{ var filesystemObjectMetricsParseMap = map[string]parseRelation{ "capacity": {"CAPACITY", parseStorageSectorsToGB}, - "capacity_usage": {"", parseCapacityUsage}, + "capacity_usage": {"", parseFilesystemCapacityUsage}, } var filesystemObjectLabelParseMap = map[string]parseRelation{ "endpoint": {"backendName", parseStorageData}, @@ -94,3 +100,18 @@ func NewFilesystemCollector(backendName string, monitorType string, metricsIndic } return buildFunc(backendName, monitorType, metricsIndicators, metricsDataCache) } + +func parseFilesystemCapacityUsage(inDataKey, metricsName string, inData map[string]string) string { + if len(inData) == 0 { + return "" + } + capacity, err := strconv.ParseFloat(inData[filesystemCapacityKey], bitSize) + if err != nil || capacity == 0 { + return "" + } + usedCapacity, err := strconv.ParseFloat(inData[filesystemUsedCapacityKey], bitSize) + if err != nil { + return "" + } + return strconv.FormatFloat(usedCapacity/capacity*calculatePercentage, 'f', unlimitedPrecision, bitSize) +} diff --git a/server/prometheus-exporter/collector/lun_collector.go b/server/prometheus-exporter/collector/lun_collector.go index 5f40756..26baa93 100644 --- a/server/prometheus-exporter/collector/lun_collector.go +++ b/server/prometheus-exporter/collector/lun_collector.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package collector import ( "fmt" + "strconv" "github.com/prometheus/client_golang/prometheus" @@ -29,6 +30,11 @@ func init() { RegisterCollector("lun", NewLunCollector) } +const ( + lunCapacityKey = "CAPACITY" + lunUsedCapacityKey = "ALLOCCAPACITY" +) + var lunBuildMap = map[string]collectorInitFunc{ "object": buildObjectLunCollector, "performance": buildPerformanceLunCollector, @@ -45,7 +51,7 @@ var lunObjectMetricsHelpMap = map[string]string{ var lunObjectMetricsParseMap = map[string]parseRelation{ "capacity": {"CAPACITY", parseStorageSectorsToGB}, - "capacity_usage": {"", parseCapacityUsage}, + "capacity_usage": {"", parseLunCapacityUsage}, } var lunObjectLabelParseMap = map[string]parseRelation{ "endpoint": {"backendName", parseStorageData}, @@ -94,3 +100,18 @@ func NewLunCollector(backendName, monitorType string, metricsIndicators []string } return buildFunc(backendName, monitorType, metricsIndicators, metricsDataCache) } + +func parseLunCapacityUsage(inDataKey, metricsName string, inData map[string]string) string { + if len(inData) == 0 { + return "" + } + capacity, err := strconv.ParseFloat(inData[lunCapacityKey], bitSize) + if err != nil || capacity == 0 { + return "" + } + allocCapacity, err := strconv.ParseFloat(inData[lunUsedCapacityKey], bitSize) + if err != nil { + return "" + } + return strconv.FormatFloat(allocCapacity/capacity*calculatePercentage, 'f', unlimitedPrecision, bitSize) +} diff --git a/server/prometheus-exporter/collector/lun_collector_test.go b/server/prometheus-exporter/collector/lun_collector_test.go index 984577e..4412fd9 100644 --- a/server/prometheus-exporter/collector/lun_collector_test.go +++ b/server/prometheus-exporter/collector/lun_collector_test.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,11 +31,12 @@ func Test_parseLunCapacityUsage(t *testing.T) { } // action - got := parseCapacityUsage("", "", mockInData) + got := parseLunCapacityUsage("", "", mockInData) + want := "50" // assert - if !reflect.DeepEqual(got, "50.00") { - t.Errorf("parseStorageStatus() got = %v, want %v", got, "50.00") + if !reflect.DeepEqual(got, want) { + t.Errorf("parseStorageStatus() got = %v, want %v", got, want) } } diff --git a/server/prometheus-exporter/collector/pv_collector.go b/server/prometheus-exporter/collector/pv_collector.go index e1809c8..401ea13 100644 --- a/server/prometheus-exporter/collector/pv_collector.go +++ b/server/prometheus-exporter/collector/pv_collector.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ var pvObjectMetricsHelpMap = map[string]string{ var pvObjectMetricsParseMap = map[string]parseRelation{ "capacity": {"CAPACITY", parseStorageSectorsToGB}, - "capacity_usage": {"", parseCapacityUsage}, + "capacity_usage": {"", parsePVCapacityUsage}, } var pvTypePrometheusMetrics = map[string][]string{ @@ -124,10 +124,10 @@ func parsePVCapacityUsage(inDataKey, metricsName string, inData map[string]strin } var pvCapacityUsage string if pvType == "oceanstor-san" { - pvCapacityUsage = parseCapacityUsage(inDataKey, metricsName, inData) + pvCapacityUsage = parseLunCapacityUsage(inDataKey, metricsName, inData) } if pvType == "oceanstor-nas" { - pvCapacityUsage = parseStorageData("AVAILABLEANDALLOCCAPACITYRATIO", metricsName, inData) + pvCapacityUsage = parseFilesystemCapacityUsage(inDataKey, metricsName, inData) } return pvCapacityUsage } diff --git a/server/prometheus-exporter/collector/pv_collector_test.go b/server/prometheus-exporter/collector/pv_collector_test.go index 6fc2b0e..ecc2b2d 100644 --- a/server/prometheus-exporter/collector/pv_collector_test.go +++ b/server/prometheus-exporter/collector/pv_collector_test.go @@ -69,9 +69,10 @@ func Test_parsePVCapacityUsageSan(t *testing.T) { // action got := parsePVCapacityUsage(mockInDataKey, mockMetricsName, mockInData) + want := "10" // assert - if !reflect.DeepEqual(got, "10.00") { - t.Errorf("parseStorageData() got = %v, want %v", got, "fake_data") + if !reflect.DeepEqual(got, want) { + t.Errorf("parseStorageData() got = %v, want %v", got, want) } } diff --git a/server/prometheus-exporter/collector/storage_pool_collector.go b/server/prometheus-exporter/collector/storage_pool_collector.go index 9c7915c..41b6e40 100644 --- a/server/prometheus-exporter/collector/storage_pool_collector.go +++ b/server/prometheus-exporter/collector/storage_pool_collector.go @@ -1,5 +1,5 @@ /* - * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,7 +83,7 @@ func parseStoragePoolCapacityUsage(inDataKey, metricsName string, inData map[str if err != nil { return "" } - return strconv.FormatFloat(usedCapacity/capacity*calculatePercentage, 'f', precisionOfTwo, bitSize) + return strconv.FormatFloat(usedCapacity/capacity*calculatePercentage, 'f', unlimitedPrecision, bitSize) } // Describe implements the prometheus.Collector interface.