mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-02 18:15:22 +00:00
feat: add metrics on endpointlist
This commit is contained in:
parent
877c8ec91c
commit
bbb269a665
@ -19,7 +19,7 @@ import { ElMessage } from "element-plus";
|
|||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
import { useSelectorStore } from "@/store/modules/selectors";
|
import { useSelectorStore } from "@/store/modules/selectors";
|
||||||
import { useAppStoreWithOut } from "@/store/modules/app";
|
import { useAppStoreWithOut } from "@/store/modules/app";
|
||||||
import { Instance } from "@/types/selector";
|
import { Instance, Endpoint } from "@/types/selector";
|
||||||
|
|
||||||
export function useQueryProcessor(config: any) {
|
export function useQueryProcessor(config: any) {
|
||||||
if (!(config.metrics && config.metrics.length)) {
|
if (!(config.metrics && config.metrics.length)) {
|
||||||
@ -194,7 +194,7 @@ function aggregation(json: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useQueryPodsMetrics(
|
export function useQueryPodsMetrics(
|
||||||
pods: Instance[],
|
pods: Array<Instance | Endpoint>,
|
||||||
config: { metrics: string[]; metricTypes: string[] }
|
config: { metrics: string[]; metricTypes: string[] }
|
||||||
) {
|
) {
|
||||||
const appStore = useAppStoreWithOut();
|
const appStore = useAppStoreWithOut();
|
||||||
@ -205,7 +205,7 @@ export function useQueryPodsMetrics(
|
|||||||
const variables: string[] = [`$duration: Duration!`];
|
const variables: string[] = [`$duration: Duration!`];
|
||||||
const { currentService } = selectorStore;
|
const { currentService } = selectorStore;
|
||||||
|
|
||||||
const fragmentList = pods.map((d: Instance, index: number) => {
|
const fragmentList = pods.map((d: Instance | Endpoint, index: number) => {
|
||||||
const param = {
|
const param = {
|
||||||
scope: "ServiceInstance",
|
scope: "ServiceInstance",
|
||||||
serviceName: currentService.label,
|
serviceName: currentService.label,
|
||||||
@ -229,7 +229,7 @@ export function useQueryPodsMetrics(
|
|||||||
return { queryStr, conditions };
|
return { queryStr, conditions };
|
||||||
}
|
}
|
||||||
export function usePodsSource(
|
export function usePodsSource(
|
||||||
instances: Instance[],
|
pods: Array<Instance | Endpoint>,
|
||||||
resp: { errors: string; data: { [key: string]: any } },
|
resp: { errors: string; data: { [key: string]: any } },
|
||||||
config: { metrics: string[]; metricTypes: string[] }
|
config: { metrics: string[]; metricTypes: string[] }
|
||||||
): any {
|
): any {
|
||||||
@ -237,7 +237,7 @@ export function usePodsSource(
|
|||||||
ElMessage.error(resp.errors);
|
ElMessage.error(resp.errors);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const data = instances.map((d: Instance | any, idx: number) => {
|
const data = pods.map((d: Instance | any, idx: number) => {
|
||||||
config.metrics.map((name: string, index: number) => {
|
config.metrics.map((name: string, index: number) => {
|
||||||
const key = name + idx + index;
|
const key = name + idx + index;
|
||||||
|
|
||||||
|
6
src/types/selector.d.ts
vendored
6
src/types/selector.d.ts
vendored
@ -31,3 +31,9 @@ export type Instance = {
|
|||||||
instanceUUID: string;
|
instanceUUID: string;
|
||||||
attributes: { name: string; value: string }[];
|
attributes: { name: string; value: string }[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type Endpoint = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
@ -46,6 +46,21 @@ limitations under the License. -->
|
|||||||
</router-link>
|
</router-link>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column
|
||||||
|
v-for="(metric, index) in dashboardStore.selectedGrid.metrics"
|
||||||
|
:label="metric"
|
||||||
|
:key="metric + index"
|
||||||
|
>
|
||||||
|
<template #default="scope">
|
||||||
|
<div class="chart">
|
||||||
|
<Line
|
||||||
|
:data="{ metric: scope.row[metric] }"
|
||||||
|
:intervalTime="intervalTime"
|
||||||
|
:config="{ showXAxis: false, showYAxis: false }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
<el-pagination
|
<el-pagination
|
||||||
class="pagination"
|
class="pagination"
|
||||||
@ -60,11 +75,15 @@ limitations under the License. -->
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onBeforeMount, ref } from "vue";
|
import { ref, watch } from "vue";
|
||||||
import { useSelectorStore } from "@/store/modules/selectors";
|
import { useSelectorStore } from "@/store/modules/selectors";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import type { PropType } from "vue";
|
import type { PropType } from "vue";
|
||||||
import { EndpointListConfig } from "@/types/dashboard";
|
import { EndpointListConfig } from "@/types/dashboard";
|
||||||
|
import { Endpoint } from "@/types/selector";
|
||||||
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
|
import { useQueryPodsMetrics, usePodsSource } from "@/hooks/useProcessor";
|
||||||
|
import Line from "./Line.vue";
|
||||||
|
|
||||||
/*global defineProps */
|
/*global defineProps */
|
||||||
defineProps({
|
defineProps({
|
||||||
@ -75,15 +94,19 @@ defineProps({
|
|||||||
type: Object as PropType<EndpointListConfig>,
|
type: Object as PropType<EndpointListConfig>,
|
||||||
default: () => ({ dashboardName: "", fontSize: 12 }),
|
default: () => ({ dashboardName: "", fontSize: 12 }),
|
||||||
},
|
},
|
||||||
|
intervalTime: { type: Array as PropType<string[]>, default: () => [] },
|
||||||
});
|
});
|
||||||
const selectorStore = useSelectorStore();
|
const selectorStore = useSelectorStore();
|
||||||
|
const dashboardStore = useDashboardStore();
|
||||||
const chartLoading = ref<boolean>(false);
|
const chartLoading = ref<boolean>(false);
|
||||||
const endpoints = ref<{ layer: string; label: string }[]>([]);
|
const endpoints = ref<Endpoint[]>([]);
|
||||||
const searchEndpoints = ref<{ layer: string; label: string }[]>([]);
|
const currentEndpoints = ref<Endpoint[]>([]);
|
||||||
const pageSize = 7;
|
const pageSize = 7;
|
||||||
const searchText = ref<string>("");
|
const searchText = ref<string>("");
|
||||||
|
|
||||||
onBeforeMount(async () => {
|
queryEndpoints();
|
||||||
|
|
||||||
|
async function queryEndpoints() {
|
||||||
chartLoading.value = true;
|
chartLoading.value = true;
|
||||||
const resp = await selectorStore.getEndpoints();
|
const resp = await selectorStore.getEndpoints();
|
||||||
|
|
||||||
@ -93,16 +116,50 @@ onBeforeMount(async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
endpoints.value = selectorStore.endpoints.splice(0, pageSize);
|
endpoints.value = selectorStore.endpoints.splice(0, pageSize);
|
||||||
});
|
queryMetrics(endpoints.value);
|
||||||
|
}
|
||||||
|
async function queryMetrics(currentPods: Endpoint[]) {
|
||||||
|
const { metrics } = dashboardStore.selectedGrid;
|
||||||
|
|
||||||
|
if (metrics.length && metrics[0]) {
|
||||||
|
const params = await useQueryPodsMetrics(
|
||||||
|
currentPods,
|
||||||
|
dashboardStore.selectedGrid
|
||||||
|
);
|
||||||
|
const json = await dashboardStore.fetchMetricValue(params);
|
||||||
|
|
||||||
|
if (json.errors) {
|
||||||
|
ElMessage.error(json.errors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
endpoints.value = usePodsSource(
|
||||||
|
currentPods,
|
||||||
|
json,
|
||||||
|
dashboardStore.selectedGrid
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
endpoints.value = currentPods;
|
||||||
|
}
|
||||||
function changePage(pageIndex: number) {
|
function changePage(pageIndex: number) {
|
||||||
endpoints.value = selectorStore.endpoints.splice(pageIndex - 1, pageSize);
|
endpoints.value = selectorStore.endpoints.splice(pageIndex - 1, pageSize);
|
||||||
}
|
}
|
||||||
function searchList() {
|
function searchList() {
|
||||||
searchEndpoints.value = selectorStore.instances.filter(
|
currentEndpoints.value = selectorStore.instances.filter(
|
||||||
(d: { label: string }) => d.label.includes(searchText.value)
|
(d: { label: string }) => d.label.includes(searchText.value)
|
||||||
);
|
);
|
||||||
endpoints.value = searchEndpoints.value.splice(0, pageSize);
|
endpoints.value = currentEndpoints.value.splice(0, pageSize);
|
||||||
}
|
}
|
||||||
|
watch(
|
||||||
|
() => [
|
||||||
|
dashboardStore.selectedGrid.metricTypes,
|
||||||
|
dashboardStore.selectedGrid.metrics,
|
||||||
|
],
|
||||||
|
() => {
|
||||||
|
const currentPods = currentEndpoints.value.splice(0, pageSize);
|
||||||
|
queryMetrics(currentPods);
|
||||||
|
}
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import "./style.scss";
|
@import "./style.scss";
|
||||||
|
@ -167,6 +167,6 @@ watch(
|
|||||||
@import "./style.scss";
|
@import "./style.scss";
|
||||||
|
|
||||||
.chart {
|
.chart {
|
||||||
height: 50px;
|
height: 39px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user