From 8d969c8d29672b9e2cf94e2659863a438b02da6c Mon Sep 17 00:00:00 2001 From: chrisronline Date: Fri, 15 Jan 2021 15:49:52 -0500 Subject: [PATCH] Some more --- x-pack/plugins/monitoring/common/types/es.ts | 47 ++++++++++++++++++- ...luster_status.js => get_cluster_status.ts} | 30 ++++++------ 2 files changed, 60 insertions(+), 17 deletions(-) rename x-pack/plugins/monitoring/server/lib/cluster/{get_cluster_status.js => get_cluster_status.ts} (53%) diff --git a/x-pack/plugins/monitoring/common/types/es.ts b/x-pack/plugins/monitoring/common/types/es.ts index eb806764e8730..2802dcaea9a79 100644 --- a/x-pack/plugins/monitoring/common/types/es.ts +++ b/x-pack/plugins/monitoring/common/types/es.ts @@ -100,8 +100,35 @@ export interface ElasticsearchNodeStats { export interface ElasticsearchLegacySource { timestamp: string; cluster_uuid: string; - cluster_stats?: {}; + cluster_stats?: { + nodes?: { + count?: { + total?: number; + }; + jvm?: { + max_uptime_in_millis?: number; + mem?: { + heap_used_in_bytes?: number; + heap_max_in_bytes?: number; + }; + }; + versions?: string[]; + }; + indices?: { + count?: number; + docs?: { + count?: number; + }; + shards?: { + total?: number; + }; + store?: { + size_in_bytes?: number; + }; + }; + }; cluster_state?: { + status?: string; nodes?: { [nodeUuid: string]: {}; }; @@ -199,7 +226,23 @@ export interface ElasticsearchLegacySource { }; }; }; - job_stats?: {}; + job_stats?: { + job_id?: number; + state?: string; + data_counts?: { + processed_record_count?: number; + }; + model_size_stats?: { + model_bytes?: number; + }; + forecasts_stats?: { + total?: number; + }; + node?: { + id?: number; + name?: string; + }; + }; index_stats?: { index?: string; primaries?: { diff --git a/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.js b/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.ts similarity index 53% rename from x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.js rename to x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.ts index cef06bb473c3f..3184893d6c637 100644 --- a/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.js +++ b/x-pack/plugins/monitoring/server/lib/cluster/get_cluster_status.ts @@ -3,20 +3,20 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - import { get } from 'lodash'; +import { ElasticsearchSource } from '../../../common/types/es'; /* * @param cluster {Object} clusterStats from getClusterStatus * @param unassignedShards {Object} shardStats from getShardStats * @return top-level cluster summary data */ -export function getClusterStatus(cluster, shardStats) { - const clusterStats = get(cluster, 'cluster_stats', {}); - const clusterNodes = get(clusterStats, 'nodes', {}); - const clusterIndices = get(clusterStats, 'indices', {}); +export function getClusterStatus(cluster: ElasticsearchSource, shardStats: unknown) { + const clusterStats = cluster.cluster_stats ?? {}; + const clusterNodes = clusterStats.nodes ?? {}; + const clusterIndices = clusterStats.indices ?? {}; - const clusterTotalShards = get(clusterIndices, 'shards.total', 0); + const clusterTotalShards = clusterIndices.shards?.total ?? 0; let unassignedShardsTotal = 0; const unassignedShards = get(shardStats, 'indicesTotals.unassigned'); if (unassignedShards !== undefined) { @@ -26,17 +26,17 @@ export function getClusterStatus(cluster, shardStats) { const totalShards = clusterTotalShards + unassignedShardsTotal; return { - status: get(cluster, 'cluster_state.status', 'unknown'), + status: cluster.cluster_state?.status ?? 'unknown', // index-based stats - indicesCount: get(clusterIndices, 'count', 0), - documentCount: get(clusterIndices, 'docs.count', 0), - dataSize: get(clusterIndices, 'store.size_in_bytes', 0), + indicesCount: clusterIndices.count ?? 0, + documentCount: clusterIndices.docs?.count ?? 0, + dataSize: clusterIndices.store?.size_in_bytes ?? 0, // node-based stats - nodesCount: get(clusterNodes, 'count.total', 0), - upTime: get(clusterNodes, 'jvm.max_uptime_in_millis', 0), - version: get(clusterNodes, 'versions', null), - memUsed: get(clusterNodes, 'jvm.mem.heap_used_in_bytes', 0), - memMax: get(clusterNodes, 'jvm.mem.heap_max_in_bytes', 0), + nodesCount: clusterNodes.count?.total ?? 0, + upTime: clusterNodes.jvm?.max_uptime_in_millis ?? 0, + version: clusterNodes.versions ?? null, + memUsed: clusterNodes.jvm?.mem?.heap_used_in_bytes ?? 0, + memMax: clusterNodes.jvm?.mem?.heap_max_in_bytes ?? 0, unassignedShards: unassignedShardsTotal, totalShards, };