@@ -12,6 +12,7 @@ import {
12
12
convertBulkStringsToObject ,
13
13
convertRedisInfoReplyToObject ,
14
14
} from 'src/utils' ;
15
+ import { getTotal } from 'src/modules/database/utils/database.total.util' ;
15
16
import { DatabaseOverview } from 'src/modules/database/models/database-overview' ;
16
17
17
18
@Injectable ( )
@@ -29,16 +30,21 @@ export class DatabaseOverviewProvider {
29
30
) : Promise < DatabaseOverview > {
30
31
let nodesInfo = [ ] ;
31
32
let currentDbIndex = 0 ;
33
+ let totalKeys ;
34
+ let totalKeysPerDb ;
32
35
33
- if ( client instanceof IORedis . Cluster ) {
36
+ if ( client . isCluster ) {
34
37
currentDbIndex = get ( client , [ 'options' , 'db' ] , 0 ) ;
35
- nodesInfo = await this . getNodesInfo ( client ) ;
38
+ nodesInfo = await this . getNodesInfo ( client as IORedis . Cluster ) ;
39
+ totalKeys = await this . calculateNodesTotalKeys ( client ) ;
36
40
} else {
37
41
currentDbIndex = get ( client , [ 'options' , 'db' ] , 0 ) ;
38
- nodesInfo = [ await this . getNodeInfo ( client ) ] ;
42
+ nodesInfo = [ await this . getNodeInfo ( client as IORedis . Redis ) ] ;
43
+ const [ calculatedTotalKeys , calculatedTotalKeysPerDb ] = this . calculateTotalKeys ( nodesInfo , currentDbIndex ) ;
44
+ totalKeys = calculatedTotalKeys ;
45
+ totalKeysPerDb = calculatedTotalKeysPerDb ;
39
46
}
40
47
41
- const [ totalKeys , totalKeysPerDb ] = this . calculateTotalKeys ( nodesInfo , currentDbIndex ) ;
42
48
return {
43
49
version : this . getVersion ( nodesInfo ) ,
44
50
totalKeys,
@@ -234,6 +240,19 @@ export class DatabaseOverviewProvider {
234
240
}
235
241
}
236
242
243
+ private async calculateNodesTotalKeys (
244
+ client : IORedis . Cluster ,
245
+ ) : Promise < number > {
246
+ const nodesTotal : number [ ] = await Promise . all (
247
+ client
248
+ . nodes ( 'master' )
249
+ . map ( async ( node ) => getTotal ( node ) ) ,
250
+ ) ;
251
+ return nodesTotal . reduce ( ( prev , cur ) => (
252
+ prev + cur
253
+ ) , 0 ) ;
254
+ }
255
+
237
256
/**
238
257
* Calculates sum of cpu usage in percentage for all shards
239
258
* CPU% = ((used_cpu_sys_t2+used_cpu_user_t2)-(used_cpu_sys_t1+used_cpu_user_t1)) / (t2-t1)
0 commit comments