Skip to content

Commit 1cc7270

Browse files
authored
Merge pull request #53 from KunfengHe/br_release_sdk_v3
support for MRS & DAYU & LakeFormation
2 parents 0649b35 + c05d770 commit 1cc7270

File tree

365 files changed

+19999
-7448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

365 files changed

+19999
-7448
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Prometheus cloudeye exporter for [Huaweicloud](https://www.huaweicloud.com/).
44

5+
Note: The plug-in is applicable only to the Huaweicloud regions.
6+
57
[中文](./README_cn.md)
68

79
## Download
@@ -39,7 +41,7 @@ Usage of ./cloudeye-exporter:
3941
```
4042

4143
## Example of config file(clouds.yml)
42-
The "URL" value can be get from [Identity and Access Management (IAM) endpoint list](https://developer.huaweicloud.com/en-us/endpoint).
44+
The "URL" value can be get from [Identity and Access Management (IAM) endpoint list](https://developer.huaweicloud.com/endpoint?IAM).
4345
```
4446
global:
4547
prefix: "huaweicloud"
@@ -48,7 +50,7 @@ global:
4850
scrape_batch_size: 300
4951
5052
auth:
51-
auth_url: "https://iam.xxx.yyy.com/v3"
53+
auth_url: "https://iam.{region_id}.myhuaweicloud.com/v3"
5254
project_name: "{project_name}"
5355
access_key: "{access_key}"
5456
secret_key: "{secret_key}"

README_cn.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
[华为云](https://www.huaweicloud.com/)云监控的 Prometheus Exporter.
55

6+
注意:该插件仅适用于华为云局点。
67

78
## 介绍
89
Prometheus是用于展示大型测量数据的开源可视化工具,在工业监控、气象监控、家居自动化和过程管理等领域也有着较广泛的用户基础。将华为云Cloudeye服务接入 prometheus后,您可以利用 prometheus更好地监控和分析来自 Cloudeye服务的数据。
@@ -46,6 +47,9 @@ Prometheus是用于展示大型测量数据的开源可视化工具,在工业
4647
|VPC终端节点|SYS.VPCEP ||RMS|
4748
|图引擎服务GES|SYS.GES||RMS|
4849
|数据库安全服务DBSS|SYS.DBSS ||RMS|
50+
|MapReduce服务|SYS.MRS ||RMS/云服务|
51+
|湖仓构建服务|SYS.LakeFormation ||RMS/云服务|
52+
|智能数据湖运营平台|SYS.DAYU ||云服务|
4953

5054
注:自定义标签时,key只能包含大写字母、小写字母以及中划线
5155

@@ -64,20 +68,20 @@ Prometheus是用于展示大型测量数据的开源可视化工具,在工业
6468
# 参考命令:
6569
mkdir cloudeye-exporter
6670
cd cloudeye-exporter
67-
wget https://github.com/huaweicloud/cloudeye-exporter/releases/download/v2.0.4/cloudeye-exporter.v2.0.4.tar.gz
68-
tar -xzvf cloudeye-exporter.v2.0.4.tar.gz
71+
wget https://github.com/huaweicloud/cloudeye-exporter/releases/download/v2.0.5/cloudeye-exporter.v2.0.5.tar.gz
72+
tar -xzvf cloudeye-exporter.v2.0.5.tar.gz
6973
```
7074
2. 编辑clouds.yml文件配置公有云信息
7175
```
7276
global:
7377
port: ":8087"
7478
scrape_batch_size: 300
7579
auth:
76-
auth_url: "https://iam.cn-north-1.myhuaweicloud.com/v3"
77-
project_name: "cn-north-1"
78-
access_key: ""
79-
secret_key: ""
80-
region: "cn-north-1"
80+
auth_url: "https://iam.{region_id}.myhuaweicloud.com/v3"
81+
project_name: "cn-north-1"
82+
access_key: ""
83+
secret_key: ""
84+
region: "cn-north-1"
8185
```
8286
注:默认的监控端口为8087.
8387

collector/as.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"time"
55

66
cesmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
7-
8-
"github.com/huaweicloud/cloudeye-exporter/logs"
97
)
108

119
var asInfo serversInfo
@@ -42,17 +40,5 @@ func (getter ASInfo) GetResourceInfo() (map[string]labelInfo, []cesmodel.MetricI
4240
}
4341

4442
func getAllASFromRMS() ([]ResourceBaseInfo, error) {
45-
resp, err := listResources("as", "scalingGroups")
46-
if err != nil {
47-
logs.Logger.Errorf("Failed to list resource of as.scalingGroups, error: %s", err.Error())
48-
return nil, err
49-
}
50-
scalingGroups := make([]ResourceBaseInfo, len(resp))
51-
for index, resource := range resp {
52-
scalingGroups[index].ID = *resource.Id
53-
scalingGroups[index].Name = *resource.Name
54-
scalingGroups[index].EpId = *resource.EpId
55-
scalingGroups[index].Tags = resource.Tags
56-
}
57-
return scalingGroups, nil
43+
return getResourcesBaseInfoFromRMS("as", "scalingGroups")
5844
}

collector/cbr.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,7 @@ func (getter CBRInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricInf
5757
}
5858

5959
func getAllCbrInstancesFromRMS() ([]ResourceBaseInfo, error) {
60-
resp, err := listResources("cbr", "vault")
61-
if err != nil {
62-
logs.Logger.Errorf("Failed to list resource of cbr.vault, error: %s", err.Error())
63-
return nil, err
64-
}
65-
cbrInstances := make([]ResourceBaseInfo, 0, len(resp))
66-
for _, resource := range resp {
67-
cbrInstances = append(cbrInstances, ResourceBaseInfo{
68-
ID: *resource.Id,
69-
Name: *resource.Name,
70-
EpId: *resource.EpId,
71-
Tags: resource.Tags,
72-
})
73-
}
74-
return cbrInstances, nil
60+
return getResourcesBaseInfoFromRMS("cbr", "vault")
7561
}
7662

7763
func getAllCbrInstancesFromCBR() ([]ResourceBaseInfo, error) {

collector/dayu.go

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package collector
2+
3+
import (
4+
"errors"
5+
"net/http"
6+
"time"
7+
8+
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/def"
9+
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
10+
11+
"github.com/huaweicloud/cloudeye-exporter/logs"
12+
)
13+
14+
var dayuInfo serversInfo
15+
16+
type DayuInfo struct{}
17+
18+
func (getter DayuInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricInfoList) {
19+
resourceInfos := map[string]labelInfo{}
20+
filterMetrics := make([]model.MetricInfoList, 0)
21+
dayuInfo.Lock()
22+
defer dayuInfo.Unlock()
23+
if dayuInfo.LabelInfo == nil || time.Now().Unix() > dayuInfo.TTL {
24+
streams, err := getAllStreams()
25+
if err != nil {
26+
logs.Logger.Error("Get all dis Streams error:", err.Error())
27+
return dayuInfo.LabelInfo, dayuInfo.FilterMetrics
28+
}
29+
30+
sysConfigMap := getMetricConfigMap("SYS.DAYU")
31+
for _, stream := range streams {
32+
if metricNames, ok := sysConfigMap["stream_id"]; ok {
33+
metrics := buildSingleDimensionMetrics(metricNames, "SYS.DAYU", "stream_id", stream.ID)
34+
filterMetrics = append(filterMetrics, metrics...)
35+
info := labelInfo{
36+
Name: []string{"name", "epId"},
37+
Value: []string{stream.Name, stream.EpId},
38+
}
39+
keys, values := getTags(stream.Tags)
40+
info.Name = append(info.Name, keys...)
41+
info.Value = append(info.Value, values...)
42+
resourceInfos[GetResourceKeyFromMetricInfo(metrics[0])] = info
43+
}
44+
}
45+
46+
dayuInfo.LabelInfo = resourceInfos
47+
dayuInfo.FilterMetrics = filterMetrics
48+
dayuInfo.TTL = time.Now().Add(TTL).Unix()
49+
}
50+
return dayuInfo.LabelInfo, dayuInfo.FilterMetrics
51+
}
52+
53+
type StreamInfo struct {
54+
Private bool `json:"private"`
55+
StreamID string `json:"stream_id"`
56+
StreamName string `json:"stream_name"`
57+
CreateTime int64 `json:"create_time"`
58+
RetentionPeriod int `json:"retention_period"`
59+
Status string `json:"status"`
60+
StreamType string `json:"stream_type"`
61+
DataType string `json:"data_type"`
62+
PartitionCount int `json:"partition_count"`
63+
Tags []Tag `json:"tags"`
64+
SysTags []Tag `json:"sys_tags"`
65+
AutoScaleEnabled bool `json:"auto_scale_enabled"`
66+
AutoScaleMinPartitionCount int `json:"auto_scale_min_partition_count"`
67+
AutoScaleMaxPartitionCount int `json:"auto_scale_max_partition_count"`
68+
}
69+
70+
type ListStreamsResp struct {
71+
TotalNumber int `json:"total_number"`
72+
StreamNames []string `json:"stream_names"`
73+
StreamInfoList []StreamInfo `json:"stream_info_list"`
74+
HasMoreStreams bool `json:"has_more_streams"`
75+
HttpStatusCode int `json:"-"`
76+
}
77+
78+
type ListStreamsRep struct {
79+
Limit string `json:"limit"`
80+
StartStreamName string `json:"start_stream_name"`
81+
}
82+
83+
func genReqDefForListStreams() *def.HttpRequestDef {
84+
reqDefBuilder := def.NewHttpRequestDefBuilder().WithMethod(http.MethodGet).WithPath("/v2/{project_id}/streams").
85+
WithResponse(new(ListStreamsResp)).WithContentType("application/json")
86+
87+
reqDefBuilder.WithRequestField(def.NewFieldDef().WithName("Limit").WithJsonTag("limit").WithLocationType(def.Query))
88+
reqDefBuilder.WithRequestField(def.NewFieldDef().WithName("StartStreamName").WithJsonTag("start_stream_name").WithLocationType(def.Query))
89+
return reqDefBuilder.Build()
90+
}
91+
92+
func listStreams() ([]StreamInfo, error) {
93+
disClient := getHcClient(getEndpoint("dis", "v2"))
94+
request := &ListStreamsRep{Limit: "100"}
95+
var streams []StreamInfo
96+
for {
97+
resp, err := disClient.Sync(request, genReqDefForListStreams())
98+
if err != nil {
99+
logs.Logger.Errorf("Failed to get list streams : %s", err.Error())
100+
return nil, err
101+
}
102+
response, ok := resp.(*ListStreamsResp)
103+
if !ok {
104+
err := errors.New("resp type is not ServiceDetail")
105+
logs.Logger.Errorf("Failed to get list streams : %s", err.Error())
106+
return nil, err
107+
}
108+
streams = append(streams, response.StreamInfoList...)
109+
if !response.HasMoreStreams {
110+
break
111+
}
112+
request.StartStreamName = response.StreamNames[len(response.StreamNames)-1]
113+
}
114+
return streams, nil
115+
}
116+
117+
func getAllStreams() ([]ResourceBaseInfo, error) {
118+
streams, err := listStreams()
119+
if err != nil {
120+
logs.Logger.Errorf("Failed to get list streams : %s", err.Error())
121+
return nil, err
122+
}
123+
124+
resources := make([]ResourceBaseInfo, len(streams))
125+
for i, stream := range streams {
126+
resources[i].ID = stream.StreamID
127+
resources[i].Name = stream.StreamName
128+
resources[i].EpId = fmtTags(stream.SysTags)["_sys_enterprise_project_id"]
129+
resources[i].Tags = fmtTags(stream.Tags)
130+
}
131+
return resources, nil
132+
}

collector/dcaas.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,5 @@ func getDcaasVifFromRMS() ([]VifInfo, error) {
182182
}
183183

184184
func getDcaasVgwFromRMS() ([]ResourceBaseInfo, error) {
185-
resp, err := listResources("dcaas", "vgw")
186-
if err != nil {
187-
logs.Logger.Errorf("Failed to list resource of dcaas.vgw, error: %s", err.Error())
188-
return nil, err
189-
}
190-
vgws := make([]ResourceBaseInfo, len(resp))
191-
for index, resource := range resp {
192-
vgws[index].ID = *resource.Id
193-
vgws[index].Name = *resource.Name
194-
vgws[index].EpId = *resource.EpId
195-
vgws[index].Tags = resource.Tags
196-
}
197-
return vgws, nil
185+
return getResourcesBaseInfoFromRMS("dcaas", "vgw")
198186
}

collector/ddos.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,5 @@ func (getter DDOSInfo) GetResourceInfo() (map[string]labelInfo, []model.MetricIn
4646
}
4747

4848
func getAllDDosInstancesFromRMS() ([]ResourceBaseInfo, error) {
49-
resp, err := listResources("aad", "instances")
50-
if err != nil {
51-
logs.Logger.Errorf("Failed to list resource of aad.instances, error: %s", err.Error())
52-
return nil, err
53-
}
54-
instances := make([]ResourceBaseInfo, 0, len(resp))
55-
for _, resource := range resp {
56-
instances = append(instances, ResourceBaseInfo{
57-
ID: *resource.Id,
58-
Name: *resource.Name,
59-
EpId: *resource.EpId,
60-
Tags: resource.Tags,
61-
})
62-
}
63-
return instances, nil
49+
return getResourcesBaseInfoFromRMS("aad", "instances")
6450
}

collector/dli.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,7 @@ func buildFlinkJobsInfo(sysConfigMap map[string][]string, filterMetrics *[]model
8585
}
8686

8787
func getQueuesFromRMS() ([]ResourceBaseInfo, error) {
88-
resp, err := listResources("dli", "queues")
89-
if err != nil {
90-
return nil, err
91-
}
92-
instances := make([]ResourceBaseInfo, len(resp))
93-
for index, resource := range resp {
94-
instances[index].ID = *resource.Id
95-
instances[index].Name = *resource.Name
96-
instances[index].EpId = *resource.EpId
97-
instances[index].Tags = resource.Tags
98-
}
99-
return instances, nil
88+
return getResourcesBaseInfoFromRMS("dli", "queues")
10089
}
10190

10291
type ListFlinkJobsRequest struct {

collector/dms.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
77
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
88
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
9-
rmsmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rms/v1/model"
109
rocketmq "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rocketmq/v2"
1110
rocketmqmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rocketmq/v2/model"
1211

@@ -62,27 +61,20 @@ func getDMSResourceAndMetrics() (map[string]labelInfo, []model.MetricInfoList) {
6261
}
6362

6463
func getDMSInstanceFromRMS() []ResourceBaseInfo {
65-
var resources []rmsmodel.ResourceEntity
66-
kafkaResp, err := listResources("dms", "kafkas")
64+
instances := make([]ResourceBaseInfo, 0)
65+
66+
kafkaResp, err := getResourcesBaseInfoFromRMS("dms", "kafkas")
6767
if err != nil {
6868
logs.Logger.Errorf("Get all dms kafkas : %s", err.Error())
6969
} else {
70-
resources = append(resources, kafkaResp...)
70+
instances = append(instances, kafkaResp...)
7171
}
7272

73-
rabbitResp, err := listResources("dms", "rabbitmqs")
73+
rabbitResp, err := getResourcesBaseInfoFromRMS("dms", "rabbitmqs")
7474
if err != nil {
7575
logs.Logger.Errorf("Get all dms rabbitmqs: %s", err.Error())
7676
} else {
77-
resources = append(resources, rabbitResp...)
78-
}
79-
80-
instances := make([]ResourceBaseInfo, len(resources))
81-
for index, resource := range resources {
82-
instances[index].ID = *resource.Id
83-
instances[index].Name = *resource.Name
84-
instances[index].EpId = *resource.EpId
85-
instances[index].Tags = resource.Tags
77+
instances = append(instances, rabbitResp...)
8678
}
8779

8880
rocketMqs, err := getRocketMQInstances()

collector/extensions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ var (
4747
"SYS.GES": GESInfo{},
4848
"SYS.DBSS": DBSSInfo{},
4949
"SYS.CC": CCInfo{},
50+
"SYS.LakeFormation": LakeFormationInfo{},
51+
"SYS.MRS": MRSInfo{},
52+
"SYS.DAYU": DayuInfo{},
5053
}
5154
)
5255

0 commit comments

Comments
 (0)