Skip to content

Commit 8d969c8

Browse files
committed
Some more
1 parent a6d8780 commit 8d969c8

2 files changed

Lines changed: 60 additions & 17 deletions

File tree

x-pack/plugins/monitoring/common/types/es.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,35 @@ export interface ElasticsearchNodeStats {
100100
export interface ElasticsearchLegacySource {
101101
timestamp: string;
102102
cluster_uuid: string;
103-
cluster_stats?: {};
103+
cluster_stats?: {
104+
nodes?: {
105+
count?: {
106+
total?: number;
107+
};
108+
jvm?: {
109+
max_uptime_in_millis?: number;
110+
mem?: {
111+
heap_used_in_bytes?: number;
112+
heap_max_in_bytes?: number;
113+
};
114+
};
115+
versions?: string[];
116+
};
117+
indices?: {
118+
count?: number;
119+
docs?: {
120+
count?: number;
121+
};
122+
shards?: {
123+
total?: number;
124+
};
125+
store?: {
126+
size_in_bytes?: number;
127+
};
128+
};
129+
};
104130
cluster_state?: {
131+
status?: string;
105132
nodes?: {
106133
[nodeUuid: string]: {};
107134
};
@@ -199,7 +226,23 @@ export interface ElasticsearchLegacySource {
199226
};
200227
};
201228
};
202-
job_stats?: {};
229+
job_stats?: {
230+
job_id?: number;
231+
state?: string;
232+
data_counts?: {
233+
processed_record_count?: number;
234+
};
235+
model_size_stats?: {
236+
model_bytes?: number;
237+
};
238+
forecasts_stats?: {
239+
total?: number;
240+
};
241+
node?: {
242+
id?: number;
243+
name?: string;
244+
};
245+
};
203246
index_stats?: {
204247
index?: string;
205248
primaries?: {

x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.js renamed to x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
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-
76
import { 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

Comments
 (0)