Skip to content

Commit

Permalink
Merge pull request #4 from KunfengHe/master
Browse files Browse the repository at this point in the history
supported cdn service
  • Loading branch information
KunfengHe authored Apr 25, 2023
2 parents cf70d81 + 839c16b commit 2b21f37
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 77 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ go 1.16

require (
github.com/grafana/grafana-plugin-sdk-go v0.114.0
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.0.46
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.9
gopkg.in/yaml.v2 v2.4.0
)
5 changes: 4 additions & 1 deletion pkg/plugin/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ func (c *MetricCache) getRespElem(metric model.MetricInfoList) string {
}

func (c *MetricCache) buildQuery(param *QueryParam) *model.ListMetricsRequest {
dims := strings.Split(param.DimStr, ".")
dims := strings.Split(param.DimStr, ",")
reqParam := &model.ListMetricsRequest{
Namespace: &param.Namespace,
}
for i, dim := range dims {
dims[i]=strings.ReplaceAll(dim,":",",")
}
switch len(dims) {
case 3:
reqParam.Dim2 = &dims[2]
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func (c *CESClient) Check() error {
func getDimStr(dims []model.MetricsDimension) string {
var dimsList []string
for _, dim := range dims {
dimsList = append(dimsList, fmt.Sprintf("%s,%s", dim.Name, dim.Value))
dimsList = append(dimsList, fmt.Sprintf("%s:%s", dim.Name, dim.Value))
}
return strings.Join(dimsList, ".")
return strings.Join(dimsList, ",")
}

type QueryParam struct {
Expand Down
12 changes: 6 additions & 6 deletions pkg/plugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,31 @@ func LoadDimensions(region, namespace string) []string {
for k, v := range dims {
dimKeys := strings.Split(k, ",")
for i := range v {
dimValues := strings.Split(v[i], ",")
dimValues := strings.Split(v[i], ":")
if len(dimKeys) != len(dimValues) {
continue
}
dimStrs := make([]string, 0, len(dimKeys))
for j := range dimKeys {
dimStrs = append(dimStrs, fmt.Sprintf("%s,%s", dimKeys[j], dimValues[j]))
dimStrs = append(dimStrs, fmt.Sprintf("%s:%s", dimKeys[j], dimValues[j]))
}

res = append(res, strings.Join(dimStrs, "."))
res = append(res, strings.Join(dimStrs, ","))
}
}
return res
}

func LoadMetrics(namespace, dimStr string) []string {
dims := strings.Split(dimStr, ".")
dims := strings.Split(dimStr, ",")
dimKeys := make([]string, 0, len(dims))
for _, dim := range dims {
eachDim := strings.Split(dim, ",")
eachDim := strings.Split(dim, ":")
if len(eachDim) != 2 {
continue
}
dimKeys = append(dimKeys, eachDim[0])
}

return GetMeta().Metrics[fmt.Sprintf("%s|%s", namespace, strings.Join(dimKeys, ","))]
return GetMeta().Metrics[fmt.Sprintf("%s|%s", namespace, strings.Join(dimKeys, ":"))]
}
18 changes: 9 additions & 9 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptio
if (dimsName.indexOf("$" + item.name) >= 0) {
dimsName = dimsName.replace("$" + item.name, item.current.value)
}
dimsName = dimsName.replace(";",",");
});
return await this.listDims(region, namespace, dimsName, tagDimName);
}
Expand Down Expand Up @@ -220,15 +221,14 @@ export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptio
});
return result;
}
const newDimsName = dimsName.replace(':', ',')
const tagDimsName = this.getOrderedDimNames(newDimsName);
const preDim = this.parseDims(newDimsName)
const tagDimsName = this.getOrderedDimNames(dimsName);
const preDim = this.parseDims(dimsName)

