Skip to content

Commit

Permalink
update CSM v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
QiuzhuoYang committed Jan 13, 2025
1 parent bb5f0a1 commit 22c0cb7
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 35 deletions.
Binary file not shown.
Binary file not shown.
3 changes: 2 additions & 1 deletion provider/collect/types.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"`
}
20 changes: 2 additions & 18 deletions server/prometheus-exporter/collector/collector_parse_func.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
)
Expand Down Expand Up @@ -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)
}
25 changes: 23 additions & 2 deletions server/prometheus-exporter/collector/filesystem_collector.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,6 +19,7 @@ package collector

import (
"fmt"
"strconv"

"github.com/prometheus/client_golang/prometheus"

Expand All @@ -29,6 +30,11 @@ func init() {
RegisterCollector("filesystem", NewFilesystemCollector)
}

const (
filesystemCapacityKey = "CAPACITY"
filesystemUsedCapacityKey = "allocatedPoolQuota"
)

var filesystemBuildMap = map[string]collectorInitFunc{
"object": buildObjectFilesystemCollector,
"performance": buildPerformanceFilesystemCollector,
Expand All @@ -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},
Expand Down Expand Up @@ -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)
}
25 changes: 23 additions & 2 deletions server/prometheus-exporter/collector/lun_collector.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,6 +19,7 @@ package collector

import (
"fmt"
"strconv"

"github.com/prometheus/client_golang/prometheus"

Expand All @@ -29,6 +30,11 @@ func init() {
RegisterCollector("lun", NewLunCollector)
}

const (
lunCapacityKey = "CAPACITY"
lunUsedCapacityKey = "ALLOCCAPACITY"
)

var lunBuildMap = map[string]collectorInitFunc{
"object": buildObjectLunCollector,
"performance": buildPerformanceLunCollector,
Expand All @@ -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},
Expand Down Expand Up @@ -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)
}
9 changes: 5 additions & 4 deletions server/prometheus-exporter/collector/lun_collector_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions server/prometheus-exporter/collector/pv_collector.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions server/prometheus-exporter/collector/pv_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 22c0cb7

Please sign in to comment.