Skip to content

Commit 2943344

Browse files
swordqiuQiu Jian
andauthored
feature: monitor bucket formance and resource status (#22552)
Co-authored-by: Qiu Jian <[email protected]>
1 parent cc92a5e commit 2943344

File tree

24 files changed

+1179
-532
lines changed

24 files changed

+1179
-532
lines changed

cmd/climc/shell/compute/buckets.go

Lines changed: 63 additions & 466 deletions
Large diffs are not rendered by default.

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ require (
9393
k8s.io/cri-api v0.22.17
9494
k8s.io/klog/v2 v2.20.0
9595
moul.io/http2curl/v2 v2.3.0
96-
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515074509-c7dba5d8b5e2
97-
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256
96+
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250519035927-2b74cec67090
97+
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0
9898
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1
9999
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
100100
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
101-
yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e
101+
yunion.io/x/pkg v1.10.4-0.20250519013345-54017bf6c1f0
102102
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1
103103
yunion.io/x/sqlchemy v1.1.3-0.20250513031856-ce9f71063b3a
104104
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,10 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
13761376
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
13771377
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
13781378
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
1379-
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515074509-c7dba5d8b5e2 h1:Zrqat1z8qiSqZXitZlUOs1uD4xN+pHXkrWir1vYBXr8=
1380-
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250515074509-c7dba5d8b5e2/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
1381-
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256 h1:kLKQ6zbgPDQflRwoHFAjxNChcbhXIFgsUVLkJwiXu/8=
1382-
yunion.io/x/executor v0.0.0-20241205080005-48f5b1212256/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
1379+
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250519035927-2b74cec67090 h1:E/I9CkZumtHaEBweSYc9bq5rFZ25i+s17bAZskXLGDc=
1380+
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20250519035927-2b74cec67090/go.mod h1:FXxAEbdNfWXX9gjME3K2nJhkydHY5EKEUZb+RLEzVwQ=
1381+
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0 h1:msG4SiDSVU7CrXH06WuHlNEZXIooTcmNbfrIGHuIHBU=
1382+
yunion.io/x/executor v0.0.0-20250518005516-5402e9e0bed0/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
13831383
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
13841384
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1 h1:/+THlvf/MvgCW+7KeCDCr33e81KSRa5JmdZ1IIyLOXQ=
13851385
yunion.io/x/jsonutils v1.0.1-0.20250507052344-1abcf4f443b1/go.mod h1:VK4Z93dgiKgAijcSqbMKmGaBMJuHulR16Hz4K015ZPo=
@@ -1391,8 +1391,8 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
13911391
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
13921392
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
13931393
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
1394-
yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e h1:OiBxJR18bq5fFK/IZWYRX+5HTMs2KgQJe0a3BZfdIVU=
1395-
yunion.io/x/pkg v1.10.4-0.20250513085810-efeaaca81a0e/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
1394+
yunion.io/x/pkg v1.10.4-0.20250519013345-54017bf6c1f0 h1:iKWkBMKazSijYNhOaSh4qBuIu+PmXYhEAMNwrxaXL4Q=
1395+
yunion.io/x/pkg v1.10.4-0.20250519013345-54017bf6c1f0/go.mod h1:0Bwxqd9MA3ACi119/l02FprY/o9gHahmYC2bsSbnVpM=
13961396
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1 h1:1KJ3YYinydPHpDEQRXdr/T8SYcKZ5Er+m489H+PnaQ4=
13971397
yunion.io/x/s3cli v0.0.0-20241221171442-1c11599d28e1/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
13981398
yunion.io/x/sqlchemy v1.1.3-0.20250513031856-ce9f71063b3a h1:mDW1VyYJxZ4ORITZGDWacUiBNyqX6rMObnQk77NvUOg=

pkg/apigateway/handler/init.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,5 @@
1515
package handler
1616

1717
import (
18-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/ansible"
19-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/cloudevent"
20-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/cloudid"
21-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/cloudnet"
22-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/cloudproxy"
23-
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
24-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/devtool"
25-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/etcd"
26-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/identity"
27-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/image"
28-
"yunion.io/x/onecloud/pkg/mcclient/modules/k8s"
29-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/logger"
30-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/monitor"
31-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/notify"
32-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/quota"
33-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/scheduledtask"
34-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/scheduler"
35-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/webconsole"
36-
_ "yunion.io/x/onecloud/pkg/mcclient/modules/yunionconf"
18+
_ "yunion.io/x/onecloud/pkg/mcclient/modules/loader"
3719
)
38-
39-
func init() {
40-
modules.InitUsages()
41-
modules.Usages.RegisterManager(modules.UsageManagerK8s, k8s.Usages)
42-
}

pkg/apis/compute/bucket.go

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package compute
1717
import (
1818
"net/http"
1919
"reflect"
20+
"time"
2021

2122
"yunion.io/x/cloudmux/pkg/apis/compute"
2223
"yunion.io/x/cloudmux/pkg/cloudprovider"
@@ -53,6 +54,8 @@ type BucketCreateInput struct {
5354
CloudproviderResourceInput
5455

5556
StorageClass string `json:"storage_class"`
57+
58+
EnablePerfMon *bool `json:"enable_perf_mon"`
5659
}
5760

5861
type BucketDetails struct {
@@ -66,28 +69,28 @@ type BucketDetails struct {
6669
AccessUrls []cloudprovider.SBucketAccessUrl `json:"access_urls"`
6770
}
6871

69-
func (self BucketDetails) GetMetricTags() map[string]string {
72+
func (bucket BucketDetails) GetMetricTags() map[string]string {
7073
ret := map[string]string{
71-
"id": self.Id,
72-
"brand": self.Brand,
73-
"cloudregion": self.Cloudregion,
74-
"cloudregion_id": self.CloudregionId,
75-
"domain_id": self.DomainId,
76-
"oss_id": self.Id,
77-
"oss_name": self.Name,
78-
"project_domain": self.ProjectDomain,
79-
"region_ext_id": self.RegionExtId,
80-
"status": self.Status,
81-
"tenant": self.Project,
82-
"tenant_id": self.ProjectId,
83-
"account": self.Account,
84-
"account_id": self.AccountId,
85-
"external_id": self.ExternalId,
74+
"id": bucket.Id,
75+
"brand": bucket.Brand,
76+
"cloudregion": bucket.Cloudregion,
77+
"cloudregion_id": bucket.CloudregionId,
78+
"domain_id": bucket.DomainId,
79+
"oss_id": bucket.Id,
80+
"oss_name": bucket.Name,
81+
"project_domain": bucket.ProjectDomain,
82+
"region_ext_id": bucket.RegionExtId,
83+
"status": bucket.Status,
84+
"tenant": bucket.Project,
85+
"tenant_id": bucket.ProjectId,
86+
"account": bucket.Account,
87+
"account_id": bucket.AccountId,
88+
"external_id": bucket.ExternalId,
8689
}
87-
return AppendMetricTags(ret, self.MetadataResourceInfo, self.ProjectizedResourceInfo)
90+
return AppendMetricTags(ret, bucket.MetadataResourceInfo, bucket.ProjectizedResourceInfo)
8891
}
8992

90-
func (self BucketDetails) GetMetricPairs() map[string]string {
93+
func (bucket BucketDetails) GetMetricPairs() map[string]string {
9194
ret := map[string]string{}
9295
return ret
9396
}
@@ -150,6 +153,8 @@ type BucketSyncstatusInput struct {
150153

151154
type BucketUpdateInput struct {
152155
apis.SharableVirtualResourceBaseUpdateInput
156+
157+
EnablePerfMon *bool `json:"enable_perf_mon"`
153158
}
154159

155160
type BucketPerformTempUrlInput struct {
@@ -370,3 +375,29 @@ func init() {
370375
return &SBackupStorageAccessInfo{}
371376
})
372377
}
378+
379+
type BucketProbeResult struct {
380+
UploadTime time.Duration
381+
DownloadTime time.Duration
382+
DeleteTime time.Duration
383+
}
384+
385+
func (result BucketProbeResult) UploadDelayMs() float64 {
386+
return float64(result.UploadTime) / float64(time.Millisecond)
387+
}
388+
389+
func (result BucketProbeResult) DownloadDelayMs() float64 {
390+
return float64(result.DownloadTime) / float64(time.Millisecond)
391+
}
392+
393+
func (result BucketProbeResult) DeleteDelayMs() float64 {
394+
return float64(result.DeleteTime) / float64(time.Millisecond)
395+
}
396+
397+
func (result BucketProbeResult) UploadThroughputMbps(sizeMBytes int) float64 {
398+
return float64(sizeMBytes) * 8 / float64(result.UploadTime.Seconds())
399+
}
400+
401+
func (result BucketProbeResult) DownloadThroughputMbps(sizeMBytes int) float64 {
402+
return float64(sizeMBytes) * 8 / float64(result.DownloadTime.Seconds())
403+
}

pkg/cloudmon/misc/bucketprobe.go

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// Copyright 2019 Yunion
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 misc
16+
17+
import (
18+
"context"
19+
"fmt"
20+
"time"
21+
22+
"yunion.io/x/jsonutils"
23+
"yunion.io/x/log"
24+
"yunion.io/x/pkg/errors"
25+
26+
computeapi "yunion.io/x/onecloud/pkg/apis/compute"
27+
"yunion.io/x/onecloud/pkg/cloudmon/options"
28+
"yunion.io/x/onecloud/pkg/mcclient"
29+
"yunion.io/x/onecloud/pkg/mcclient/auth"
30+
computemodules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
31+
baseoptions "yunion.io/x/onecloud/pkg/mcclient/options"
32+
"yunion.io/x/onecloud/pkg/util/influxdb"
33+
)
34+
35+
func BucketProbe(ctx context.Context, userCred mcclient.TokenCredential, isStart bool) {
36+
if options.Options.EnableBucketProbeDebug {
37+
log.Debugf("BucketProbe start")
38+
}
39+
if !options.Options.EnableBucketProbe {
40+
if options.Options.EnableBucketProbeDebug {
41+
log.Debugf("BucketProbe is disabled")
42+
}
43+
return
44+
}
45+
46+
sess := auth.GetSession(ctx, userCred, options.Options.Region)
47+
48+
metrics, err := gatherBucketMetrics(ctx, sess)
49+
if err != nil {
50+
log.Errorf("BucketProbe gatherBucketMetrics failed: %s", err)
51+
return
52+
}
53+
54+
err = sendMetrics(sess, metrics, "telegraf")
55+
if err != nil {
56+
log.Errorf("StatusProbe SendMetrics error: %s", err)
57+
}
58+
}
59+
60+
func gatherBucketMetrics(ctx context.Context, sess *mcclient.ClientSession) ([]influxdb.SMetricData, error) {
61+
allMetrics := []influxdb.SMetricData{}
62+
63+
params := baseoptions.BaseListOptions{}
64+
params.Scope = "max"
65+
limit := 1000
66+
params.Limit = &limit
67+
params.Filter = []string{
68+
"enable_perf_mon.equals(1)",
69+
}
70+
boolTrue := true
71+
params.Details = &boolTrue
72+
73+
total := -1
74+
offset := 0
75+
for total < 0 || offset < total {
76+
params.Offset = &offset
77+
results, err := computemodules.Buckets.List(sess, jsonutils.Marshal(params))
78+
if err != nil {
79+
return nil, errors.Wrap(err, "computemodules.Buckets.List")
80+
}
81+
total = results.Total
82+
offset = results.Offset + len(results.Data)
83+
84+
for _, bucket := range results.Data {
85+
bucketDetails := computeapi.BucketDetails{}
86+
err = bucket.Unmarshal(&bucketDetails)
87+
if err != nil {
88+
log.Errorf("BucketProbe failed: %s", err)
89+
continue
90+
}
91+
92+
metrics, err := probeBucketStats(ctx, sess, &bucketDetails)
93+
if err != nil {
94+
log.Errorf("BucketProbe failed: %s", err)
95+
continue
96+
}
97+
allMetrics = append(allMetrics, metrics...)
98+
}
99+
}
100+
101+
return allMetrics, nil
102+
}
103+
104+
func probeBucketStats(ctx context.Context, sess *mcclient.ClientSession, bucketDetails *computeapi.BucketDetails) ([]influxdb.SMetricData, error) {
105+
bucket, err := computemodules.GetIBucket(ctx, sess, bucketDetails)
106+
if err != nil {
107+
return nil, errors.Wrap(err, "getIBucket")
108+
}
109+
110+
resultDelay, err := computemodules.ProbeBucketStats(ctx, bucket, options.Options.BucketProbeTestKey, 0)
111+
if err != nil {
112+
return nil, errors.Wrap(err, "doProbeBucketStats zero")
113+
}
114+
115+
resultRate, err := computemodules.ProbeBucketStats(ctx, bucket, options.Options.BucketProbeTestKey, int64(options.Options.BucketProbeTestSizeMb)*1024*1024)
116+
if err != nil {
117+
return nil, errors.Wrap(err, "doProbeBucketStats with payload")
118+
}
119+
120+
metricTags := []influxdb.SKeyValue{}
121+
for k, v := range bucketDetails.GetMetricTags() {
122+
if len(v) == 0 {
123+
continue
124+
}
125+
metricTags = append(metricTags, influxdb.SKeyValue{
126+
Key: k,
127+
Value: v,
128+
})
129+
}
130+
131+
metrics := []influxdb.SKeyValue{}
132+
for k, v := range bucketDetails.GetMetricTags() {
133+
if len(v) == 0 {
134+
continue
135+
}
136+
metrics = append(metrics, influxdb.SKeyValue{
137+
Key: k,
138+
Value: v,
139+
})
140+
}
141+
142+
metrics = append(metrics,
143+
influxdb.SKeyValue{
144+
Key: "upload_delay_ms",
145+
Value: fmt.Sprintf("%f", resultDelay.UploadDelayMs()),
146+
},
147+
influxdb.SKeyValue{
148+
Key: "download_delay_ms",
149+
Value: fmt.Sprintf("%f", resultDelay.DownloadDelayMs()),
150+
},
151+
influxdb.SKeyValue{
152+
Key: "delete_delay_ms",
153+
Value: fmt.Sprintf("%f", resultDelay.DeleteDelayMs()),
154+
},
155+
influxdb.SKeyValue{
156+
Key: "upload_rate_mbps",
157+
Value: fmt.Sprintf("%f", resultRate.UploadThroughputMbps(options.Options.BucketProbeTestSizeMb)),
158+
},
159+
influxdb.SKeyValue{
160+
Key: "download_rate_mbps",
161+
Value: fmt.Sprintf("%f", resultRate.DownloadThroughputMbps(options.Options.BucketProbeTestSizeMb)),
162+
},
163+
)
164+
165+
if options.Options.EnableBucketProbeDebug {
166+
log.Debugf("BucketProbe for bucket %s metrics: %s", bucketDetails.Name, jsonutils.Marshal(metrics))
167+
}
168+
169+
return []influxdb.SMetricData{
170+
{
171+
Name: "bucket_perf",
172+
Tags: metricTags,
173+
Metrics: metrics,
174+
Timestamp: time.Now(),
175+
},
176+
}, nil
177+
}

pkg/cloudmon/misc/pinger.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ func getNetworkAddrMap(s *mcclient.ClientSession, netId string) (map[string]api.
110110
return nil, errors.Wrap(err, "GetSpecific addresses")
111111
}
112112
addrList := make([]api.SNetworkUsedAddress, 0)
113-
err = addrListJson.Unmarshal(&addrList, "addresses")
114-
if err != nil {
115-
return nil, errors.Wrap(err, "Unmarshal addreses")
113+
if addrListJson.Contains("addresses") {
114+
err = addrListJson.Unmarshal(&addrList, "addresses")
115+
if err != nil {
116+
return nil, errors.Wrap(err, "Unmarshal addreses")
117+
}
116118
}
117119
addrMap := make(map[string]api.SNetworkUsedAddress)
118120
for i := range addrList {

0 commit comments

Comments
 (0)