From 1b0fe9b4b9eb14f2674d9f8bd8cef8066bf327b8 Mon Sep 17 00:00:00 2001 From: qishibo Date: Sat, 17 Feb 2024 20:23:50 +0800 Subject: [PATCH] add keys count for each master node in cluster --- src/components/Status.vue | 123 +++++++++++++++++++++++++++++++------- 1 file changed, 103 insertions(+), 20 deletions(-) diff --git a/src/components/Status.vue b/src/components/Status.vue index 92645a010..721f276c5 100644 --- a/src/components/Status.vue +++ b/src/components/Status.vue @@ -113,8 +113,55 @@ + + + + +
+ + {{ $t('message.key_statistics') }} +
+ + + + + + + + + + + + + + +
+
+
+ - +
@@ -201,31 +248,14 @@ export default { connectionStatus: {}, statusConnection: null, allInfoFilter: '', + clusterKeysInfo: [], }; }, props: ['client', 'hotKeyScope'], components: { ScrollToTop }, computed: { DBKeys() { - const dbs = []; - - for (const i in this.connectionStatus) { - // fix #1101 unexpected db prefix - // if (i.startsWith('db')) { - if (/^db\d+/.test(i)) { - const item = this.connectionStatus[i]; - const array = item.split(','); - - dbs.push({ - db: i, - keys: array[0] ? array[0].split('=')[1] : NaN, - expires: array[1] ? array[1].split('=')[1] : NaN, - avg_ttl: array[2] ? array[2].split('=')[1] : NaN, - }); - } - } - - return dbs; + return this.initDbKeys(this.connectionStatus); }, AllRedisInfo() { const infos = []; @@ -267,6 +297,9 @@ export default { this.$message.error(e.message) } }); + + // if cluster, init keys count in master nodes + this.initClusterKeys(); }, refreshInit() { this.refreshTimer && clearInterval(this.refreshTimer); @@ -306,6 +339,56 @@ export default { return lines; }, + initDbKeys(status, name = undefined) { + const dbs = []; + + for (const i in status) { + // fix #1101 unexpected db prefix + // if (i.startsWith('db')) { + if (/^db\d+/.test(i)) { + const item = status[i]; + const array = item.split(','); + + dbs.push({ + db: i, + keys: array[0] ? array[0].split('=')[1] : NaN, + expires: array[1] ? array[1].split('=')[1] : NaN, + avg_ttl: array[2] ? array[2].split('=')[1] : NaN, + name: name, + }); + } + } + + return dbs; + }, + initClusterKeys() { + let nodes = this.client.nodes ? this.client.nodes('master') : [this.client]; + + // not in cluster mode + if (nodes.length < 2) { + return; + } + + nodes.map(node => { + node.call('INFO', 'KEYSPACE').then(reply => { + const options = node.options; + const name = `${options.host}:${options.port}`; + + const keys = this.initDbKeys(this.initStatus(reply), name); + + // clear only when first reply, avoid jitter + if (this.clusterKeysInfo.length === nodes.length) { + this.clusterKeysInfo = []; + } + + this.clusterKeysInfo = this.clusterKeysInfo.concat(keys); + // sort by node name + this.clusterKeysInfo.sort((a, b) => a.name > b.name ? 1 : -1); + }).catch(e => { + this.$message.error(e.message); + }); + }); + }, initShortcut() { this.$shortcut.bind('ctrl+r, ⌘+r, f5', this.hotKeyScope, () => { this.initShow();