33 * or more contributor license agreements. Licensed under the Elastic License;
44 * you may not use this file except in compliance with the Elastic License.
55 */
6-
76import { get } from 'lodash' ;
7+ import { ElasticsearchSource } from '../../../common/types/es' ;
88
99/*
1010 * @param cluster {Object} clusterStats from getClusterStatus
1111 * @param unassignedShards {Object} shardStats from getShardStats
1212 * @return top-level cluster summary data
1313 */
14- export function getClusterStatus ( cluster , shardStats ) {
15- const clusterStats = get ( cluster , ' cluster_stats' , { } ) ;
16- const clusterNodes = get ( clusterStats , ' nodes' , { } ) ;
17- const clusterIndices = get ( clusterStats , ' indices' , { } ) ;
14+ export function getClusterStatus ( cluster : ElasticsearchSource , shardStats : unknown ) {
15+ const clusterStats = cluster . cluster_stats ?? { } ;
16+ const clusterNodes = clusterStats . nodes ?? { } ;
17+ const clusterIndices = clusterStats . indices ?? { } ;
1818
19- const clusterTotalShards = get ( clusterIndices , ' shards.total' , 0 ) ;
19+ const clusterTotalShards = clusterIndices . shards ? .total ?? 0 ;
2020 let unassignedShardsTotal = 0 ;
2121 const unassignedShards = get ( shardStats , 'indicesTotals.unassigned' ) ;
2222 if ( unassignedShards !== undefined ) {
@@ -26,17 +26,17 @@ export function getClusterStatus(cluster, shardStats) {
2626 const totalShards = clusterTotalShards + unassignedShardsTotal ;
2727
2828 return {
29- status : get ( cluster , ' cluster_state.status' , 'unknown' ) ,
29+ status : cluster . cluster_state ? .status ?? 'unknown' ,
3030 // index-based stats
31- indicesCount : get ( clusterIndices , ' count' , 0 ) ,
32- documentCount : get ( clusterIndices , ' docs.count' , 0 ) ,
33- dataSize : get ( clusterIndices , ' store.size_in_bytes' , 0 ) ,
31+ indicesCount : clusterIndices . count ?? 0 ,
32+ documentCount : clusterIndices . docs ? .count ?? 0 ,
33+ dataSize : clusterIndices . store ? .size_in_bytes ?? 0 ,
3434 // node-based stats
35- nodesCount : get ( clusterNodes , ' count.total' , 0 ) ,
36- upTime : get ( clusterNodes , ' jvm.max_uptime_in_millis' , 0 ) ,
37- version : get ( clusterNodes , ' versions' , null ) ,
38- memUsed : get ( clusterNodes , ' jvm.mem.heap_used_in_bytes' , 0 ) ,
39- memMax : get ( clusterNodes , ' jvm.mem.heap_max_in_bytes' , 0 ) ,
35+ nodesCount : clusterNodes . count ? .total ?? 0 ,
36+ upTime : clusterNodes . jvm ? .max_uptime_in_millis ?? 0 ,
37+ version : clusterNodes . versions ?? null ,
38+ memUsed : clusterNodes . jvm ? .mem ? .heap_used_in_bytes ?? 0 ,
39+ memMax : clusterNodes . jvm ? .mem ? .heap_max_in_bytes ?? 0 ,
4040 unassignedShards : unassignedShardsTotal ,
4141 totalShards,
4242 } ;
0 commit comments