This commit is contained in:
Fine 2025-01-09 17:33:01 +08:00
parent b2627de8c2
commit 4e47242053
3 changed files with 19 additions and 3 deletions

View File

@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { MetricsResults } from "@/types/dashboard";
export function useSnapshot(metrics: { name: string; results: any[] }[]) {
export function useSnapshot(metrics: { name: string; results: MetricsResults[] }[]) {
function processResults() {
const sources = metrics.map((metric: { name: string; results: any[] }) => {
const sources = metrics.map((metric: { name: string; results: MetricsResults[] }) => {
const values = metric.results.map(
(r: { values: { value: string }[]; metric: { labels: { key: string; value: string }[] } }) => {
const arr = r.values.map((v: { value: string }) => Number(v.value));

View File

@ -198,3 +198,17 @@ export type LegendOptions = {
toTheRight: boolean;
width: number;
};
export type MetricsResults = {
metric: { labels: MetricLabel[] };
values: MetricValue[];
};
type MetricLabel = {
key: string;
value: string;
};
type MetricValue = {
name: string;
value: string;
owner: null | string;
refId: null | string;
};

View File

@ -139,6 +139,7 @@ limitations under the License. -->
import { useSnapshot } from "@/hooks/useSnapshot";
import Snapshot from "./components/Snapshot.vue";
import Line from "@/views/dashboard/graphs/Line.vue";
import type { MetricsResults } from "@/types/dashboard";
const { t } = useI18n();
const alarmStore = useAlarmStore();
@ -164,7 +165,7 @@ limitations under the License. -->
showEventDetails.value = true;
}
function handleMetrics(snapshot: any) {
function handleMetrics(snapshot: { metrics: { name: string; results: MetricsResults[] }[] }) {
const { getMetricsMap } = useSnapshot(snapshot.metrics);
return getMetricsMap();