Skip to content

Commit

Permalink
Some more
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Jan 15, 2021
1 parent a6d8780 commit 8d969c8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
47 changes: 45 additions & 2 deletions x-pack/plugins/monitoring/common/types/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]: {};
};
Expand Down Expand Up @@ -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?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
};
Expand Down

0 comments on commit 8d969c8

Please sign in to comment.