diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/fixtures/beats_stats_results.json b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/fixtures/beats_stats_results.json index be6e4352514fe8..c7fadc5057d310 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/fixtures/beats_stats_results.json +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/fixtures/beats_stats_results.json @@ -2,6 +2,58 @@ { "hits": { "hits": [ + { + "_source" : { + "cluster_uuid": "W7hppdX7R229Oy3KQbZrTw", + "type": "beats_state", + "beats_state" : { + "state" : { + "heartbeat" : { + "endpoints" : 2, + "http" : { + "endpoints" : 1, + "monitors" : 1 + }, + "icmp" : { + "monitors" : 0, + "endpoints" : 0 + }, + "tcp" : { + "monitors" : 1, + "endpoints" : 1 + }, + "monitors" : 2 + } + } + } + } + }, + { + "_source" : { + "cluster_uuid": "W7hppdX7R229Oy3KQbZrTw", + "type": "beats_state", + "beats_state" : { + "state" : { + "heartbeat" : { + "endpoints" : 2, + "http" : { + "endpoints" : 0, + "monitors" : 0 + }, + "icmp" : { + "monitors" : 0, + "endpoints" : 0 + }, + "tcp" : { + "monitors" : 1, + "endpoints" : 2 + }, + "monitors" : 1 + } + } + } + } + }, { "_source": { "type": "beats_state", @@ -74,6 +126,26 @@ "published": 1038 } } + }, + "heartbeat" : { + "http" : { + "endpoint_starts" : 1, + "endpoint_stops" : 0, + "monitor_starts" : 1, + "monitor_stops" : 0 + }, + "icmp" : { + "endpoint_starts" : 0, + "endpoint_stops" : 0, + "monitor_starts" : 0, + "monitor_stops" : 0 + }, + "tcp" : { + "endpoint_starts" : 1, + "endpoint_stops" : 0, + "monitor_starts" : 1, + "monitor_stops" : 0 + } } } } @@ -11531,5 +11603,6 @@ ] } }, + {} ] diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/get_beats_stats.js b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/get_beats_stats.js index 3cde267a1536bc..42642b16de4c48 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/get_beats_stats.js +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/__tests__/get_beats_stats.js @@ -154,6 +154,22 @@ describe('Get Beats Stats', () => { name: 'darwin' } ] + }, + heartbeat: { + endpoints: 4, + http: { + endpoints: 1, + monitors: 1 + }, + icmp: { + monitors: 0, + endpoints: 0 + }, + tcp: { + monitors: 2, + endpoints: 3 + }, + monitors: 3 } }, FlV4ckTxQ0a78hmBkzzc9A: { diff --git a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js index ff0ddadac40f11..321e2ebdad642c 100644 --- a/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js +++ b/x-pack/plugins/xpack_main/server/lib/telemetry/monitoring/get_beats_stats.js @@ -103,6 +103,34 @@ export function processResults(results = [], { clusters, clusterHostSets, cluste clusters[clusterUuid].module.count += stateModule.count; } + const heartbeatState = get(hit, '_source.beats_state.state.heartbeat'); + if (heartbeatState !== undefined) { + if (!clusters[clusterUuid].hasOwnProperty('heartbeat')) { + clusters[clusterUuid].heartbeat = { + monitors: 0, + endpoints: 0 + }; + } + const clusterHb = clusters[clusterUuid].heartbeat; + + clusterHb.monitors += heartbeatState.monitors; + clusterHb.endpoints += heartbeatState.endpoints; + for (const proto in heartbeatState) { + if (!heartbeatState.hasOwnProperty(proto)) continue; + const val = heartbeatState[proto]; + if (typeof val !== "object") continue; + + if (!clusterHb.hasOwnProperty(proto)) { + clusterHb[proto] = { + monitors: 0, + endpoints: 0 + }; + } + clusterHb[proto].monitors += val.monitors; + clusterHb[proto].endpoints += val.endpoints; + } + } + const stateHost = get(hit, '_source.beats_state.state.host'); if (stateHost !== undefined) { const hostMap = clusterArchitectureMaps[clusterUuid]; @@ -161,6 +189,7 @@ async function fetchBeatsByType(server, callCluster, clusterUuids, start, end, { 'hits.hits._source.beats_state.state.input', 'hits.hits._source.beats_state.state.module', 'hits.hits._source.beats_state.state.host', + 'hits.hits._source.beats_state.state.heartbeat', ], body: { query: createQuery({