show metric config

This commit is contained in:
Qiuxia Fan 2022-03-26 18:03:47 +08:00
parent eca4f35d0c
commit d4a900fe7f
3 changed files with 48 additions and 25 deletions

View File

@ -54,7 +54,7 @@ limitations under the License. -->
element-loading-background="rgba(0, 0, 0, 0)" element-loading-background="rgba(0, 0, 0, 0)"
@click="handleClick" @click="handleClick"
> >
<Sankey @click="selectNodeLink" /> <Sankey @click="selectNodeLink" :settings="settings" />
</div> </div>
<div <div
class="operations-list" class="operations-list"

View File

@ -17,11 +17,19 @@ limitations under the License. -->
<Graph :option="option" @select="clickChart" /> <Graph :option="option" @select="clickChart" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from "vue"; import { computed, PropType } from "vue";
import { useTopologyStore } from "@/store/modules/topology"; import { useTopologyStore } from "@/store/modules/topology";
import { Node, Call } from "@/types/topology"; import { Node, Call } from "@/types/topology";
import { MetricConfigOpt } from "@/types/dashboard";
import { aggregation } from "@/hooks/useProcessor";
/*global defineEmits */ /*global defineEmits, defineProps */
const props = defineProps({
settings: {
type: Object as PropType<any>,
default: () => ({}),
},
});
const emit = defineEmits(["click"]); const emit = defineEmits(["click"]);
const topologyStore = useTopologyStore(); const topologyStore = useTopologyStore();
const option = computed(() => getOption()); const option = computed(() => getOption());
@ -77,23 +85,34 @@ function getOption() {
function linkTooltip(data: Call) { function linkTooltip(data: Call) {
const clientMetrics: string[] = Object.keys(topologyStore.linkClientMetrics); const clientMetrics: string[] = Object.keys(topologyStore.linkClientMetrics);
const serverMetrics: string[] = Object.keys(topologyStore.linkServerMetrics); const serverMetrics: string[] = Object.keys(topologyStore.linkServerMetrics);
const htmlServer = serverMetrics.map((m) => { const linkServerMetricConfig: MetricConfigOpt[] =
const metric = topologyStore.linkServerMetrics[m].values.filter( props.settings.linkServerMetricConfig || [];
const linkClientMetricConfig: MetricConfigOpt[] =
props.settings.linkClientMetricConfig || [];
const htmlServer = serverMetrics.map((m, index) => {
const metric =
topologyStore.linkServerMetrics[m].values.find(
(val: { id: string; value: unknown }) => val.id === data.id (val: { id: string; value: unknown }) => val.id === data.id
)[0]; ) || {};
if (metric) { if (metric) {
const val = m.includes("_sla") ? metric.value / 100 : metric.value; const opt: MetricConfigOpt = linkServerMetricConfig[index] || {};
return ` <div><span>${m}: </span>${val}</div>`; const v = aggregation(metric.value, opt);
return ` <div class="mb-5"><span class="grey">${
opt.label || m
}: </span>${v} ${opt.unit || ""}</div>`;
} }
}); });
const htmlClient = clientMetrics.map((m) => { const htmlClient = clientMetrics.map((m, index) => {
const metric = topologyStore.linkClientMetrics[m].values.filter( const opt: MetricConfigOpt = linkClientMetricConfig[index] || {};
const metric =
topologyStore.linkClientMetrics[m].values.find(
(val: { id: string; value: unknown }) => val.id === data.id (val: { id: string; value: unknown }) => val.id === data.id
)[0]; ) || {};
if (metric) { const v = aggregation(metric.value, opt);
const val = m.includes("_sla") ? metric.value / 100 : metric.value; return ` <div class="mb-5"><span class="grey">${
return ` <div><span>${m}: </span>${val}</div>`; opt.label || m
} }: </span>${v} ${opt.unit || ""}</div>`;
}); });
const html = [ const html = [
`<div>${data.sourceObj.serviceName} -> ${data.targetObj.serviceName}</div>`, `<div>${data.sourceObj.serviceName} -> ${data.targetObj.serviceName}</div>`,
@ -106,13 +125,17 @@ function linkTooltip(data: Call) {
function nodeTooltip(data: Node) { function nodeTooltip(data: Node) {
const nodeMetrics: string[] = Object.keys(topologyStore.nodeMetricValue); const nodeMetrics: string[] = Object.keys(topologyStore.nodeMetricValue);
const html = nodeMetrics.map((m) => { const nodeMetricConfig = props.settings.nodeMetricConfig || [];
const html = nodeMetrics.map((m, index) => {
const metric = const metric =
topologyStore.nodeMetricValue[m].values.filter( topologyStore.nodeMetricValue[m].values.find(
(val: { id: string; value: unknown }) => val.id === data.id (val: { id: string; value: unknown }) => val.id === data.id
)[0] || {}; ) || {};
const val = m.includes("_sla") ? metric.value / 100 : metric.value; const opt: MetricConfigOpt = nodeMetricConfig[index] || {};
return ` <div><span>${m}: </span>${val}</div>`; const v = aggregation(metric.value, opt);
return ` <div class="mb-5"><span class="grey">${
opt.label || m
}: </span>${v} ${opt.unit || ""}</div>`;
}); });
return [` <div><span>name: </span>${data.serviceName}</div>`, ...html].join( return [` <div><span>name: </span>${data.serviceName}</div>`, ...html].join(
" " " "

View File

@ -36,7 +36,7 @@ limitations under the License. -->
> >
<template #reference> <template #reference>
<span @click="setConfigType('linkServerMetricConfig')"> <span @click="setConfigType('linkServerMetricConfig')">
<Icon class="cp mr-5" iconName="mode_edit" size="middle" /> <Icon class="cp ml-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<Metrics <Metrics
@ -67,7 +67,7 @@ limitations under the License. -->
> >
<template #reference> <template #reference>
<span @click="setConfigType('linkClientMetricConfig')"> <span @click="setConfigType('linkClientMetricConfig')">
<Icon class="cp mr-5" iconName="mode_edit" size="middle" /> <Icon class="cp ml-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<Metrics <Metrics
@ -149,7 +149,7 @@ limitations under the License. -->
> >
<template #reference> <template #reference>
<span @click="setConfigType('nodeMetricConfig')"> <span @click="setConfigType('nodeMetricConfig')">
<Icon class="cp mr-5" iconName="mode_edit" size="middle" /> <Icon class="cp ml-5" iconName="mode_edit" size="middle" />
</span> </span>
</template> </template>
<Metrics <Metrics