@cloudcare/guance-front-tools 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,6 +106,22 @@ function sortPanelItemsByRowCol(panels) {
106
106
  return -1;
107
107
  });
108
108
  }
109
+ // 数字转成abc
110
+ function tenToTweenty(source = 1) {
111
+ let numArr = [];
112
+ source--;
113
+ do {
114
+ numArr.push(source % 26);
115
+ source = Math.floor(source / 26);
116
+ } while (source > 0);
117
+ return numArr
118
+ .reverse()
119
+ .map((item, index) => {
120
+ return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1));
121
+ })
122
+ .join('')
123
+ .toUpperCase();
124
+ }
109
125
  function getGridH(h, rowHeight, margin) {
110
126
  return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin);
111
127
  }
@@ -135,22 +151,27 @@ function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
135
151
  }
136
152
  const queries = [];
137
153
  if (targets && targets.length) {
154
+ let currentIndex = 0;
138
155
  targets.forEach((_target) => {
139
- if (!_target.expr)
156
+ const queryStr = _target.expr || _target.query;
157
+ if (!queryStr)
140
158
  return;
159
+ currentIndex++;
141
160
  const queryItem = {
142
161
  datasource: 'dataflux',
143
162
  qtype: 'promql',
144
163
  type: chartType,
145
164
  query: {
146
- q: replaceVariableStr(_target.expr),
165
+ q: replaceVariableStr(queryStr),
147
166
  type: 'promql',
167
+ code: tenToTweenty(currentIndex),
168
+ promqlCode: currentIndex,
148
169
  },
149
170
  };
150
171
  queries.push(queryItem);
151
172
  });
152
173
  }
153
- const settings = {};
174
+ let settings = {};
154
175
  if (options) {
155
176
  switch (chartType) {
156
177
  case 'text':
@@ -161,6 +182,12 @@ function covertPanelToGuanceChart(grafanaPanel, rowPanel) {
161
182
  };
162
183
  queries.push(queryItem);
163
184
  break;
185
+ case 'toplist':
186
+ settings = {
187
+ showTopSize: true,
188
+ chartType: 'bar',
189
+ };
190
+ break;
164
191
  default:
165
192
  break;
166
193
  }
@@ -110,6 +110,22 @@ function sortPanelItemsByRowCol(panels: Panel[]): Panel[] {
110
110
  return -1
111
111
  })
112
112
  }
113
+ // 数字转成abc
114
+ function tenToTweenty(source: number = 1): string {
115
+ let numArr: any = []
116
+ source--
117
+ do {
118
+ numArr.push(source % 26)
119
+ source = Math.floor(source / 26)
120
+ } while (source > 0)
121
+ return numArr
122
+ .reverse()
123
+ .map((item: number, index: number) => {
124
+ return String.fromCharCode(item + 97 + (index === numArr.length - 1 ? 0 : -1))
125
+ })
126
+ .join('')
127
+ .toUpperCase()
128
+ }
113
129
  function getGridH(h: number, rowHeight: number, margin: number) {
114
130
  return Math.round(h * rowHeight + Math.max(0, 2 * (h - 1)) * margin)
115
131
  }
@@ -140,21 +156,26 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
140
156
  }
141
157
  const queries: GuanceChartQueries = []
142
158
  if (targets && targets.length) {
159
+ let currentIndex = 0
143
160
  targets.forEach((_target) => {
144
- if (!_target.expr) return
161
+ const queryStr: string | unknown = _target.expr || _target.query
162
+ if (!queryStr) return
163
+ currentIndex++
145
164
  const queryItem: GuanceChartQueryItem = {
146
165
  datasource: 'dataflux',
147
166
  qtype: 'promql',
148
167
  type: chartType,
149
168
  query: {
150
- q: replaceVariableStr(_target.expr as string),
169
+ q: replaceVariableStr(queryStr as string),
151
170
  type: 'promql',
171
+ code: tenToTweenty(currentIndex),
172
+ promqlCode: currentIndex,
152
173
  },
153
174
  }
154
175
  queries.push(queryItem)
155
176
  })
156
177
  }
