From 8f4d37803d2a2641e0feffd74013e6aaa8f68076 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Thu, 15 Jun 2023 11:15:32 +0800 Subject: [PATCH] add gui-json-mode package --- .../server/gui-json-mode/cpu_usage_rate.json | 67 +++++++++++++++++++ gala-ops/server/httphandler/agent.go | 2 +- gala-ops/server/httphandler/component.go | 1 - gala-ops/server/plugin/prometheus.go | 16 +++-- 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 gala-ops/server/gui-json-mode/cpu_usage_rate.json diff --git a/gala-ops/server/gui-json-mode/cpu_usage_rate.json b/gala-ops/server/gui-json-mode/cpu_usage_rate.json new file mode 100644 index 00000000..414808db --- /dev/null +++ b/gala-ops/server/gui-json-mode/cpu_usage_rate.json @@ -0,0 +1,67 @@ +{ + "id": 7, + "gridPos": { + "h": 5, + "w": 11, + "x": 0, + "y": 6 + }, + "type": "bargauge", + "title": "CPU使用率", + "datasource": { + "type": "prometheus", + "uid": "r3WqfVA4z" + }, + "pluginVersion": "9.3.14", + "fieldConfig": { + "defaults": { + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "color": { + "mode": "thresholds" + }, + "decimals": 2, + "unit": "percent" + }, + "overrides": [] + }, + "options": { + "reduceOptions": { + "values": false, + "calcs": [ + "lastNotNull" + ], + "fields": "" + }, + "orientation": "horizontal", + "displayMode": "lcd", + "showUnfilled": true, + "minVizWidth": 0, + "minVizHeight": 10 + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "r3WqfVA4z" + }, + "editorMode": "builder", + "expr": "avg by(job) (gala_gopher_cpu_total_used_per{job=~\"$instance\"})", + "legendFormat": "__auto", + "range": true, + "refId": "A" + } + ] + } \ No newline at end of file diff --git a/gala-ops/server/httphandler/agent.go b/gala-ops/server/httphandler/agent.go index 6c104674..8fb93c8c 100644 --- a/gala-ops/server/httphandler/agent.go +++ b/gala-ops/server/httphandler/agent.go @@ -61,7 +61,7 @@ func InstallGopher(ctx *gin.Context) { ret = append(ret, d) } - err = plugin.MonitorTargets(monitorTargets) + err = plugin.MonitorTargets(monitorTargets, Galaops.PromePlugin["url"].(string)) if err != nil { fmt.Println("error: failed to add gala-gopher to prometheus monitor targets") } diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/httphandler/component.go index 08c98c57..f48f3122 100644 --- a/gala-ops/server/httphandler/component.go +++ b/gala-ops/server/httphandler/component.go @@ -53,7 +53,6 @@ func (o *Opsclient) QueryMetric(endpoint string, querymethod string, param strin err = json.Unmarshal(bs, &data) if err != nil { - logger.Error("unmarshal cpu usage rate error:%s", err.Error()) return nil, fmt.Errorf("unmarshal cpu usage rate error:%s", err.Error()) } return data, nil diff --git a/gala-ops/server/plugin/prometheus.go b/gala-ops/server/plugin/prometheus.go index 6dc050fb..a6699f09 100644 --- a/gala-ops/server/plugin/prometheus.go +++ b/gala-ops/server/plugin/prometheus.go @@ -1,6 +1,8 @@ package plugin -import "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" +import ( + "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" +) // 请求prometheus插件接口,将gala-ops targets添加到监控清单当中 func addTargets(targets []string, url string) error { @@ -11,13 +13,13 @@ func addTargets(targets []string, url string) error { return nil } -func MonitorTargets(targets []string) error { - plugin, err := client.GetClient().GetPluginInfo("prometheus") - if err != nil { - return err - } +func MonitorTargets(targets []string, promeurl string) error { + // plugin, err := client.GetClient().GetPluginInfo("prometheus") + // if err != nil { + // return err + // } - if err := addTargets(targets, plugin.Url); err != nil { + if err := addTargets(targets, promeurl); err != nil { return err } -- Gitee