diff --git a/x-pack/plugins/monitoring/common/types/es.ts b/x-pack/plugins/monitoring/common/types/es.ts index b6b0b1149ee3e..942a0d28ff43f 100644 --- a/x-pack/plugins/monitoring/common/types/es.ts +++ b/x-pack/plugins/monitoring/common/types/es.ts @@ -539,9 +539,11 @@ export interface ElasticsearchMetricbeatSource { kibana?: { stats?: { name?: string; + index?: string; status?: string; transport_address?: string; concurrent_connections?: number; + snapshot?: boolean; host?: { name?: string; }; diff --git a/x-pack/plugins/monitoring/server/lib/kibana/build_kibana_info.ts b/x-pack/plugins/monitoring/server/lib/kibana/build_kibana_info.ts new file mode 100644 index 0000000000000..463217eda32dd --- /dev/null +++ b/x-pack/plugins/monitoring/server/lib/kibana/build_kibana_info.ts @@ -0,0 +1,28 @@ +import { ElasticsearchResponseHit } from '../../../common/types/es'; + +export interface KibanaInfo { + transport_address?: string; + name?: string; + index?: string; + host?: string; + uuid?: string; + status?: string; + snapshot?: boolean; + version?: string; +} + +export const buildKibanaInfo = (hit: ElasticsearchResponseHit): KibanaInfo => { + const source = hit._source; + if (source.kibana_stats) return source.kibana_stats.kibana as KibanaInfo; + + return { + name: source.kibana?.stats?.name, + host: source.kibana?.stats?.host?.name, + status: source.kibana?.stats?.status, + transport_address: source.kibana?.stats?.transport_address, + uuid: source.service?.id, + snapshot: source.kibana?.stats?.snapshot, + index: source.kibana?.stats?.index, + version: source.service?.version, + }; +}; diff --git a/x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.ts b/x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.ts index 309f26c210831..81a653d370c0b 100644 --- a/x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.ts +++ b/x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.ts @@ -12,21 +12,21 @@ import { checkParam, MissingRequiredError } from '../error_missing_required'; import { calculateAvailability } from '../calculate_availability'; import { LegacyRequest } from '../../types'; import { ElasticsearchResponse } from '../../../common/types/es'; +import { buildKibanaInfo } from './build_kibana_info'; export function handleResponse(resp: ElasticsearchResponse) { const hit = resp.hits?.hits[0]; const legacySource = hit?._source.kibana_stats; const mbSource = hit?._source.kibana?.stats; - const kibana = mbSource ?? legacySource?.kibana; const availabilityTimestamp = hit?._source['@timestamp'] ?? legacySource?.timestamp; if (!availabilityTimestamp) { throw new MissingRequiredError('timestamp'); } - return merge(kibana, { + + return merge(buildKibanaInfo(hit!), { availability: calculateAvailability(availabilityTimestamp), os_memory_free: mbSource?.os?.memory?.free_in_bytes ?? legacySource?.os?.memory?.free_in_bytes, uptime: mbSource?.process?.uptime?.ms ?? legacySource?.process?.uptime_in_millis, - version: hit?._source.service?.version ?? legacySource?.kibana?.version, }); } @@ -50,6 +50,7 @@ export function getKibanaInfo( 'hits.hits._source.kibana.stats.process.uptime.ms', 'hits.hits._source.kibana_stats.timestamp', 'hits.hits._source.@timestamp', + 'hits.hits._source.service.id', 'hits.hits._source.service.version', ], body: { diff --git a/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.ts b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.ts index 02a358d46b26f..6e55bf83bbd02 100644 --- a/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.ts +++ b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.ts @@ -16,14 +16,7 @@ import { calculateAvailability } from '../calculate_availability'; import { KibanaMetric } from '../metrics'; import { LegacyRequest } from '../../types'; import { ElasticsearchResponse, ElasticsearchResponseHit } from '../../../common/types/es'; - -interface KibanaInfo { - transport_address?: string; - name?: string; - host?: string; - uuid?: string; - status?: string; -} +import { KibanaInfo, buildKibanaInfo } from './build_kibana_info'; interface Kibana { process?: { @@ -119,19 +112,6 @@ export async function getKibanas( const response: ElasticsearchResponse = await callWithRequest(req, 'search', params); const instances = response.hits?.hits ?? []; - const buildKibanaInfo = (hit: ElasticsearchResponseHit): KibanaInfo => { - const source = hit._source; - if (source.kibana_stats) return source.kibana_stats.kibana as KibanaInfo; - - return { - name: source.kibana?.stats?.name, - host: source.kibana?.stats?.host?.name, - status: source.kibana?.stats?.status, - transport_address: source.kibana?.stats?.transport_address, - uuid: source.service?.id, - }; - }; - return instances.map((hit: ElasticsearchResponseHit) => { const legacyStats = hit._source.kibana_stats; const mbStats = hit._source.kibana?.stats;