dims.forEach((item: any) => {
const itemDimsName = this.getOrderedDimNames(item);
let valid = true;
preDim.forEach((dim: any) => {
if (item.indexOf(dim.name + "," + dim.value) === -1) {
if (item.indexOf(dim.name + ":" + dim.value) === -1) {
valid = false
}
})
Expand All @@ -251,15 +251,15 @@ export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptio
getOrderedDimNames(dimsStr: string | null): string {
if (dimsStr) {
const dimNames: Array<Object> = [];
const dims = dimsStr.split('.');
const dims = dimsStr.split(',');
dims.forEach((item: any) => {
const temp = item.split(',');
const temp = item.split(':');
if (temp.length === 0) {
return;
}
dimNames.push(temp[0])
});
return dimNames.sort().join('.');
return dimNames.sort().join(',');
}
return "";
}
Expand All @@ -286,9 +286,9 @@ export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptio
parseDims(dimStr: string): Array<any> {
if (dimStr) {
const dimsions: Array<Object> = [];
const dims = dimStr.split('.');
const dims = dimStr.split(',');
dims.forEach((item: any) => {
const temp = item.split(',');
const temp = item.split(':');
if (temp.length == 2) {
dimsions.push({name: temp[0], value: temp[1]})
}
Expand Down
38 changes: 19 additions & 19 deletions src/templates/dcs_redis_dashboard_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"targets": [
{
"dimstr": "dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "memory_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -186,7 +186,7 @@
},
"targets": [
{
"dimstr": "dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "bandwidth_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -271,7 +271,7 @@
},
"targets": [
{
"dimstr": "dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "instantaneous_ops",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -356,7 +356,7 @@
},
"targets": [
{
"dimstr": "dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "keys",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -441,7 +441,7 @@
},
"targets": [
{
"dimstr": "dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "rx_controlled",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -526,7 +526,7 @@
},
"targets": [
{
"dimstr": "dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "is_slow_log_exist",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -624,7 +624,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_redis_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_redis_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "memory_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -709,7 +709,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_redis_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_redis_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "cpu_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -794,7 +794,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_redis_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_redis_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "bandwidth_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -879,7 +879,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_redis_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_redis_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "instantaneous_ops",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -964,7 +964,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_redis_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_redis_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "keys",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -1049,7 +1049,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_redis_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_redis_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "is_slow_log_exist",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -1147,7 +1147,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_proxy2_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_proxy2_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "memory_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -1232,7 +1232,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_proxy2_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_proxy2_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "cpu_usage",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -1316,7 +1316,7 @@
},
"targets": [
{
"dimstr": "dcs_cluster_proxy2_node,00000000000000000000000000000000.dcs_instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "dcs_cluster_proxy2_node:00000000000000000000000000000000,dcs_instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "instantaneous_ops",
"namespace": "SYS.DCS",
Expand Down Expand Up @@ -1369,14 +1369,14 @@
},
{
"datasource": "${cloudeye-grafana}",
"definition": "listDims($region,SYS.DCS,dcs_cluster_redis_node.$dcs_instance_id,dcs_cluster_redis_node)",
"definition": "listDims($region,SYS.DCS,dcs_cluster_redis_node;$dcs_instance_id,dcs_cluster_redis_node)",
"hide": 0,
"includeAll": false,
"label": "数据节点",
"multi": false,
"name": "dcs_cluster_redis_node",
"options": [],
"query": "listDims($region,SYS.DCS,dcs_cluster_redis_node.$dcs_instance_id,dcs_cluster_redis_node)",
"query": "listDims($region,SYS.DCS,dcs_cluster_redis_node;$dcs_instance_id,dcs_cluster_redis_node)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
Expand All @@ -1391,14 +1391,14 @@
"value": ""
},
"datasource": "${cloudeye-grafana}",
"definition": "listDims($region,SYS.DCS,dcs_cluster_proxy2_node.$dcs_instance_id,dcs_cluster_proxy2_node)",
"definition": "listDims($region,SYS.DCS,dcs_cluster_proxy2_node;$dcs_instance_id,dcs_cluster_proxy2_node)",
"hide": 0,
"includeAll": false,
"label": "Proxy节点",
"multi": false,
"name": "dcs_cluster_proxy2_node",
"options": [],
"query": "listDims($region,SYS.DCS,dcs_cluster_proxy2_node.$dcs_instance_id,dcs_cluster_proxy2_node)",
"query": "listDims($region,SYS.DCS,dcs_cluster_proxy2_node;$dcs_instance_id,dcs_cluster_proxy2_node)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
Expand Down
12 changes: 6 additions & 6 deletions src/templates/ecs_dashboard_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
},
"targets": [
{
"dimstr": "instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "cpu_util",
"namespace": "SYS.ECS",
Expand Down Expand Up @@ -170,7 +170,7 @@
},
"targets": [
{
"dimstr": "instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "disk_read_requests_rate",
"namespace": "SYS.ECS",
Expand Down Expand Up @@ -254,7 +254,7 @@
},
"targets": [
{
"dimstr": "instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "disk_write_requests_rate",
"namespace": "SYS.ECS",
Expand Down Expand Up @@ -338,7 +338,7 @@
},
"targets": [
{
"dimstr": "instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "network_vm_pps_in",
"namespace": "SYS.ECS",
Expand Down Expand Up @@ -422,7 +422,7 @@
},
"targets": [
{
"dimstr": "instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "network_vm_pps_out",
"namespace": "SYS.ECS",
Expand Down Expand Up @@ -506,7 +506,7 @@
},
"targets": [
{
"dimstr": "instance_id,00000000-0000-0000-0000-000000000000",
"dimstr": "instance_id:00000000-0000-0000-0000-000000000000",
"filter": "average",
"metricName": "network_vm_connections",
"namespace": "SYS.ECS",
Expand Down
Loading

0 comments on commit 2b21f37

Please sign in to comment.