Files
----/后端源码/yifan.action-ai.cn/index/js/index.DWKHrtNR.js

860 lines
40 KiB
JavaScript

import { a6 as ElTabPane, U as ElRow, V as ElCol, T as ElCard, a3 as ElDescriptions, a4 as ElDescriptionsItem, i as ElIcon, l as ElTooltip, al as ElTable, am as ElTableColumn, h as ElButton, aR as ElPopconfirm, u as ElEmpty, w as ElForm, x as ElFormItem, y as ElInput, a5 as ElTabs, D as ElMessageBox } from "./element-plus.CkEW9frc.js";
import { l as httpRequest } from "./index.CMd5bD1r.js";
import { i as init } from "./echarts.Cg_Ec8L-.js";
import { J as defineComponent, t as onMounted, ah as onUnmounted, aO as resolveComponent, aP as resolveDirective, S as openBlock, _ as createElementBlock, $ as createVNode, a0 as withCtx, a9 as createTextVNode, aa as toDisplayString, o as unref, a1 as createBaseVNode, a6 as withDirectives, T as createBlock, r as ref } from "./.pnpm.BW3P1y8f.js";
import { _ as _export_sfc } from "./_plugin-vue_export-helper.1tPrXgE0.js";
import "./codemirror.CvJAcn2d.js";
const API_PATH = "/monitor/cache";
const CacheAPI = {
getCacheInfo() {
return httpRequest({
url: `${API_PATH}/info`,
method: "get"
});
},
getCacheNames() {
return httpRequest({
url: `${API_PATH}/get/names`,
method: "get"
});
},
getCacheKeys(cacheName) {
return httpRequest({
url: `${API_PATH}/get/keys/${cacheName}`,
method: "get"
});
},
getCacheValue(cacheName, cacheKey) {
return httpRequest({
url: `${API_PATH}/get/value/${cacheName}/${cacheKey}`,
method: "get"
});
},
deleteCacheName(cacheName) {
return httpRequest({
url: `${API_PATH}/delete/name/${cacheName}`,
method: "delete"
});
},
deleteCacheKey(cacheKey) {
return httpRequest({
url: `${API_PATH}/delete/key/${cacheKey}`,
method: "delete"
});
},
deleteCacheAll() {
return httpRequest({
url: `${API_PATH}/delete/all`,
method: "delete"
});
}
};
const _hoisted_1 = { class: "app-container" };
const _hoisted_2 = { class: "flex items-center gap-2" };
const _hoisted_3 = { class: "flex items-center gap-2" };
const _hoisted_4 = { class: "flex items-center gap-2" };
const _hoisted_5 = { class: "flex justify-between items-center" };
const _hoisted_6 = { class: "flex items-center gap-2" };
const _hoisted_7 = { class: "flex justify-between items-center" };
const _hoisted_8 = { class: "flex items-center gap-2" };
const _hoisted_9 = { class: "flex justify-between items-center" };
const _hoisted_10 = { class: "flex items-center gap-2" };
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "index",
setup(__props) {
const cacheNames = ref([]);
const cacheKeys = ref([]);
const loading = ref(true);
const subLoading = ref(false);
const nowCacheName = ref("");
const commandstats = ref(null);
const usedmemory = ref(null);
const cache = ref({
info: {},
command_stats: [],
db_size: 0
});
const cacheForm = ref({
cache_name: "",
cache_key: "",
cache_value: ""
});
let commandstatsInstance = null;
let usedmemoryInstance = null;
const resetCacheForm = () => {
cacheKeys.value = [];
cacheForm.value = {
cache_name: "",
cache_key: "",
cache_value: ""
};
};
const getCacheNameList = async () => {
try {
loading.value = true;
const response = await CacheAPI.getCacheNames();
cacheNames.value = response.data.data;
resetCacheForm();
} catch (error) {
console.error("获取缓存列表出错:", error);
} finally {
loading.value = false;
}
};
const refreshCacheNames = () => {
getCacheNameList();
};
const handleClearCacheName = async (row) => {
try {
await CacheAPI.deleteCacheName(row.cache_name);
refreshCacheNames();
} catch (error) {
console.error("清理缓存名称出错:", error);
}
};
const getCacheKeyList = async (row) => {
try {
const cacheName = (row == null ? void 0 : row.cache_name) || nowCacheName.value;
if (!cacheName) return;
subLoading.value = true;
const response = await CacheAPI.getCacheKeys(cacheName);
cacheKeys.value = response.data.data;
nowCacheName.value = cacheName;
cacheForm.value = {
cache_name: cacheName,
cache_key: "",
cache_value: ""
};
} catch (error) {
console.error("获取缓存键名列表出错:", error);
} finally {
subLoading.value = false;
}
};
const refreshCacheKeys = () => {
getCacheKeyList();
};
async function handleClearCacheKey(cacheKey) {
try {
await CacheAPI.deleteCacheKey(cacheKey);
getCacheKeyList();
} catch (error) {
console.error("清理缓存键名出错:", error);
}
}
async function handleCacheValue(cacheKey) {
try {
loading.value = true;
const response = await CacheAPI.getCacheValue(nowCacheName.value, cacheKey);
cacheForm.value = response.data.data;
} catch (error) {
console.error("获取缓存内容失败:", error);
} finally {
loading.value = false;
}
}
const handleClearCacheAll = async () => {
ElMessageBox.confirm("确定要清理全部缓存吗?", "危险!", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
return await CacheAPI.deleteCacheAll();
}).then(() => {
getCacheNameList();
}).catch((error) => {
if (error !== "cancel") {
console.error("清理全部缓存失败:", error);
}
});
};
const getInfo = async () => {
try {
loading.value = true;
const response = await CacheAPI.getCacheInfo();
cache.value = response.data.data || {
info: {},
command_stats: [],
dbSize: 0
};
initCharts();
} catch (error) {
console.error("获取缓存监控数据失败:", error);
} finally {
loading.value = false;
}
};
const initCharts = () => {
var _a;
if (!commandstats.value || !usedmemory.value) return;
commandstatsInstance = init(commandstats.value, "macarons");
usedmemoryInstance = init(usedmemory.value, "macarons");
const commandStatsOption = {
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)"
},
series: [
{
name: "命令",
type: "pie",
roseType: "radius",
radius: [15, 95],
center: ["50%", "38%"],
data: cache.value.command_stats || [],
animationEasing: "cubicInOut",
animationDuration: 1e3
}
]
};
const usedMemory = ((_a = cache.value.info) == null ? void 0 : _a.used_memory_human) || "0";
const usedMemoryOption = {
tooltip: {
formatter: `{b} <br/>{a} : ${usedMemory}`
},
series: [
{
name: "峰值",
type: "gauge",
min: 0,
max: 1e3,
detail: {
formatter: usedMemory
},
data: [
{
value: parseFloat(usedMemory) || 0,
name: "内存消耗"
}
]
}
]
};
commandstatsInstance.setOption(commandStatsOption);
usedmemoryInstance.setOption(usedMemoryOption);
};
onMounted(() => {
getCacheNameList();
getInfo();
});
onUnmounted(() => {
commandstatsInstance == null ? void 0 : commandstatsInstance.dispose();
usedmemoryInstance == null ? void 0 : usedmemoryInstance.dispose();
});
return (_ctx, _cache) => {
const _component_Monitor = resolveComponent("Monitor");
const _component_el_icon = ElIcon;
const _component_QuestionFilled = resolveComponent("QuestionFilled");
const _component_el_tooltip = ElTooltip;
const _component_el_descriptions_item = ElDescriptionsItem;
const _component_el_descriptions = ElDescriptions;
const _component_el_card = ElCard;
const _component_el_col = ElCol;
const _component_Stopwatch = resolveComponent("Stopwatch");
const _component_el_row = ElRow;
const _component_el_tab_pane = ElTabPane;
const _component_Tickets = resolveComponent("Tickets");
const _component_el_button = ElButton;
const _component_el_empty = ElEmpty;
const _component_el_table_column = ElTableColumn;
const _component_el_popconfirm = ElPopconfirm;
const _component_el_table = ElTable;
const _component_Key = resolveComponent("Key");
const _component_el_input = ElInput;
const _component_el_form_item = ElFormItem;
const _component_el_form = ElForm;
const _component_el_tabs = ElTabs;
const _directive_hasPerm = resolveDirective("hasPerm");
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(_component_el_tabs, { type: "border-card" }, {
default: withCtx(() => [
createVNode(_component_el_tab_pane, {
class: "monitor",
label: "监控信息"
}, {
default: withCtx(() => [
createVNode(_component_el_row, { gutter: 16 }, {
default: withCtx(() => [
createVNode(_component_el_col, { span: 24 }, {
default: withCtx(() => [
createVNode(_component_el_card, { shadow: "hover" }, {
header: withCtx(() => [
createBaseVNode("div", _hoisted_2, [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_Monitor)
]),
_: 1
}),
_cache[3] || (_cache[3] = createBaseVNode("span", null, "Redis监控信息", -1)),
createVNode(_component_el_tooltip, { content: "展示Redis监控信息详情" }, {
default: withCtx(() => [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_QuestionFilled)
]),
_: 1
})
]),
_: 1
})
])
]),
default: withCtx(() => [
createVNode(_component_el_descriptions, {
column: 12,
border: "",
direction: "vertical"
}, {
default: withCtx(() => [
createVNode(_component_el_descriptions_item, { label: "Redis版本" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.redis_version) || "-"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "运行模式" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.redis_mode) === "standalone" ? "单机" : "集群"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "端口" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.tcp_port) || "-"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "客户端数" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.connected_clients) || 0), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "运行时间(天)" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.uptime_in_days) || 0), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "使用内存" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.used_memory_human) || "-"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "使用CPU" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.used_cpu_user_children) ? parseFloat(unref(cache).info.used_cpu_user_children).toFixed(2) : "-"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "内存配置" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.maxmemory_human) || "-"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "AOF是否开启" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.aof_enabled) === "0" ? "否" : "是"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "RDB是否成功" }, {
default: withCtx(() => {
var _a;
return [
createTextVNode(toDisplayString(((_a = unref(cache).info) == null ? void 0 : _a.rdb_last_bgsave_status) || "-"), 1)
];
}),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "Key数量" }, {
default: withCtx(() => [
createTextVNode(toDisplayString(unref(cache).db_size || 0), 1)
]),
_: 1
}),
createVNode(_component_el_descriptions_item, { label: "网络入口/出口" }, {
default: withCtx(() => {
var _a, _b;
return [
createTextVNode(toDisplayString(`${((_a = unref(cache).info) == null ? void 0 : _a.instantaneous_input_kbps) || 0}kps/${((_b = unref(cache).info) == null ? void 0 : _b.instantaneous_output_kbps) || 0}kps`), 1)
];
}),
_: 1
})
]),
_: 1
})
]),
_: 1
})
]),
_: 1
}),
createVNode(_component_el_col, {
span: 12,
class: "mt-4"
}, {
default: withCtx(() => [
createVNode(_component_el_card, { shadow: "hover" }, {
header: withCtx(() => [
createBaseVNode("div", _hoisted_3, [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_Stopwatch)
]),
_: 1
}),
_cache[4] || (_cache[4] = createBaseVNode("span", { class: "title" }, "命令统计", -1)),
createVNode(_component_el_tooltip, { content: "展示命令统计详情" }, {
default: withCtx(() => [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_QuestionFilled)
]),
_: 1
})
]),
_: 1
})
])
]),
default: withCtx(() => [
createBaseVNode("div", {
ref_key: "commandstats",
ref: commandstats,
class: "chart-container"
}, null, 512)
]),
_: 1
})
]),
_: 1
}),
createVNode(_component_el_col, {
span: 12,
class: "mt-4"
}, {
default: withCtx(() => [
createVNode(_component_el_card, { shadow: "hover" }, {
header: withCtx(() => [
createBaseVNode("div", _hoisted_4, [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_Stopwatch)
]),
_: 1
}),
_cache[5] || (_cache[5] = createBaseVNode("span", null, "内存信息", -1)),
createVNode(_component_el_tooltip, { content: "展示内存信息详情" }, {
default: withCtx(() => [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_QuestionFilled)
]),
_: 1
})
]),
_: 1
})
])
]),
default: withCtx(() => [
createBaseVNode("div", {
ref_key: "usedmemory",
ref: usedmemory,
class: "chart-container"
}, null, 512)
]),
_: 1
})
]),
_: 1
})
]),
_: 1
})
]),
_: 1
}),
createVNode(_component_el_tab_pane, {
class: "cache",
label: "缓存管理"
}, {
default: withCtx(() => [
createVNode(_component_el_row, { gutter: 16 }, {
default: withCtx(() => [
createVNode(_component_el_col, { span: 8 }, {
default: withCtx(() => [
createVNode(_component_el_card, {
loading: unref(loading),
shadow: "hover"
}, {
header: withCtx(() => [
createBaseVNode("div", _hoisted_5, [
createBaseVNode("div", _hoisted_6, [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_Tickets)
]),
_: 1
}),
_cache[6] || (_cache[6] = createBaseVNode("span", { class: "flex items-center gap-2" }, "缓存列表", -1)),
createVNode(_component_el_tooltip, { content: "展示缓存列表详情" }, {
default: withCtx(() => [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_QuestionFilled)
]),
_: 1
})
]),
_: 1
})
]),
createBaseVNode("div", null, [
withDirectives(createVNode(_component_el_button, {
type: "primary",
link: "",
icon: "RefreshRight",
onClick: refreshCacheNames
}, null, 512), [
[_directive_hasPerm, ["module_monitor:cache:query"]]
])
])
])
]),
default: withCtx(() => [
createVNode(_component_el_table, {
loading: unref(loading),
data: unref(cacheNames),
"row-key": "cache_name",
height: "600",
border: ""
}, {
empty: withCtx(() => [
createVNode(_component_el_empty, {
"image-size": 80,
description: "暂无数据"
})
]),
default: withCtx(() => [
createVNode(_component_el_table_column, {
prop: "cache_name",
label: "缓存名称",
"show-overflow-tooltip": ""
}, {
default: withCtx(({ row }) => [
withDirectives((openBlock(), createBlock(_component_el_button, {
type: "primary",
link: "",
onClick: ($event) => getCacheKeyList(row)
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(row.cache_name), 1)
]),
_: 2
}, 1032, ["onClick"])), [
[_directive_hasPerm, ["module_monitor:cache:query"]]
])
]),
_: 1
}),
createVNode(_component_el_table_column, {
prop: "remark",
label: "备注",
"show-overflow-tooltip": ""
}),
createVNode(_component_el_table_column, {
label: "操作",
width: "60",
align: "center"
}, {
default: withCtx(({ row }) => [
createVNode(_component_el_popconfirm, {
class: "box-item",
title: `确认删除缓存 ${row.cache_name} 吗?`,
placement: "top",
onConfirm: ($event) => handleClearCacheName(row)
}, {
reference: withCtx(() => [
withDirectives(createVNode(_component_el_button, {
type: "danger",
size: "small",
link: "",
icon: "delete"
}, null, 512), [
[_directive_hasPerm, ["module_monitor:cache:delete"]]
])
]),
_: 1
}, 8, ["title", "onConfirm"])
]),
_: 1
})
]),
_: 1
}, 8, ["loading", "data"])
]),
_: 1
}, 8, ["loading"])
]),
_: 1
}),
createVNode(_component_el_col, { span: 8 }, {
default: withCtx(() => [
createVNode(_component_el_card, {
loading: unref(loading),
shadow: "hover"
}, {
header: withCtx(() => [
createBaseVNode("div", _hoisted_7, [
createBaseVNode("div", _hoisted_8, [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_Key)
]),
_: 1
}),
_cache[7] || (_cache[7] = createBaseVNode("span", { class: "flex items-center gap-2" }, "键名列表", -1)),
createVNode(_component_el_tooltip, { content: "展示键名列表详情" }, {
default: withCtx(() => [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_QuestionFilled)
]),
_: 1
})
]),
_: 1
})
]),
createBaseVNode("div", null, [
withDirectives(createVNode(_component_el_button, {
type: "primary",
link: "",
icon: "RefreshRight",
onClick: refreshCacheKeys
}, null, 512), [
[_directive_hasPerm, ["module_monitor:cache:query"]]
])
])
])
]),
default: withCtx(() => [
createVNode(_component_el_table, {
loading: unref(subLoading),
data: unref(cacheKeys).map((key) => ({ cacheKey: key })),
height: "600",
"row-key": "cacheKey",
border: ""
}, {
empty: withCtx(() => [
createVNode(_component_el_empty, {
"image-size": 80,
description: "暂无数据"
})
]),
default: withCtx(() => [
createVNode(_component_el_table_column, {
prop: "cacheKey",
label: "缓存键名",
"show-overflow-tooltip": ""
}, {
default: withCtx(({ row }) => [
withDirectives((openBlock(), createBlock(_component_el_button, {
type: "primary",
link: "",
onClick: ($event) => handleCacheValue(row.cacheKey)
}, {
default: withCtx(() => [
createTextVNode(toDisplayString(row.cacheKey), 1)
]),
_: 2
}, 1032, ["onClick"])), [
[_directive_hasPerm, ["module_monitor:cache:detail"]]
])
]),
_: 1
}),
createVNode(_component_el_table_column, {
label: "操作",
width: "60",
align: "center"
}, {
default: withCtx(({ row }) => [
createVNode(_component_el_popconfirm, {
class: "box-item",
title: `确认删除键 ${row.cacheKey} 吗?`,
placement: "top",
onConfirm: ($event) => handleClearCacheKey(row.cacheKey)
}, {
reference: withCtx(() => [
withDirectives(createVNode(_component_el_button, {
type: "danger",
size: "small",
link: "",
icon: "delete"
}, null, 512), [
[_directive_hasPerm, ["module_monitor:cache:delete"]]
])
]),
_: 1
}, 8, ["title", "onConfirm"])
]),
_: 1
})
]),
_: 1
}, 8, ["loading", "data"])
]),
_: 1
}, 8, ["loading"])
]),
_: 1
}),
createVNode(_component_el_col, { span: 8 }, {
default: withCtx(() => [
createVNode(_component_el_card, {
loading: unref(loading),
shadow: "hover"
}, {
header: withCtx(() => [
createBaseVNode("div", _hoisted_9, [
createBaseVNode("div", _hoisted_10, [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_Key)
]),
_: 1
}),
_cache[8] || (_cache[8] = createBaseVNode("span", { class: "flex items-center gap-2" }, "缓存内容", -1)),
createVNode(_component_el_tooltip, { content: "展示缓存内容详情" }, {
default: withCtx(() => [
createVNode(_component_el_icon, null, {
default: withCtx(() => [
createVNode(_component_QuestionFilled)
]),
_: 1
})
]),
_: 1
})
]),
createBaseVNode("div", null, [
withDirectives((openBlock(), createBlock(_component_el_button, {
type: "danger",
link: "",
icon: "delete",
onClick: handleClearCacheAll
}, {
default: withCtx(() => [..._cache[9] || (_cache[9] = [
createTextVNode(" 清理全部 ", -1)
])]),
_: 1
})), [
[_directive_hasPerm, ["module_monitor:cache:delete"]]
])
])
])
]),
default: withCtx(() => [
createVNode(_component_el_form, {
model: unref(cacheForm),
"label-suffix": ":",
"label-width": "auto",
"label-position": "top"
}, {
default: withCtx(() => [
createVNode(_component_el_form_item, { label: "缓存名称" }, {
default: withCtx(() => [
createVNode(_component_el_input, {
modelValue: unref(cacheForm).cache_name,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => unref(cacheForm).cache_name = $event),
readonly: "",
placeholder: "缓存名称"
}, null, 8, ["modelValue"])
]),
_: 1
}),
createVNode(_component_el_form_item, { label: "缓存键名" }, {
default: withCtx(() => [
createVNode(_component_el_input, {
modelValue: unref(cacheForm).cache_key,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => unref(cacheForm).cache_key = $event),
readonly: "",
placeholder: "缓存键名"
}, null, 8, ["modelValue"])
]),
_: 1
}),
createVNode(_component_el_form_item, { label: "缓存内容" }, {
default: withCtx(() => [
createVNode(_component_el_input, {
modelValue: unref(cacheForm).cache_value,
"onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => unref(cacheForm).cache_value = $event),
type: "textarea",
rows: 18,
readonly: "",
placeholder: "缓存内容"
}, null, 8, ["modelValue"])
]),
_: 1
})
]),
_: 1
}, 8, ["model"])
]),
_: 1
}, 8, ["loading"])
]),
_: 1
})
]),
_: 1
})
]),
_: 1
})
]),
_: 1
})
]);
};
}
});
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-8e3ed0b9"]]);
export {
index as default
};