157
- const settings: GuanceChartSettings = {}
178
+ let settings: GuanceChartSettings = {}
158
179
  if (options) {
159
180
  switch (chartType) {
160
181
  case 'text':
@@ -165,6 +186,12 @@ function covertPanelToGuanceChart(grafanaPanel: Panel, rowPanel: RowPanel | unde
165
186
  }
166
187
  queries.push(queryItem)
167
188
  break
189
+ case 'toplist':
190
+ settings = {
191
+ showTopSize: true,
192
+ chartType: 'bar',
193
+ }
194
+ break
168
195
  default:
169
196
  break
170
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcare/guance-front-tools",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/test/pod.json ADDED
@@ -0,0 +1 @@
1
+ {"title":"项目容器状态","dashboardExtend":{"groupUnfoldStatus":{}},"main":{"vars":[{"type":"PROMQL_QUERY","datasource":"dataflux","name":"namespace","seq":0,"hide":0,"multiple":false,"includeStar":false,"valueSort":"desc","code":"namespace","definition":{"value":"label_values(kube_pod_info, namespace)","defaultVal":{"label":"kube-system","value":"kube-system"}}},{"type":"PROMQL_QUERY","datasource":"dataflux","name":"workload","seq":1,"hide":0,"multiple":false,"includeStar":false,"valueSort":"desc","code":"workload","definition":{"value":"label_values(kube_deployment_created{namespace=\"#{namespace}\"}, deployment)","defaultVal":{"label":"tiller-deploy","value":"tiller-deploy"}}}],"charts":[{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":0.5,"h":5.8,"w":3},"name":"CPU Limit","queries":[{"datasource":"dataflux","qtype":"promql","type":"singlestat","query":{"q":"max(kube_pod_container_resource_limits_cpu_cores{namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"})","type":"promql"}}],"type":"singlestat"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":3,"y":0.5,"h":5.8,"w":3},"name":"Memory Limit","queries":[{"datasource":"dataflux","qtype":"promql","type":"singlestat","query":{"q":"max(kube_pod_container_resource_limits_memory_bytes{namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"})","type":"promql"}}],"type":"singlestat"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":6,"y":0.5,"h":5.8,"w":3},"name":"最大实例数","queries":[{"datasource":"dataflux","qtype":"promql","type":"singlestat","query":{"q":"kube_deployment_spec_replicas{deployment=~\"#{workload}\"}","type":"promql"}}],"type":"singlestat"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":9,"y":0.5,"h":15.3,"w":5},"name":"整体CPU使用率","queries":[{"datasource":"dataflux","qtype":"promql","type":"gauge","query":{"q":"avg(\navg(irate(container_cpu_usage_seconds_total{container!~\"(POD|istio-proxy)\", namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m]) ) by (pod)\n/\navg( kube_pod_container_resource_limits_cpu_cores{namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"} ) by (pod)\n)","type":"promql"}}],"type":"gauge"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":14,"y":0.5,"h":15.3,"w":5},"name":"整体内存使用率","queries":[{"datasource":"dataflux","qtype":"promql","type":"gauge","query":{"q":"avg(\navg(container_memory_working_set_bytes{ container=\"#{workload}\",namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"} ) by (pod)\n/\nmax( kube_pod_container_resource_limits_memory_bytes{container=~\"#{workload}\"} ) by (pod)\n)","type":"promql"}}],"type":"gauge"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":19,"y":0.5,"h":15.3,"w":5},"name":"实例可用率","queries":[{"datasource":"dataflux","qtype":"promql","type":"gauge","query":{"q":"kube_deployment_status_replicas_available{deployment=~\"#{workload}\"} / kube_deployment_spec_replicas{deployment=~\"#{workload}\"} ","type":"promql"}}],"type":"gauge"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":5.8,"h":9.6,"w":9},"name":"可用副本数","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"kube_deployment_status_replicas_available{deployment=~\"${workload}\"}","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":15.3,"h":15.3,"w":12},"name":"CPU使用率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"avg(irate(container_cpu_usage_seconds_total{container!~\"(POD|istio-proxy)\", namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m]) ) by (pod)\n/\nmax( kube_pod_container_resource_limits_cpu_cores{namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"} ) by (pod)","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":15.3,"h":15.3,"w":12},"name":"内存使用率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"avg(container_memory_working_set_bytes{ container=\"#{workload}\", namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"} ) by (pod)\n/\nmax( kube_pod_container_resource_limits_memory_bytes{namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"} ) by (pod)","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":30.5,"h":15.3,"w":12},"name":"磁盘读取速率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"rate(container_fs_reads_bytes_total{namespace=~\"#{namespace}\", container=~\"#{workload}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m])","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":30.5,"h":15.3,"w":12},"name":"磁盘写入速率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"rate(container_fs_writes_bytes_total{namespace=~\"#{namespace}\", container=~\"#{workload}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m])","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":45.7,"h":17.2,"w":12},"name":"网络传输速率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"irate(container_network_transmit_bytes_total{namespace=~\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m])","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":45.7,"h":17.2,"w":12},"name":"网络接收速率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"irate(container_network_receive_bytes_total{namespace=~\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m])","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":62.8,"h":15.3,"w":12},"name":"文件打开数","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"process_files_open{namespace=~\"#{namespace}\", service=~\"#{workload}\"}","type":"promql"}},{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"process_files_open_files{namespace=~\"#{namespace}\", service=~\"#{workload}\"}","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":62.8,"h":15.3,"w":12},"name":"网络速率","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"sum(irate(container_network_receive_bytes_total{namespace=~\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m]))","type":"promql"}},{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"0- sum(irate(container_network_transmit_bytes_total{namespace=~\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m]))","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":78,"h":15.3,"w":12},"name":"业务状态码 isSuccess","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"product_appId_isSuccess:polaris_requests_business_code_total:increase1m{appId=~\"#{workload}\"}","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":78,"h":15.3,"w":12},"name":"业务状态码 respCode - busCode","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"sum(product_appId_isSuccess_respCode_busCode:polaris_requests_business_code_total:increase1m{appId=~\"#{workload}\"}) by (respCode, busCode)","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":93.2,"h":15.3,"w":12},"name":"访问量","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"sum(increase(nginx_ingress_controller_requests{namespace=\"#{namespace}\", service=\"#{workload}\",service!~\"ingress.+\"}[1m])) by (service) ","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":93.2,"h":15.3,"w":12},"name":"状态码","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"sum(increase(nginx_ingress_controller_requests{status=~\"(40[1-4]|40[5-9]|4[1-9][0-9]|5[0-9]+)\", namespace=\"#{namespace}\", service=\"#{workload}\"}[1m])) by (service, status) > 0","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":0,"y":108.4,"h":15.3,"w":12},"name":"cpu throttle (核心数)","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"irate(container_cpu_cfs_throttled_seconds_total{container=~\"#{workload}\", namespace=\"#{namespace}\", pod=~\"#{workload}-[0-9a-z]+-[0-9a-z]+\"}[5m])","type":"promql"}}],"type":"sequence"},{"extend":{"settings":{}},"group":{"name":null},"pos":{"x":12,"y":108.4,"h":15.3,"w":12},"name":"pod挂载状态","queries":[{"datasource":"dataflux","qtype":"promql","type":"sequence","query":{"q":"kube_pod_container_status_ready{container=\"#{workload}\"} == 1","type":"promql"}}],"type":"sequence"}],"groups":[]}}