diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/container/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/index.ts new file mode 100644 index 0000000000000..254ed7b759300 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { layout } from './layout'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const container: InventoryModel = { + id: 'container', + requiredModules: ['docker'], + layout, + metrics, +}; diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/container.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/layout.ts similarity index 73% rename from x-pack/legacy/plugins/infra/public/pages/metrics/layouts/container.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/layout.ts index 65dd1acddbf98..821e180cda016 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/container.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/layout.ts @@ -5,16 +5,10 @@ */ import { i18n } from '@kbn/i18n'; -import { InfraMetric } from '../../../graphql/types'; -import { InfraFormatterType } from '../../../lib/lib'; -import { nginxLayoutCreator } from './nginx'; -import { - InfraMetricLayoutCreator, - InfraMetricLayoutSectionType, - InfraMetricLayoutVisualizationType, -} from './types'; +import { InventoryDetailLayoutCreator } from '../types'; +import { nginxLayoutCreator } from '../shared/layouts/nginx'; -export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ +export const layout: InventoryDetailLayoutCreator = theme => [ { id: 'containerOverview', label: i18n.translate('xpack.infra.metricDetailPage.containerMetricsLayout.layoutLabel', { @@ -22,7 +16,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ }), sections: [ { - id: InfraMetric.containerOverview, + id: 'containerOverview', label: i18n.translate( 'xpack.infra.metricDetailPage.containerMetricsLayout.overviewSection.sectionLabel', { @@ -30,7 +24,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['docker.cpu', 'docker.memory', 'docker.network'], - type: InfraMetricLayoutSectionType.gauges, + type: 'gauges', visConfig: { seriesOverrides: { cpu: { @@ -41,7 +35,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, + formatter: 'percent', gaugeMax: 1, }, memory: { @@ -52,7 +46,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, + formatter: 'percent', gaugeMax: 1, }, rx: { @@ -63,7 +57,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.bits, + formatter: 'bits', formatterTemplate: '{{value}}/s', }, tx: { @@ -74,14 +68,14 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.bits, + formatter: 'bits', formatterTemplate: '{{value}}/s', }, }, }, }, { - id: InfraMetric.containerCpuUsage, + id: 'containerCpuUsage', label: i18n.translate( 'xpack.infra.metricDetailPage.containerMetricsLayout.cpuUsageSection.sectionLabel', { @@ -89,24 +83,18 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['docker.cpu'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { stacked: true, - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.percent, + type: 'area', + formatter: 'percent', seriesOverrides: { - cpu: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.containerMetricsLayout.cpuUsageSection.seriesLabel.cpu', - { defaultMessage: 'cpu' } - ), - }, + cpu: { color: theme.eui.euiColorVis1 }, }, }, }, { - id: InfraMetric.containerMemory, + id: 'containerMemory', label: i18n.translate( 'xpack.infra.metricDetailPage.containerMetricsLayout.memoryUsageSection.sectionLabel', { @@ -114,24 +102,18 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['docker.memory'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { stacked: true, - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.percent, + type: 'area', + formatter: 'percent', seriesOverrides: { - memory: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.containerMetricsLayout.memoryUsageSection.seriesLabel.memory', - { defaultMessage: 'memory' } - ), - }, + memory: { color: theme.eui.euiColorVis1 }, }, }, }, { - id: InfraMetric.containerNetworkTraffic, + id: 'containerNetworkTraffic', label: i18n.translate( 'xpack.infra.metricDetailPage.containerMetricsLayout.networkTrafficSection.sectionLabel', { @@ -139,11 +121,11 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['docker.network'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - formatter: InfraFormatterType.bits, + formatter: 'bits', formatterTemplate: '{{value}}/s', - type: InfraMetricLayoutVisualizationType.area, + type: 'area', seriesOverrides: { rx: { color: theme.eui.euiColorVis1, @@ -167,7 +149,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ }, }, { - id: InfraMetric.containerDiskIOOps, + id: 'containerDiskIOOps', label: i18n.translate( 'xpack.infra.metricDetailPage.containerMetricsLayout.diskIoOpsSection.sectionLabel', { @@ -175,11 +157,11 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['docker.diskio'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - formatter: InfraFormatterType.number, + formatter: 'number', formatterTemplate: '{{value}}/s', - type: InfraMetricLayoutVisualizationType.area, + type: 'area', seriesOverrides: { read: { color: theme.eui.euiColorVis1, @@ -203,7 +185,7 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ }, }, { - id: InfraMetric.containerDiskIOBytes, + id: 'containerDiskIOBytes', label: i18n.translate( 'xpack.infra.metricDetailPage.containerMetricsLayout.diskIoBytesSection.sectionLabel', { @@ -211,11 +193,11 @@ export const containerLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['docker.diskio'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - formatter: InfraFormatterType.bytes, + formatter: 'bytes', formatterTemplate: '{{value}}/s', - type: InfraMetricLayoutVisualizationType.area, + type: 'area', seriesOverrides: { read: { color: theme.eui.euiColorVis1, diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/index.ts new file mode 100644 index 0000000000000..9cbbb2dca7ffa --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/index.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { InventoryMetrics } from '../../types'; +import { cpu } from './snapshot/cpu'; +import { memory } from './snapshot/memory'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; + +import { containerOverview } from './tsvb/container_overview'; +import { containerCpuUsage } from './tsvb/container_cpu_usage'; +import { containerCpuKernel } from './tsvb/container_cpu_kernel'; +import { containerDiskIOOps } from './tsvb/container_diskio_ops'; +import { containerDiskIOBytes } from './tsvb/container_disk_io_bytes'; +import { containerMemory } from './tsvb/container_memory'; +import { containerNetworkTraffic } from './tsvb/container_network_traffic'; + +export const metrics: InventoryMetrics = { + tsvb: { + containerOverview, + containerCpuUsage, + containerCpuKernel, + containerDiskIOOps, + containerDiskIOBytes, + containerNetworkTraffic, + containerMemory, + }, + snapshot: { cpu, memory, rx, tx }, +}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/count.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/cpu.ts similarity index 50% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/count.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/cpu.ts index a81e7ff505cfd..a6c25ee260cac 100644 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/count.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/cpu.ts @@ -4,17 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -export const count = () => { - return { - count: { - bucket_script: { - buckets_path: { count: '_count' }, - script: { - source: 'count * 1', - lang: 'expression', - }, - gap_policy: 'skip', - }, +import { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu: { + avg: { + field: 'docker.cpu.total.pct', }, - }; + }, }; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/memory.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/memory.ts new file mode 100644 index 0000000000000..30df0ebbaa1d4 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/memory.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const memory: SnapshotModel = { memory: { avg: { field: 'docker.memory.usage.pct' } } }; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/rx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..6843f6149c711 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/rx.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const rx = networkTrafficWithInterfaces( + 'rx', + 'docker.network.in.bytes', + 'docker.network.interface' +); diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/tx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..bccb4e60e9d19 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/snapshot/tx.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const tx = networkTrafficWithInterfaces( + 'tx', + 'docker.network.out.bytes', + 'docker.network.interface' +); diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_cpu_kernel.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_kernel.ts similarity index 62% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_cpu_kernel.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_kernel.ts index 1aff438aaf07a..9e4a6dad429bb 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_cpu_kernel.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_kernel.ts @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerCpuKernel: InfraMetricModelCreator = (timeField, indexPattern, interval) => ({ - id: InfraMetric.containerCpuKernel, +export const containerCpuKernel: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerCpuKernel', requires: ['docker.cpu'], index_pattern: indexPattern, interval, @@ -22,7 +25,7 @@ export const containerCpuKernel: InfraMetricModelCreator = (timeField, indexPatt { field: 'docker.cpu.kernel.pct', id: 'avg-cpu-kernel', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_cpu_usage.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_usage.ts similarity index 62% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_cpu_usage.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_usage.ts index 81290cec4805f..0eb84f4c3aca5 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_cpu_usage.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_cpu_usage.ts @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerCpuUsage: InfraMetricModelCreator = (timeField, indexPattern, interval) => ({ - id: InfraMetric.containerCpuUsage, +export const containerCpuUsage: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerCpuUsage', requires: ['docker.cpu'], index_pattern: indexPattern, interval, @@ -22,7 +25,7 @@ export const containerCpuUsage: InfraMetricModelCreator = (timeField, indexPatte { field: 'docker.cpu.total.pct', id: 'avg-cpu-total', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_disk_io_bytes.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_disk_io_bytes.ts similarity index 74% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_disk_io_bytes.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_disk_io_bytes.ts index 9e028b918ec9e..273056f376825 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_disk_io_bytes.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_disk_io_bytes.ts @@ -4,15 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerDiskIOBytes: InfraMetricModelCreator = ( +export const containerDiskIOBytes: TSVBMetricModelCreator = ( timeField, indexPattern, interval -) => ({ - id: InfraMetric.containerDiskIOBytes, +): TSVBMetricModel => ({ + id: 'containerDiskIOBytes', requires: ['docker.disk'], index_pattern: indexPattern, interval, @@ -26,17 +25,17 @@ export const containerDiskIOBytes: InfraMetricModelCreator = ( { field: 'docker.diskio.read.bytes', id: 'max-diskio-read-bytes', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-diskio-read-bytes', id: 'deriv-max-diskio-read-bytes', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-diskio-read-bytes', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-read-bytes' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, @@ -49,24 +48,24 @@ export const containerDiskIOBytes: InfraMetricModelCreator = ( { field: 'docker.diskio.write.bytes', id: 'max-diskio-write-bytes', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-diskio-write-bytes', id: 'deriv-max-diskio-write-bytes', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-diskio-write-bytes', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-write-bytes' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { id: 'calc-invert-rate', script: 'params.rate * -1', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'posonly-deriv-max-diskio-write-bytes', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_diskio_ops.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_diskio_ops.ts similarity index 72% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_diskio_ops.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_diskio_ops.ts index 561cdf519353e..4067a5cf6c6f4 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_diskio_ops.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_diskio_ops.ts @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerDiskIOOps: InfraMetricModelCreator = (timeField, indexPattern, interval) => ({ - id: InfraMetric.containerDiskIOOps, +export const containerDiskIOOps: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerDiskIOOps', requires: ['docker.disk'], index_pattern: indexPattern, interval, @@ -22,17 +25,17 @@ export const containerDiskIOOps: InfraMetricModelCreator = (timeField, indexPatt { field: 'docker.diskio.read.ops', id: 'max-diskio-read-ops', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-diskio-read-ops', id: 'deriv-max-diskio-read-ops', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-diskio-read-ops', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-read-ops' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, @@ -45,24 +48,24 @@ export const containerDiskIOOps: InfraMetricModelCreator = (timeField, indexPatt { field: 'docker.diskio.write.ops', id: 'max-diskio-write-ops', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-diskio-write-ops', id: 'deriv-max-diskio-write-ops', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-diskio-write-ops', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-diskio-write-ops' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { id: 'calc-invert-rate', script: 'params.rate * -1', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'posonly-deriv-max-diskio-write-ops', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_memory.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_memory.ts similarity index 63% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_memory.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_memory.ts index dc984f5475328..8af7f057e8bad 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_memory.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_memory.ts @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerMemory: InfraMetricModelCreator = (timeField, indexPattern, interval) => ({ - id: InfraMetric.containerMemory, +export const containerMemory: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerMemory', requires: ['docker.memory'], index_pattern: indexPattern, interval, @@ -22,7 +25,7 @@ export const containerMemory: InfraMetricModelCreator = (timeField, indexPattern { field: 'docker.memory.usage.pct', id: 'avg-memory', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_network_traffic.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_network_traffic.ts similarity index 71% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_network_traffic.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_network_traffic.ts index a993d85cb4165..18daac446bdcd 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_network_traffic.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_network_traffic.ts @@ -4,15 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerNetworkTraffic: InfraMetricModelCreator = ( +export const containerNetworkTraffic: TSVBMetricModelCreator = ( timeField, indexPattern, interval -) => ({ - id: InfraMetric.containerNetworkTraffic, +): TSVBMetricModel => ({ + id: 'containerNetworkTraffic', requires: ['docker.network'], index_pattern: indexPattern, interval, @@ -26,7 +25,7 @@ export const containerNetworkTraffic: InfraMetricModelCreator = ( { field: 'docker.network.out.bytes', id: 'avg-network-out', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -37,12 +36,12 @@ export const containerNetworkTraffic: InfraMetricModelCreator = ( { field: 'docker.network.in.bytes', id: 'avg-network-in', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'invert-posonly-deriv-max-network-in', script: 'params.rate * -1', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'avg-network-in', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_overview.ts b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_overview.ts similarity index 69% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_overview.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_overview.ts index 5e33f23a6983d..7facd082718b1 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/container/container_overview.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/container/metrics/tsvb/container_overview.ts @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModelCreator, InfraMetricModelMetricType } from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const containerOverview: InfraMetricModelCreator = (timeField, indexPattern, interval) => ({ - id: InfraMetric.containerOverview, +export const containerOverview: TSVBMetricModelCreator = ( + timeField, + indexPattern, + interval +): TSVBMetricModel => ({ + id: 'containerOverview', requires: ['docker'], index_pattern: indexPattern, interval, @@ -22,7 +25,7 @@ export const containerOverview: InfraMetricModelCreator = (timeField, indexPatte { field: 'docker.cpu.total.pct', id: 'avg-cpu-total', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -33,7 +36,7 @@ export const containerOverview: InfraMetricModelCreator = (timeField, indexPatte { field: 'docker.memory.usage.pct', id: 'avg-memory', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -44,7 +47,7 @@ export const containerOverview: InfraMetricModelCreator = (timeField, indexPatte { field: 'docker.network.out.bytes', id: 'avg-network-out', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -55,7 +58,7 @@ export const containerOverview: InfraMetricModelCreator = (timeField, indexPatte { field: 'docker.network.in.bytes', id: 'avg-network-in', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/index.ts new file mode 100644 index 0000000000000..e29f5878bfcb3 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { layout } from './layout'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; + +export const host: InventoryModel = { + id: 'host', + requiredModules: ['system'], + layout, + metrics, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/layout.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/layout.ts new file mode 100644 index 0000000000000..2ac12387e26a4 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/layout.ts @@ -0,0 +1,364 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +import { InventoryDetailLayoutCreator } from '../types'; + +import { nginxLayoutCreator } from '../shared/layouts/nginx'; +import { awsLayoutCreator } from '../shared/layouts/aws'; + +export const layout: InventoryDetailLayoutCreator = theme => [ + { + id: 'hostOverview', + label: i18n.translate('xpack.infra.metricDetailPage.hostMetricsLayout.layoutLabel', { + defaultMessage: 'Host', + }), + sections: [ + { + id: 'hostSystemOverview', + linkToId: 'hostOverview', + label: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.sectionLabel', + { + defaultMessage: 'Overview', + } + ), + requires: ['system.cpu', 'system.load', 'system.memory', 'system.network'], + type: 'gauges', + visConfig: { + seriesOverrides: { + cpu: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.cpuUsageSeriesLabel', + { + defaultMessage: 'CPU Usage', + } + ), + color: theme.eui.euiColorFullShade, + formatter: 'percent', + gaugeMax: 1, + }, + load: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.loadSeriesLabel', + { + defaultMessage: 'Load (5m)', + } + ), + color: theme.eui.euiColorFullShade, + }, + memory: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.memoryCapacitySeriesLabel', + { + defaultMessage: 'Memory Usage', + } + ), + color: theme.eui.euiColorFullShade, + formatter: 'percent', + gaugeMax: 1, + }, + rx: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.inboundRXSeriesLabel', + { + defaultMessage: 'Inbound (RX)', + } + ), + color: theme.eui.euiColorFullShade, + formatter: 'bits', + formatterTemplate: '{{value}}/s', + }, + tx: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.outboundTXSeriesLabel', + { + defaultMessage: 'Outbound (TX)', + } + ), + color: theme.eui.euiColorFullShade, + formatter: 'bits', + formatterTemplate: '{{value}}/s', + }, + }, + }, + }, + { + id: 'hostCpuUsage', + label: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.sectionLabel', + { + defaultMessage: 'CPU Usage', + } + ), + requires: ['system.cpu'], + type: 'chart', + visConfig: { + stacked: true, + type: 'area', + formatter: 'percent', + seriesOverrides: { + user: { color: theme.eui.euiColorVis0 }, + system: { color: theme.eui.euiColorVis2 }, + steal: { color: theme.eui.euiColorVis9 }, + irq: { color: theme.eui.euiColorVis4 }, + softirq: { color: theme.eui.euiColorVis6 }, + iowait: { color: theme.eui.euiColorVis7 }, + nice: { color: theme.eui.euiColorVis5 }, + }, + }, + }, + { + id: 'hostLoad', + label: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.sectionLabel', + { + defaultMessage: 'Load', + } + ), + requires: ['system.load'], + type: 'chart', + visConfig: { + seriesOverrides: { + load_1m: { + color: theme.eui.euiColorVis0, + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.oneMinuteSeriesLabel', + { + defaultMessage: '1m', + } + ), + }, + load_5m: { + color: theme.eui.euiColorVis1, + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.fiveMinuteSeriesLabel', + { + defaultMessage: '5m', + } + ), + }, + load_15m: { + color: theme.eui.euiColorVis3, + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.fifteenMinuteSeriesLabel', + { + defaultMessage: '15m', + } + ), + }, + }, + }, + }, + { + id: 'hostMemoryUsage', + label: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.memoryUsageSection.sectionLabel', + { + defaultMessage: 'Memory Usage', + } + ), + requires: ['system.memory'], + type: 'chart', + visConfig: { + stacked: true, + formatter: 'bytes', + type: 'area', + seriesOverrides: { + used: { color: theme.eui.euiColorVis2 }, + free: { color: theme.eui.euiColorVis0 }, + cache: { color: theme.eui.euiColorVis1 }, + }, + }, + }, + { + id: 'hostNetworkTraffic', + label: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.networkTrafficSection.sectionLabel', + { + defaultMessage: 'Network Traffic', + } + ), + requires: ['system.network'], + type: 'chart', + visConfig: { + formatter: 'bits', + formatterTemplate: '{{value}}/s', + type: 'area', + seriesOverrides: { + rx: { + color: theme.eui.euiColorVis1, + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.networkTrafficSection.networkRxRateSeriesLabel', + { + defaultMessage: 'in', + } + ), + }, + tx: { + color: theme.eui.euiColorVis2, + name: i18n.translate( + 'xpack.infra.metricDetailPage.hostMetricsLayout.networkTrafficSection.networkTxRateSeriesLabel', + { + defaultMessage: 'out', + } + ), + }, + }, + }, + }, + ], + }, + { + id: 'k8sOverview', + label: 'Kubernetes', + sections: [ + { + id: 'hostK8sOverview', + linkToId: 'k8sOverview', + label: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.sectionLabel', + { + defaultMessage: 'Overview', + } + ), + requires: ['kubernetes.node'], + type: 'gauges', + visConfig: { + seriesOverrides: { + cpucap: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.cpuUsageSeriesLabel', + { + defaultMessage: 'CPU Capacity', + } + ), + color: 'secondary', + formatter: 'percent', + gaugeMax: 1, + }, + load: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.loadSeriesLabel', + { + defaultMessage: 'Load (5m)', + } + ), + color: 'secondary', + }, + memorycap: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.memoryUsageSeriesLabel', + { + defaultMessage: 'Memory Capacity', + } + ), + color: 'secondary', + formatter: 'percent', + gaugeMax: 1, + }, + podcap: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.podCapacitySeriesLabel', + { + defaultMessage: 'Pod Capacity', + } + ), + color: 'secondary', + formatter: 'percent', + gaugeMax: 1, + }, + diskcap: { + name: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.diskCapacitySeriesLabel', + { + defaultMessage: 'Disk Capacity', + } + ), + color: 'secondary', + formatter: 'percent', + gaugeMax: 1, + }, + }, + }, + }, + { + id: 'hostK8sCpuCap', + label: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeCpuCapacitySection.sectionLabel', + { + defaultMessage: 'Node CPU Capacity', + } + ), + requires: ['kubernetes.node'], + type: 'chart', + visConfig: { + formatter: 'abbreviatedNumber', + seriesOverrides: { + capacity: { color: theme.eui.euiColorVis2 }, + used: { color: theme.eui.euiColorVis1, type: 'area' }, + }, + }, + }, + { + id: 'hostK8sMemoryCap', + label: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeMemoryCapacitySection.sectionLabel', + { + defaultMessage: 'Node Memory Capacity', + } + ), + requires: ['kubernetes.node'], + type: 'chart', + visConfig: { + formatter: 'bytes', + seriesOverrides: { + capacity: { color: theme.eui.euiColorVis2 }, + used: { color: theme.eui.euiColorVis1, type: 'area' }, + }, + }, + }, + { + id: 'hostK8sDiskCap', + label: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeDiskCapacitySection.sectionLabel', + { + defaultMessage: 'Node Disk Capacity', + } + ), + requires: ['kubernetes.node'], + type: 'chart', + visConfig: { + formatter: 'bytes', + seriesOverrides: { + capacity: { color: theme.eui.euiColorVis2 }, + used: { color: theme.eui.euiColorVis1, type: 'area' }, + }, + }, + }, + { + id: 'hostK8sPodCap', + label: i18n.translate( + 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodePodCapacitySection.sectionLabel', + { + defaultMessage: 'Node Pod Capacity', + } + ), + requires: ['kubernetes.node'], + type: 'chart', + visConfig: { + formatter: 'number', + seriesOverrides: { + capacity: { color: theme.eui.euiColorVis2 }, + used: { color: theme.eui.euiColorVis1, type: 'area' }, + }, + }, + }, + ], + }, + ...nginxLayoutCreator(theme), + ...awsLayoutCreator(theme), +]; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/index.ts new file mode 100644 index 0000000000000..d1fd3a307ae36 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/index.ts @@ -0,0 +1,54 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { cpu } from './snapshot/cpu'; +import { count } from '../../shared/metrics/snapshot/count'; +import { load } from './snapshot/load'; +import { logRate } from './snapshot/log_rate'; +import { memory } from './snapshot/memory'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; + +import { hostSystemOverview } from './tsvb/host_system_overview'; +import { hostCpuUsage } from './tsvb/host_cpu_usage'; +import { hostLoad } from './tsvb/host_load'; +import { hostMemoryUsage } from './tsvb/host_memory_usage'; +import { hostNetworkTraffic } from './tsvb/host_network_traffic'; +import { hostFilesystem } from './tsvb/host_filesystem'; + +import { hostK8sOverview } from './tsvb/host_k8s_overview'; +import { hostK8sCpuCap } from './tsvb/host_k8s_cpu_cap'; +import { hostK8sPodCap } from './tsvb/host_k8s_pod_cap'; +import { hostK8sDiskCap } from './tsvb/host_k8s_disk_cap'; +import { hostK8sMemoryCap } from './tsvb/host_k8s_memory_cap'; + +import { hostDockerTop5ByMemory } from './tsvb/host_docker_top_5_by_memory'; +import { hostDockerTop5ByCpu } from './tsvb/host_docker_top_5_by_cpu'; +import { hostDockerOverview } from './tsvb/host_docker_overview'; +import { hostDockerInfo } from './tsvb/host_docker_info'; + +import { InventoryMetrics } from '../../types'; + +export const metrics: InventoryMetrics = { + tsvb: { + hostSystemOverview, + hostCpuUsage, + hostLoad, + hostMemoryUsage, + hostNetworkTraffic, + hostFilesystem, + hostK8sOverview, + hostK8sCpuCap, + hostK8sPodCap, + hostK8sDiskCap, + hostK8sMemoryCap, + hostDockerOverview, + hostDockerInfo, + hostDockerTop5ByMemory, + hostDockerTop5ByCpu, + }, + snapshot: { count, cpu, load, logRate, memory, rx, tx }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..fa43acb8d6108 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/cpu.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu_user: { + avg: { + field: 'system.cpu.user.pct', + }, + }, + cpu_system: { + avg: { + field: 'system.cpu.system.pct', + }, + }, + cpu_cores: { + max: { + field: 'system.cpu.cores', + }, + }, + cpu: { + bucket_script: { + buckets_path: { + user: 'cpu_user', + system: 'cpu_system', + cores: 'cpu_cores', + }, + script: { + source: '(params.user + params.system) / params.cores', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/load.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/load.ts new file mode 100644 index 0000000000000..803fb2664ad27 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/load.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const load: SnapshotModel = { load: { avg: { field: 'system.load.5' } } }; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/log_rate.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/log_rate.ts new file mode 100644 index 0000000000000..658111bd07676 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/log_rate.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const logRate: SnapshotModel = { + count: { + bucket_script: { + buckets_path: { count: '_count' }, + script: { + source: 'count * 1', + lang: 'expression', + }, + gap_policy: 'skip', + }, + }, + cumsum: { + cumulative_sum: { + buckets_path: 'count', + }, + }, + logRate: { + derivative: { + buckets_path: 'cumsum', + gap_policy: 'skip', + unit: '1s', + }, + }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/memory.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/memory.ts new file mode 100644 index 0000000000000..cb08a9eaebb3b --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/memory.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const memory: SnapshotModel = { + memory: { avg: { field: 'system.memory.actual.used.pct' } }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/rx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..602169339101e --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/rx.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const rx = networkTrafficWithInterfaces( + 'rx', + 'system.network.in.bytes', + 'system.network.name' +); diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/tx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..4042a7ab7b66e --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/snapshot/tx.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { networkTrafficWithInterfaces } from '../../../shared/metrics/snapshot/network_traffic_with_interfaces'; +export const tx = networkTrafficWithInterfaces( + 'tx', + 'system.network.out.bytes', + 'system.network.name' +); diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_cpu_usage.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_cpu_usage.ts similarity index 78% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_cpu_usage.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_cpu_usage.ts index 4988ee6b1ba0b..c7db1f9e7394c 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_cpu_usage.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_cpu_usage.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostCpuUsage: InfraMetricModelCreator = ( +export const hostCpuUsage: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostCpuUsage, +): TSVBMetricModel => ({ + id: 'hostCpuUsage', requires: ['system.cpu'], index_pattern: indexPattern, interval, @@ -29,17 +24,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.user.pct', id: 'avg-cpu-user', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cores', @@ -62,17 +57,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.system.pct', id: 'avg-cpu-system', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cores', @@ -95,17 +90,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.steal.pct', id: 'avg-cpu-steal', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'avg-cpu-steal', @@ -128,17 +123,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.irq.pct', id: 'avg-cpu-irq', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cores', @@ -161,17 +156,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.softirq.pct', id: 'avg-cpu-softirq', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cores', @@ -194,17 +189,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.iowait.pct', id: 'avg-cpu-iowait', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cores', @@ -227,17 +222,17 @@ export const hostCpuUsage: InfraMetricModelCreator = ( { field: 'system.cpu.nice.pct', id: 'avg-cpu-nice', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-avg-cores', script: 'params.avg / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cores', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_info.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_info.ts similarity index 69% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_info.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_info.ts index dd8e1ea7232c9..9c55eaa932d33 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_info.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_info.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostDockerInfo: InfraMetricModelCreator = ( +export const hostDockerInfo: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostDockerInfo, +): TSVBMetricModel => ({ + id: 'hostDockerInfo', requires: ['docker.info'], index_pattern: indexPattern, interval, @@ -29,7 +24,7 @@ export const hostDockerInfo: InfraMetricModelCreator = ( { field: 'docker.info.containers.running', id: 'max-running', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -40,7 +35,7 @@ export const hostDockerInfo: InfraMetricModelCreator = ( { field: 'docker.info.containers.paused', id: 'max-paused', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -51,7 +46,7 @@ export const hostDockerInfo: InfraMetricModelCreator = ( { field: 'docker.info.containers.stopped', id: 'max-stopped', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_overview.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_overview.ts similarity index 70% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_overview.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_overview.ts index b2b37ddebb547..d7026d7648d37 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_overview.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_overview.ts @@ -3,20 +3,14 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; - -export const hostDockerOverview: InfraMetricModelCreator = ( +export const hostDockerOverview: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostDockerOverview, +): TSVBMetricModel => ({ + id: 'hostDockerOverview', requires: ['docker.info'], index_pattern: indexPattern, interval, @@ -29,7 +23,7 @@ export const hostDockerOverview: InfraMetricModelCreator = ( { field: 'docker.info.containers.total', id: 'max-total', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -40,7 +34,7 @@ export const hostDockerOverview: InfraMetricModelCreator = ( { field: 'docker.info.containers.running', id: 'max-running', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -51,7 +45,7 @@ export const hostDockerOverview: InfraMetricModelCreator = ( { field: 'docker.info.containers.paused', id: 'max-paused', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -62,7 +56,7 @@ export const hostDockerOverview: InfraMetricModelCreator = ( { field: 'docker.info.containers.stopped', id: 'max-stopped', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_top_5_by_cpu.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_cpu.ts similarity index 66% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_top_5_by_cpu.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_cpu.ts index de2ea2e8d7d6f..a4f8bcd426edd 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_top_5_by_cpu.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_cpu.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostDockerTop5ByCpu: InfraMetricModelCreator = ( +export const hostDockerTop5ByCpu: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostDockerTop5ByCpu, +): TSVBMetricModel => ({ + id: 'hostDockerTop5ByCpu', requires: ['docker.cpu'], index_pattern: indexPattern, interval, @@ -29,7 +24,7 @@ export const hostDockerTop5ByCpu: InfraMetricModelCreator = ( { field: 'docker.cpu.total.pct', id: 'avg-cpu-metric', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'terms', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_top_5_by_memory.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_memory.ts similarity index 66% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_top_5_by_memory.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_memory.ts index 0cd863c95cac1..4441b1824e2a2 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_docker_top_5_by_memory.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_docker_top_5_by_memory.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostDockerTop5ByMemory: InfraMetricModelCreator = ( +export const hostDockerTop5ByMemory: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostDockerTop5ByMemory, +): TSVBMetricModel => ({ + id: 'hostDockerTop5ByMemory', requires: ['docker.memory'], index_pattern: indexPattern, interval, @@ -29,7 +24,7 @@ export const hostDockerTop5ByMemory: InfraMetricModelCreator = ( { field: 'docker.memory.usage.pct', id: 'avg-memory-metric', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'terms', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_filesystem.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_filesystem.ts similarity index 69% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_filesystem.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_filesystem.ts index 7377c830b21b1..850674ce89c75 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_filesystem.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_filesystem.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostFilesystem: InfraMetricModelCreator = ( +export const hostFilesystem: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostFilesystem, +): TSVBMetricModel => ({ + id: 'hostFilesystem', requires: ['system.filesystem'], filter: 'system.filesystem.device_name:\\/*', index_pattern: indexPattern, @@ -30,7 +25,7 @@ export const hostFilesystem: InfraMetricModelCreator = ( { field: 'system.filesystem.used.pct', id: 'avg-filesystem-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'terms', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_cpu_cap.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_cpu_cap.ts similarity index 71% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_cpu_cap.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_cpu_cap.ts index d671148a9c210..97e2bc8f09196 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_cpu_cap.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_cpu_cap.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sCpuCap: InfraMetricModelCreator = ( +export const hostK8sCpuCap: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostK8sCpuCap, +): TSVBMetricModel => ({ + id: 'hostK8sCpuCap', map_field_to: 'kubernetes.node.name', requires: ['kubernetes.node'], index_pattern: indexPattern, @@ -30,11 +25,11 @@ export const hostK8sCpuCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.cpu.allocatable.cores', id: 'max-cpu-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-nanocores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { id: 'var-cores', @@ -53,7 +48,7 @@ export const hostK8sCpuCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.cpu.usage.nanocores', id: 'avg-cpu-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_disk_cap.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_disk_cap.ts similarity index 68% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_disk_cap.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_disk_cap.ts index 5c64809192dd7..8ac4c70d06fed 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_disk_cap.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_disk_cap.ts @@ -4,19 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; - -export const hostK8sDiskCap: InfraMetricModelCreator = ( +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; +export const hostK8sDiskCap: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostK8sDiskCap, +): TSVBMetricModel => ({ + id: 'hostK8sDiskCap', map_field_to: 'kubernetes.node.name', requires: ['kubernetes.node'], index_pattern: indexPattern, @@ -30,7 +24,7 @@ export const hostK8sDiskCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.fs.capacity.bytes', id: 'max-fs-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -41,7 +35,7 @@ export const hostK8sDiskCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.fs.used.bytes', id: 'avg-fs-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_memory_cap.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_memory_cap.ts similarity index 68% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_memory_cap.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_memory_cap.ts index 9977a97db043c..6bf76b59dd60a 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_memory_cap.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_memory_cap.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sMemoryCap: InfraMetricModelCreator = ( +export const hostK8sMemoryCap: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostK8sMemoryCap, +): TSVBMetricModel => ({ + id: 'hostK8sMemoryCap', map_field_to: 'kubernetes.node.name', requires: ['kubernetes.node'], index_pattern: indexPattern, @@ -30,7 +25,7 @@ export const hostK8sMemoryCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.memory.allocatable.bytes', id: 'max-memory-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -41,7 +36,7 @@ export const hostK8sMemoryCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.memory.usage.bytes', id: 'avg-memory-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_overview.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_overview.ts similarity index 77% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_overview.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_overview.ts index 9930c3f046066..86d615231f070 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_overview.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_overview.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sOverview: InfraMetricModelCreator = ( +export const hostK8sOverview: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostK8sOverview, +): TSVBMetricModel => ({ + id: 'hostK8sOverview', requires: ['kubernetes'], index_pattern: indexPattern, interval, @@ -30,17 +25,17 @@ export const hostK8sOverview: InfraMetricModelCreator = ( { field: 'kubernetes.node.cpu.allocatable.cores', id: 'max-cpu-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'kubernetes.node.cpu.usage.nanocores', id: 'avg-cpu-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'calc-used-cap', script: 'params.used / (params.cap * 1000000000)', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-cpu-cap', @@ -62,17 +57,17 @@ export const hostK8sOverview: InfraMetricModelCreator = ( { field: 'kubernetes.node.fs.capacity.bytes', id: 'max-fs-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'kubernetes.node.fs.used.bytes', id: 'avg-fs-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'calc-used-cap', script: 'params.used / params.cap', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-fs-cap', @@ -95,17 +90,17 @@ export const hostK8sOverview: InfraMetricModelCreator = ( { field: 'kubernetes.node.memory.allocatable.bytes', id: 'max-memory-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'kubernetes.node.memory.usage.bytes', id: 'avg-memory-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'calc-used-cap', script: 'params.used / params.cap', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-memory-cap', @@ -128,17 +123,17 @@ export const hostK8sOverview: InfraMetricModelCreator = ( { field: 'kubernetes.node.pod.capacity.total', id: 'max-pod-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'kubernetes.pod.uid', id: 'card-pod-name', - type: InfraMetricModelMetricType.cardinality, + type: 'cardinality', }, { id: 'calc-used-cap', script: 'params.used / params.cap', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'max-pod-cap', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_pod_cap.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_pod_cap.ts similarity index 68% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_pod_cap.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_pod_cap.ts index 3efd57a77e97d..e4c844f954599 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_k8s_pod_cap.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_k8s_pod_cap.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostK8sPodCap: InfraMetricModelCreator = ( +export const hostK8sPodCap: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostK8sPodCap, +): TSVBMetricModel => ({ + id: 'hostK8sPodCap', requires: ['kubernetes.node'], map_field_to: 'kubernetes.node.name', index_pattern: indexPattern, @@ -31,7 +26,7 @@ export const hostK8sPodCap: InfraMetricModelCreator = ( { field: 'kubernetes.node.pod.allocatable.total', id: 'max-pod-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], split_mode: 'everything', @@ -42,7 +37,7 @@ export const hostK8sPodCap: InfraMetricModelCreator = ( { field: 'kubernetes.pod.uid', id: 'avg-pod', - type: InfraMetricModelMetricType.cardinality, + type: 'cardinality', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_load.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_load.ts similarity index 69% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_load.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_load.ts index 587998e73b93d..dcee609e7acd7 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_load.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_load.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostLoad: InfraMetricModelCreator = ( +export const hostLoad: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostLoad, +): TSVBMetricModel => ({ + id: 'hostLoad', requires: ['system.cpu'], index_pattern: indexPattern, interval, @@ -29,7 +24,7 @@ export const hostLoad: InfraMetricModelCreator = ( { field: 'system.load.1', id: 'avg-load-1m', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', @@ -40,7 +35,7 @@ export const hostLoad: InfraMetricModelCreator = ( { field: 'system.load.5', id: 'avg-load-5m', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', @@ -51,7 +46,7 @@ export const hostLoad: InfraMetricModelCreator = ( { field: 'system.load.15', id: 'avg-load-15m', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_memory_usage.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_memory_usage.ts similarity index 73% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_memory_usage.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_memory_usage.ts index cf1d64f51ffb3..ef0f7b44912c7 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_memory_usage.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_memory_usage.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostMemoryUsage: InfraMetricModelCreator = ( +export const hostMemoryUsage: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostMemoryUsage, +): TSVBMetricModel => ({ + id: 'hostMemoryUsage', requires: ['system.memory'], index_pattern: indexPattern, interval, @@ -29,7 +24,7 @@ export const hostMemoryUsage: InfraMetricModelCreator = ( { field: 'system.memory.free', id: 'avg-memory-free', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', @@ -40,7 +35,7 @@ export const hostMemoryUsage: InfraMetricModelCreator = ( { field: 'system.memory.actual.used.bytes', id: 'avg-memory-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', @@ -51,17 +46,17 @@ export const hostMemoryUsage: InfraMetricModelCreator = ( { field: 'system.memory.actual.used.bytes', id: 'avg-memory-actual-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.memory.used.bytes', id: 'avg-memory-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'calc-used-actual', script: 'params.used - params.actual', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'avg-memory-actual-used', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_network_traffic.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_network_traffic.ts similarity index 70% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_network_traffic.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_network_traffic.ts index 15edff3f11011..94eb03111e855 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_network_traffic.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_network_traffic.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostNetworkTraffic: InfraMetricModelCreator = ( +export const hostNetworkTraffic: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostNetworkTraffic, +): TSVBMetricModel => ({ + id: 'hostNetworkTraffic', requires: ['system.network'], index_pattern: indexPattern, interval, @@ -29,24 +24,24 @@ export const hostNetworkTraffic: InfraMetricModelCreator = ( { field: 'system.network.out.bytes', id: 'max-net-out', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-net-out', id: 'deriv-max-net-out', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-net-out', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-out' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { function: 'sum', id: 'seriesagg-sum', - type: InfraMetricModelMetricType.series_agg, + type: 'series_agg', }, ], split_mode: 'terms', @@ -58,24 +53,24 @@ export const hostNetworkTraffic: InfraMetricModelCreator = ( { field: 'system.network.in.bytes', id: 'max-net-in', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-net-in', id: 'deriv-max-net-in', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-net-in', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-in' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { id: 'calc-invert-rate', script: 'params.rate * -1', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'posonly-deriv-max-net-in', @@ -87,7 +82,7 @@ export const hostNetworkTraffic: InfraMetricModelCreator = ( { function: 'sum', id: 'seriesagg-sum', - type: InfraMetricModelMetricType.series_agg, + type: 'series_agg', }, ], split_mode: 'terms', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_system_overview.ts b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_system_overview.ts similarity index 74% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_system_overview.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_system_overview.ts index 1caa78fb5da88..953c14ab2a9ce 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/host/host_system_overview.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/host/metrics/tsvb/host_system_overview.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const hostSystemOverview: InfraMetricModelCreator = ( +export const hostSystemOverview: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.hostSystemOverview, +): TSVBMetricModel => ({ + id: 'hostSystemOverview', requires: ['system.cpu', 'system.memory', 'system.load', 'system.network'], index_pattern: indexPattern, interval, @@ -30,22 +25,22 @@ export const hostSystemOverview: InfraMetricModelCreator = ( { field: 'system.cpu.user.pct', id: 'avg-cpu-user', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'system.cpu.cores', id: 'max-cpu-cores', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'system.cpu.system.pct', id: 'avg-cpu-system', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'calc-user-system-cores', script: '(params.users + params.system) / params.cores', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'avg-cpu-user', @@ -73,7 +68,7 @@ export const hostSystemOverview: InfraMetricModelCreator = ( { field: 'system.load.5', id: 'avg-load-5m', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -84,7 +79,7 @@ export const hostSystemOverview: InfraMetricModelCreator = ( { field: 'system.memory.actual.used.pct', id: 'avg-memory-actual-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -96,24 +91,24 @@ export const hostSystemOverview: InfraMetricModelCreator = ( { field: 'system.network.in.bytes', id: 'max-net-in', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-net-in', id: 'deriv-max-net-in', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-net-in', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-in' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { function: 'sum', id: 'seriesagg-sum', - type: InfraMetricModelMetricType.series_agg, + type: 'series_agg', }, ], }, @@ -125,24 +120,24 @@ export const hostSystemOverview: InfraMetricModelCreator = ( { field: 'system.network.out.bytes', id: 'max-net-out', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-net-out', id: 'deriv-max-net-out', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-net-out', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-net-out' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { function: 'sum', id: 'seriesagg-sum', - type: InfraMetricModelMetricType.series_agg, + type: 'series_agg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/index.ts new file mode 100644 index 0000000000000..ec518cb9cb950 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/index.ts @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +import { host } from './host'; +import { pod } from './pod'; +import { container } from './container'; +import { InventoryItemType } from './types'; +export { metrics } from './metrics'; + +export const inventoryModels = [host, pod, container]; + +export const findInventoryModel = (type: InventoryItemType) => { + const model = inventoryModels.find(m => m.id === type); + if (!model) { + throw new Error( + i18n.translate('xpack.infra.inventoryModels.findInventoryModel.error', { + defaultMessage: "The inventory model you've attempted to find does not exist", + }) + ); + } + return model; +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/intl_strings.ts b/x-pack/legacy/plugins/infra/common/inventory_models/intl_strings.ts new file mode 100644 index 0000000000000..08949ed53eb10 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/intl_strings.ts @@ -0,0 +1,70 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +export const CPUUsage = i18n.translate('xpack.infra.waffle.metricOptions.cpuUsageText', { + defaultMessage: 'CPU usage', +}); + +export const MemoryUsage = i18n.translate('xpack.infra.waffle.metricOptions.memoryUsageText', { + defaultMessage: 'Memory usage', +}); + +export const InboundTraffic = i18n.translate( + 'xpack.infra.waffle.metricOptions.inboundTrafficText', + { + defaultMessage: 'Inbound traffic', + } +); + +export const OutboundTraffic = i18n.translate( + 'xpack.infra.waffle.metricOptions.outboundTrafficText', + { + defaultMessage: 'Outbound traffic', + } +); + +export const LogRate = i18n.translate('xpack.infra.waffle.metricOptions.hostLogRateText', { + defaultMessage: 'Log rate', +}); + +export const Load = i18n.translate('xpack.infra.waffle.metricOptions.loadText', { + defaultMessage: 'Load', +}); + +interface Lookup { + [id: string]: string; +} + +export const fieldToName = (field: string) => { + const LOOKUP: Lookup = { + 'kubernetes.namespace': i18n.translate('xpack.infra.groupByDisplayNames.kubernetesNamespace', { + defaultMessage: 'Namespace', + }), + 'kubernetes.node.name': i18n.translate('xpack.infra.groupByDisplayNames.kubernetesNodeName', { + defaultMessage: 'Node', + }), + 'host.name': i18n.translate('xpack.infra.groupByDisplayNames.hostName', { + defaultMessage: 'Host', + }), + 'cloud.availability_zone': i18n.translate('xpack.infra.groupByDisplayNames.availabilityZone', { + defaultMessage: 'Availability zone', + }), + 'cloud.machine.type': i18n.translate('xpack.infra.groupByDisplayNames.machineType', { + defaultMessage: 'Machine type', + }), + 'cloud.project.id': i18n.translate('xpack.infra.groupByDisplayNames.projectID', { + defaultMessage: 'Project ID', + }), + 'cloud.provider': i18n.translate('xpack.infra.groupByDisplayNames.provider', { + defaultMessage: 'Cloud provider', + }), + 'service.type': i18n.translate('xpack.infra.groupByDisplayNames.serviceType', { + defaultMessage: 'Service type', + }), + }; + return LOOKUP[field] || field; +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/metrics.ts b/x-pack/legacy/plugins/infra/common/inventory_models/metrics.ts new file mode 100644 index 0000000000000..78dc262b29bac --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/metrics.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { metrics as hostMetrics } from './host/metrics'; +import { metrics as sharedMetrics } from './shared/metrics'; +import { metrics as podMetrics } from './pod/metrics'; +import { metrics as containerMetrics } from './container/metrics'; + +export const metrics = { + tsvb: { + ...hostMetrics.tsvb, + ...sharedMetrics.tsvb, + ...podMetrics.tsvb, + ...containerMetrics.tsvb, + }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/pod/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/index.ts new file mode 100644 index 0000000000000..1cf839b787657 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/index.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { layout } from './layout'; +import { metrics } from './metrics'; +import { InventoryModel } from '../types'; +export const pod: InventoryModel = { + id: 'pod', + requiredModules: ['kubernetes'], + layout, + metrics, +}; diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/pod.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/layout.ts similarity index 70% rename from x-pack/legacy/plugins/infra/public/pages/metrics/layouts/pod.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/pod/layout.ts index b0c306f0bdcd0..ffb78894d63f6 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/pod.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/layout.ts @@ -5,16 +5,10 @@ */ import { i18n } from '@kbn/i18n'; -import { InfraMetric } from '../../../graphql/types'; -import { InfraFormatterType } from '../../../lib/lib'; -import { nginxLayoutCreator } from './nginx'; -import { - InfraMetricLayoutCreator, - InfraMetricLayoutSectionType, - InfraMetricLayoutVisualizationType, -} from './types'; +import { InventoryDetailLayoutCreator } from '../types'; +import { nginxLayoutCreator } from '../shared/layouts/nginx'; -export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ +export const layout: InventoryDetailLayoutCreator = theme => [ { id: 'podOverview', label: i18n.translate('xpack.infra.metricDetailPage.podMetricsLayout.layoutLabel', { @@ -22,7 +16,7 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ }), sections: [ { - id: InfraMetric.podOverview, + id: 'podOverview', label: i18n.translate( 'xpack.infra.metricDetailPage.podMetricsLayout.overviewSection.sectionLabel', { @@ -30,7 +24,7 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['kubernetes.pod'], - type: InfraMetricLayoutSectionType.gauges, + type: 'gauges', visConfig: { seriesOverrides: { cpu: { @@ -41,7 +35,7 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, + formatter: 'percent', gaugeMax: 1, }, memory: { @@ -52,7 +46,7 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, + formatter: 'percent', gaugeMax: 1, }, rx: { @@ -63,7 +57,7 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.bits, + formatter: 'bits', formatterTemplate: '{{value}}/s', }, tx: { @@ -74,14 +68,14 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.bits, + formatter: 'bits', formatterTemplate: '{{value}}/s', }, }, }, }, { - id: InfraMetric.podCpuUsage, + id: 'podCpuUsage', label: i18n.translate( 'xpack.infra.metricDetailPage.podMetricsLayout.cpuUsageSection.sectionLabel', { @@ -89,23 +83,16 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['kubernetes.pod'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - formatter: InfraFormatterType.percent, + formatter: 'percent', seriesOverrides: { - cpu: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.podMetricsLayout.cpuUsageSection.seriesLabel.cpu', - { defaultMessage: 'cpu' } - ), - type: InfraMetricLayoutVisualizationType.area, - }, + cpu: { color: theme.eui.euiColorVis1, type: 'area' }, }, }, }, { - id: InfraMetric.podMemoryUsage, + id: 'podMemoryUsage', label: i18n.translate( 'xpack.infra.metricDetailPage.podMetricsLayout.memoryUsageSection.sectionLabel', { @@ -113,23 +100,19 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['kubernetes.pod'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - formatter: InfraFormatterType.percent, + formatter: 'percent', seriesOverrides: { memory: { color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.podMetricsLayout.memoryUsageSection.seriesLabel.memory', - { defaultMessage: 'memory' } - ), - type: InfraMetricLayoutVisualizationType.area, + type: 'area', }, }, }, }, { - id: InfraMetric.podNetworkTraffic, + id: 'podNetworkTraffic', label: i18n.translate( 'xpack.infra.metricDetailPage.podMetricsLayout.networkTrafficSection.sectionLabel', { @@ -137,11 +120,11 @@ export const podLayoutCreator: InfraMetricLayoutCreator = theme => [ } ), requires: ['kubernetes.pod'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - formatter: InfraFormatterType.bits, + formatter: 'bits', formatterTemplate: '{{value}}/s', - type: InfraMetricLayoutVisualizationType.area, + type: 'area', seriesOverrides: { rx: { color: theme.eui.euiColorVis1, diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/index.ts new file mode 100644 index 0000000000000..03aa6d4e039b1 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/index.ts @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { cpu } from './snapshot/cpu'; +import { memory } from './snapshot/memory'; +import { rx } from './snapshot/rx'; +import { tx } from './snapshot/tx'; + +import { podOverview } from './tsvb/pod_overview'; +import { podCpuUsage } from './tsvb/pod_cpu_usage'; +import { podLogUsage } from './tsvb/pod_log_usage'; +import { podMemoryUsage } from './tsvb/pod_memory_usage'; +import { podNetworkTraffic } from './tsvb/pod_network_traffic'; +import { InventoryMetrics } from '../../types'; + +export const metrics: InventoryMetrics = { + tsvb: { + podOverview, + podCpuUsage, + podLogUsage, + podNetworkTraffic, + podMemoryUsage, + }, + snapshot: { cpu, memory, rx, tx }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts new file mode 100644 index 0000000000000..f25dd8179aa1a --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const cpu: SnapshotModel = { + cpu: { + avg: { + field: 'kubernetes.pod.cpu.usage.node.pct', + }, + }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/memory.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/memory.ts new file mode 100644 index 0000000000000..28a71d9b0275a --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/memory.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const memory: SnapshotModel = { + memory: { avg: { field: 'kubernetes.pod.memory.usage.node.pct' } }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/rx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/rx.ts new file mode 100644 index 0000000000000..e9e1b1ddd9b41 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/rx.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { networkTraffic } from '../../../shared/metrics/snapshot/network_traffic'; +export const rx = networkTraffic('rx', 'kubernetes.pod.network.rx.bytes'); diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/tx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/tx.ts new file mode 100644 index 0000000000000..198355ca29ff6 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/snapshot/tx.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { networkTraffic } from '../../../shared/metrics/snapshot/network_traffic'; +export const tx = networkTraffic('tx', 'kubernetes.pod.network.tx.bytes'); diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_cpu_usage.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts similarity index 64% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_cpu_usage.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts index d4c0fce42b51c..1d778d11e0725 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_cpu_usage.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podCpuUsage: InfraMetricModelCreator = ( +export const podCpuUsage: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.podCpuUsage, +): TSVBMetricModel => ({ + id: 'podCpuUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, @@ -30,7 +25,7 @@ export const podCpuUsage: InfraMetricModelCreator = ( { field: 'kubernetes.pod.cpu.usage.node.pct', id: 'avg-cpu-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_log_usage.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_log_usage.ts similarity index 71% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_log_usage.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_log_usage.ts index b1f184672fa73..d960322a477aa 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_log_usage.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_log_usage.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podLogUsage: InfraMetricModelCreator = ( +export const podLogUsage: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.podLogUsage, +): TSVBMetricModel => ({ + id: 'podLogUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, @@ -30,17 +25,17 @@ export const podLogUsage: InfraMetricModelCreator = ( { field: 'kubernetes.container.logs.used.bytes', id: 'avg-log-used', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { field: 'kubernetes.container.logs.capacity.bytes', id: 'max-log-cap', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'calc-usage-limit', script: 'params.usage / params.limit', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'avg-log-userd', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_memory_usage.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_memory_usage.ts similarity index 64% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_memory_usage.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_memory_usage.ts index 720e11b2b6068..8dd63787c605a 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_memory_usage.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_memory_usage.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podMemoryUsage: InfraMetricModelCreator = ( +export const podMemoryUsage: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.podMemoryUsage, +): TSVBMetricModel => ({ + id: 'podMemoryUsage', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, @@ -30,7 +25,7 @@ export const podMemoryUsage: InfraMetricModelCreator = ( { field: 'kubernetes.pod.memory.usage.node.pct', id: 'avg-memory-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_network_traffic.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_network_traffic.ts similarity index 72% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_network_traffic.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_network_traffic.ts index 9547fe75e6bbc..139e592609ae1 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_network_traffic.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_network_traffic.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podNetworkTraffic: InfraMetricModelCreator = ( +export const podNetworkTraffic: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.podNetworkTraffic, +): TSVBMetricModel => ({ + id: 'podNetworkTraffic', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, @@ -30,17 +25,17 @@ export const podNetworkTraffic: InfraMetricModelCreator = ( { field: 'kubernetes.pod.network.tx.bytes', id: 'max-network-tx', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-network-tx', id: 'deriv-max-network-tx', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-net-tx', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-tx' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, @@ -53,24 +48,24 @@ export const podNetworkTraffic: InfraMetricModelCreator = ( { field: 'kubernetes.pod.network.rx.bytes', id: 'max-network-rx', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-network-rx', id: 'deriv-max-network-rx', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-net-tx', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-tx' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, { id: 'invert-posonly-deriv-max-network-rx', script: 'params.rate * -1', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { field: 'posonly-deriv-max-network-rx', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_overview.ts b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_overview.ts similarity index 72% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_overview.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_overview.ts index bcdfa350f6aeb..129cbd96eb2ce 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/pod/pod_overview.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_overview.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const podOverview: InfraMetricModelCreator = ( +export const podOverview: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.podOverview, +): TSVBMetricModel => ({ + id: 'podOverview', requires: ['kubernetes.pod'], index_pattern: indexPattern, interval, @@ -30,7 +25,7 @@ export const podOverview: InfraMetricModelCreator = ( { field: 'kubernetes.pod.cpu.usage.node.pct', id: 'avg-cpu-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -41,7 +36,7 @@ export const podOverview: InfraMetricModelCreator = ( { field: 'kubernetes.pod.memory.usage.node.pct', id: 'avg-memory-usage', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -52,17 +47,17 @@ export const podOverview: InfraMetricModelCreator = ( { field: 'kubernetes.pod.network.rx.bytes', id: 'max-network-rx', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-network-rx', id: 'deriv-max-network-rx', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-network-rx', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-rx' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, @@ -75,17 +70,17 @@ export const podOverview: InfraMetricModelCreator = ( { field: 'kubernetes.pod.network.tx.bytes', id: 'max-network-tx', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-network-tx', id: 'deriv-max-network-tx', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-deriv-max-network-tx', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'deriv-max-network-tx' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/aws.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/layouts/aws.ts similarity index 80% rename from x-pack/legacy/plugins/infra/public/pages/metrics/layouts/aws.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/layouts/aws.ts index 75a77e9d62a08..7c7c009df6f27 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/aws.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/layouts/aws.ts @@ -5,22 +5,15 @@ */ import { i18n } from '@kbn/i18n'; -import { InfraMetric } from '../../../graphql/types'; -import { InfraFormatterType } from '../../../lib/lib'; -import { - InfraMetricLayoutSectionType, - InfraMetricLayoutVisualizationType, - InfraMetricLayout, -} from './types'; -import { EuiTheme } from '../../../../../../common/eui_styled_components'; +import { InventoryDetailLayoutCreator } from '../../types'; -export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ +export const awsLayoutCreator: InventoryDetailLayoutCreator = theme => [ { id: 'awsOverview', label: 'AWS', sections: [ { - id: InfraMetric.awsOverview, + id: 'awsOverview', linkToId: 'awsOverview', label: i18n.translate( 'xpack.infra.metricDetailPage.awsMetricsLayout.overviewSection.sectionLabel', @@ -29,7 +22,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), requires: ['aws.ec2'], - type: InfraMetricLayoutSectionType.gauges, + type: 'gauges', visConfig: { seriesOverrides: { 'cpu-util': { @@ -40,7 +33,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, + formatter: 'percent', gaugeMax: 1, }, 'status-check-failed': { @@ -60,7 +53,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.number, + formatter: 'number', }, 'packets-out': { name: i18n.translate( @@ -70,13 +63,13 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.number, + formatter: 'number', }, }, }, }, { - id: InfraMetric.awsCpuUtilization, + id: 'awsCpuUtilization', label: i18n.translate( 'xpack.infra.metricDetailPage.awsMetricsLayout.cpuUtilSection.sectionLabel', { @@ -84,10 +77,10 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), requires: ['aws.ec2'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.number, + type: 'area', + formatter: 'number', seriesOverrides: { 'cpu-util': { color: theme.eui.euiColorVis1, @@ -102,7 +95,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ }, }, { - id: InfraMetric.awsNetworkBytes, + id: 'awsNetworkBytes', label: i18n.translate( 'xpack.infra.metricDetailPage.awsMetricsLayout.networkBytesSection.sectionLabel', { @@ -110,10 +103,10 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), requires: ['aws.ec2'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.bits, + type: 'area', + formatter: 'bits', formatterTemplate: '{{value}}/s', seriesOverrides: { tx: { @@ -138,7 +131,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ }, }, { - id: InfraMetric.awsNetworkPackets, + id: 'awsNetworkPackets', label: i18n.translate( 'xpack.infra.metricDetailPage.awsMetricsLayout.networkPacketsSection.sectionLabel', { @@ -146,10 +139,10 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), requires: ['aws.ec2'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.number, + type: 'area', + formatter: 'number', seriesOverrides: { 'packets-out': { color: theme.eui.euiColorVis1, @@ -173,7 +166,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ }, }, { - id: InfraMetric.awsDiskioOps, + id: 'awsDiskioOps', label: i18n.translate( 'xpack.infra.metricDetailPage.awsMetricsLayout.diskioOperationsSection.sectionLabel', { @@ -181,10 +174,10 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), requires: ['aws.ec2'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.number, + type: 'area', + formatter: 'number', seriesOverrides: { writes: { color: theme.eui.euiColorVis1, @@ -208,7 +201,7 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ }, }, { - id: InfraMetric.awsDiskioBytes, + id: 'awsDiskioBytes', label: i18n.translate( 'xpack.infra.metricDetailPage.awsMetricsLayout.diskioBytesSection.sectionLabel', { @@ -216,10 +209,10 @@ export const awsLayoutCreator = (theme: EuiTheme): InfraMetricLayout[] => [ } ), requires: ['aws.ec2'], - type: InfraMetricLayoutSectionType.chart, + type: 'chart', visConfig: { - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.number, + type: 'area', + formatter: 'number', seriesOverrides: { writes: { color: theme.eui.euiColorVis1, diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/shared/layouts/nginx.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/layouts/nginx.ts new file mode 100644 index 0000000000000..2d895c3b83a0b --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/layouts/nginx.ts @@ -0,0 +1,102 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +import { InventoryDetailLayoutCreator } from '../../types'; + +export const nginxLayoutCreator: InventoryDetailLayoutCreator = theme => [ + { + id: 'nginxOverview', + label: 'Nginx', + sections: [ + { + id: 'nginxHits', + label: i18n.translate( + 'xpack.infra.metricDetailPage.nginxMetricsLayout.hitsSection.sectionLabel', + { + defaultMessage: 'Hits', + } + ), + requires: ['nginx.access'], + type: 'chart', + visConfig: { + formatter: 'abbreviatedNumber', + stacked: true, + seriesOverrides: { + '200s': { color: theme.eui.euiColorVis1, type: 'bar' }, + '300s': { color: theme.eui.euiColorVis5, type: 'bar' }, + '400s': { color: theme.eui.euiColorVis2, type: 'bar' }, + '500s': { color: theme.eui.euiColorVis9, type: 'bar' }, + }, + }, + }, + { + id: 'nginxRequestRate', + label: i18n.translate( + 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestRateSection.sectionLabel', + { + defaultMessage: 'Request Rate', + } + ), + requires: ['nginx.stubstatus'], + type: 'chart', + visConfig: { + formatter: 'abbreviatedNumber', + formatterTemplate: '{{value}}/s', + seriesOverrides: { + rate: { color: theme.eui.euiColorVis1, type: 'area' }, + }, + }, + }, + { + id: 'nginxActiveConnections', + label: i18n.translate( + 'xpack.infra.metricDetailPage.nginxMetricsLayout.activeConnectionsSection.sectionLabel', + { + defaultMessage: 'Active Connections', + } + ), + requires: ['nginx.stubstatus'], + type: 'chart', + visConfig: { + formatter: 'abbreviatedNumber', + seriesOverrides: { + connections: { + color: theme.eui.euiColorVis1, + type: 'bar', + }, + }, + }, + }, + { + id: 'nginxRequestsPerConnection', + label: i18n.translate( + 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestsPerConnectionsSection.sectionLabel', + { + defaultMessage: 'Requests per Connections', + } + ), + requires: ['nginx.stubstatus'], + type: 'chart', + visConfig: { + formatter: 'abbreviatedNumber', + seriesOverrides: { + reqPerConns: { + color: theme.eui.euiColorVis1, + type: 'bar', + name: i18n.translate( + 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestsPerConnectionsSection.reqsPerConnSeriesLabel', + { + defaultMessage: 'reqs per conn', + } + ), + }, + }, + }, + }, + ], + }, +]; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/index.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/index.ts new file mode 100644 index 0000000000000..a17ca0e2b09e5 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/index.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { nginxRequestRate } from './tsvb/nginx_request_rate'; +import { nginxActiveConnections } from './tsvb/nginx_active_connections'; +import { nginxHits } from './tsvb/nginx_hits'; +import { nginxRequestsPerConnection } from './tsvb/nginx_requests_per_connection'; + +import { awsCpuUtilization } from './tsvb/aws_cpu_utilization'; +import { awsDiskioBytes } from './tsvb/aws_diskio_bytes'; +import { awsDiskioOps } from './tsvb/aws_diskio_ops'; +import { awsNetworkBytes } from './tsvb/aws_network_bytes'; +import { awsNetworkPackets } from './tsvb/aws_network_packets'; +import { awsOverview } from './tsvb/aws_overview'; +import { InventoryMetrics } from '../../types'; + +export const metrics: InventoryMetrics = { + tsvb: { + nginxActiveConnections, + nginxHits, + nginxRequestRate, + nginxRequestsPerConnection, + awsCpuUtilization, + awsDiskioBytes, + awsDiskioOps, + awsNetworkBytes, + awsNetworkPackets, + awsOverview, + }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/count.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/count.ts new file mode 100644 index 0000000000000..ed8398a5d4a77 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/count.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const count: SnapshotModel = { + count: { + bucket_script: { + buckets_path: { count: '_count' }, + script: { + source: 'count * 1', + lang: 'expression', + }, + gap_policy: 'skip', + }, + }, +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic.ts new file mode 100644 index 0000000000000..37e90a6416ba7 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic.ts @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const networkTraffic = (id: string, field: string): SnapshotModel => { + return { + [`${id}_max`]: { max: { field } }, + [`${id}_deriv`]: { + derivative: { + buckets_path: `${id}_max`, + gap_policy: 'skip', + unit: '1s', + }, + }, + [id]: { + bucket_script: { + buckets_path: { value: `${id}_deriv[normalized_value]` }, + script: { + source: 'params.value > 0.0 ? params.value : 0.0', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, + }; +}; diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic_with_interfaces.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic_with_interfaces.ts new file mode 100644 index 0000000000000..1ba5cf037e708 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/network_traffic_with_interfaces.ts @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SnapshotModel } from '../../../types'; + +export const networkTrafficWithInterfaces = ( + id: string, + metricField: string, + interfaceField: string +): SnapshotModel => ({ + [`${id}_interfaces`]: { + terms: { field: interfaceField }, + aggregations: { + [`${id}_interface_max`]: { max: { field: metricField } }, + }, + }, + [`${id}_sum_of_interfaces`]: { + sum_bucket: { + buckets_path: `${id}_interfaces>${id}_interface_max`, + }, + }, + [`${id}_deriv`]: { + derivative: { + buckets_path: `${id}_sum_of_interfaces`, + gap_policy: 'skip', + unit: '1s', + }, + }, + [id]: { + bucket_script: { + buckets_path: { value: `${id}_deriv[normalized_value]` }, + script: { + source: 'params.value > 0.0 ? params.value : 0.0', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, +}); diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/log_rate.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/rate.ts similarity index 53% rename from x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/log_rate.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/rate.ts index f7f2ac26e3b96..e1c7c7df52628 100644 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/log_rate.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/snapshot/rate.ts @@ -4,28 +4,26 @@ * you may not use this file except in compliance with the Elastic License. */ -export const logRate = () => { +import { SnapshotModel } from '../../../types'; + +export const rate = (id: string, field: string): SnapshotModel => { return { - count: { - bucket_script: { - buckets_path: { count: '_count' }, - script: { - source: 'count * 1', - lang: 'expression', - }, + [`${id}_max`]: { max: { field } }, + [`${id}_deriv`]: { + derivative: { + buckets_path: `${id}_max`, gap_policy: 'skip', + unit: '1s', }, }, - cumsum: { - cumulative_sum: { - buckets_path: 'count', - }, - }, - logRate: { - derivative: { - buckets_path: 'cumsum', + [id]: { + bucket_script: { + buckets_path: { value: `${id}_deriv[normalized_value]` }, + script: { + source: 'params.value > 0.0 ? params.value : 0.0', + lang: 'painless', + }, gap_policy: 'skip', - unit: '1s', }, }, }; diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_cpu_utilization.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_cpu_utilization.ts similarity index 65% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_cpu_utilization.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_cpu_utilization.ts index e3487690e63e6..9092d8f3f5d54 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_cpu_utilization.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_cpu_utilization.ts @@ -4,18 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsCpuUtilization: InfraMetricModelCreator = ( +export const awsCpuUtilization: TSVBMetricModelCreator = ( timeField, indexPattern -): InfraMetricModel => ({ - id: InfraMetric.awsCpuUtilization, +): TSVBMetricModel => ({ + id: 'awsCpuUtilization', requires: ['aws.ec2'], map_field_to: 'cloud.instance.id', id_type: 'cloud', @@ -30,7 +25,7 @@ export const awsCpuUtilization: InfraMetricModelCreator = ( { field: 'aws.ec2.cpu.total.pct', id: 'avg-cpu-util', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_diskio_bytes.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_bytes.ts similarity index 66% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_diskio_bytes.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_bytes.ts index 15077c3c64cf7..8abb6f5d5ddff 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_diskio_bytes.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_bytes.ts @@ -4,21 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -// see discussion in: https://github.com/elastic/kibana/issues/42687 - -export const awsDiskioBytes: InfraMetricModelCreator = ( +export const awsDiskioBytes: TSVBMetricModelCreator = ( timeField, - indexPattern, - interval -): InfraMetricModel => ({ - id: InfraMetric.awsDiskioBytes, + indexPattern +): TSVBMetricModel => ({ + id: 'awsDiskioBytes', requires: ['aws.ec2'], index_pattern: indexPattern, map_field_to: 'cloud.instance.id', @@ -33,23 +25,23 @@ export const awsDiskioBytes: InfraMetricModelCreator = ( { field: 'aws.ec2.diskio.write.bytes', id: 'sum-diskio-out', - type: InfraMetricModelMetricType.sum, + type: 'sum', }, { id: 'csum-sum-diskio-out', field: 'sum-diskio-out', - type: InfraMetricModelMetricType.cumulative_sum, + type: 'cumulative_sum', }, { id: 'deriv-csum-sum-diskio-out', unit: '1s', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', field: 'csum-sum-diskio-out', }, { id: 'posonly-deriv-csum-sum-diskio-out', field: 'deriv-csum-sum-diskio-out', - type: InfraMetricModelMetricType.positive_only, + type: 'positive_only', }, ], split_mode: 'everything', @@ -60,27 +52,27 @@ export const awsDiskioBytes: InfraMetricModelCreator = ( { field: 'aws.ec2.diskio.read.bytes', id: 'sum-diskio-in', - type: InfraMetricModelMetricType.sum, + type: 'sum', }, { id: 'csum-sum-diskio-in', field: 'sum-diskio-in', - type: InfraMetricModelMetricType.cumulative_sum, + type: 'cumulative_sum', }, { id: 'deriv-csum-sum-diskio-in', unit: '1s', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', field: 'csum-sum-diskio-in', }, { id: 'posonly-deriv-csum-sum-diskio-in', field: 'deriv-csum-sum-diskio-in', - type: InfraMetricModelMetricType.positive_only, + type: 'positive_only', }, { id: 'inverted-posonly-deriv-csum-sum-diskio-in', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'posonly-deriv-csum-sum-diskio-in' }], script: 'params.rate * -1', }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_diskio_ops.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts similarity index 66% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_diskio_ops.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts index 3df6124d22a7f..d81438e3b5a61 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_diskio_ops.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_diskio_ops.ts @@ -3,22 +3,10 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; - -// see discussion in: https://github.com/elastic/kibana/issues/42687 - -export const awsDiskioOps: InfraMetricModelCreator = ( - timeField, - indexPattern, - interval -): InfraMetricModel => ({ - id: InfraMetric.awsDiskioOps, +export const awsDiskioOps: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ + id: 'awsDiskioOps', requires: ['aws.ec2'], index_pattern: indexPattern, map_field_to: 'cloud.instance.id', @@ -33,23 +21,23 @@ export const awsDiskioOps: InfraMetricModelCreator = ( { field: 'aws.ec2.diskio.write.count', id: 'sum-diskio-writes', - type: InfraMetricModelMetricType.sum, + type: 'sum', }, { id: 'csum-sum-diskio-writes', field: 'sum-diskio-writes', - type: InfraMetricModelMetricType.cumulative_sum, + type: 'cumulative_sum', }, { id: 'deriv-csum-sum-diskio-writes', unit: '1s', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', field: 'csum-sum-diskio-writes', }, { id: 'posonly-deriv-csum-sum-diskio-writes', field: 'deriv-csum-sum-diskio-writes', - type: InfraMetricModelMetricType.positive_only, + type: 'positive_only', }, ], split_mode: 'everything', @@ -60,27 +48,27 @@ export const awsDiskioOps: InfraMetricModelCreator = ( { field: 'aws.ec2.diskio.read.count', id: 'sum-diskio-reads', - type: InfraMetricModelMetricType.sum, + type: 'sum', }, { id: 'csum-sum-diskio-reads', field: 'sum-diskio-reads', - type: InfraMetricModelMetricType.cumulative_sum, + type: 'cumulative_sum', }, { id: 'deriv-csum-sum-diskio-reads', unit: '1s', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', field: 'csum-sum-diskio-reads', }, { id: 'posonly-deriv-csum-sum-diskio-reads', field: 'deriv-csum-sum-diskio-reads', - type: InfraMetricModelMetricType.positive_only, + type: 'positive_only', }, { id: 'inverted-posonly-deriv-csum-sum-diskio-reads', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { id: 'var-rate', name: 'rate', field: 'posonly-deriv-csum-sum-diskio-reads' }, ], diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_network_bytes.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_bytes.ts similarity index 67% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_network_bytes.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_bytes.ts index 3c9842c4ada8f..bbae45a5b4b8e 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_network_bytes.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_bytes.ts @@ -4,21 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; // see discussion in: https://github.com/elastic/kibana/issues/42687 -export const awsNetworkBytes: InfraMetricModelCreator = ( +export const awsNetworkBytes: TSVBMetricModelCreator = ( timeField, - indexPattern, - interval -): InfraMetricModel => ({ - id: InfraMetric.awsNetworkBytes, + indexPattern +): TSVBMetricModel => ({ + id: 'awsNetworkBytes', requires: ['aws.ec2'], index_pattern: indexPattern, map_field_to: 'cloud.instance.id', @@ -33,23 +27,23 @@ export const awsNetworkBytes: InfraMetricModelCreator = ( { field: 'aws.ec2.network.out.bytes', id: 'sum-net-out', - type: InfraMetricModelMetricType.sum, + type: 'sum', }, { id: 'csum-sum-net-out', field: 'sum-net-out', - type: InfraMetricModelMetricType.cumulative_sum, + type: 'cumulative_sum', }, { id: 'deriv-csum-sum-net-out', unit: '1s', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', field: 'csum-sum-net-out', }, { id: 'posonly-deriv-csum-sum-net-out', field: 'deriv-csum-sum-net-out', - type: InfraMetricModelMetricType.positive_only, + type: 'positive_only', }, ], split_mode: 'everything', @@ -60,27 +54,27 @@ export const awsNetworkBytes: InfraMetricModelCreator = ( { field: 'aws.ec2.network.in.bytes', id: 'sum-net-in', - type: InfraMetricModelMetricType.sum, + type: 'sum', }, { id: 'csum-sum-net-in', field: 'sum-net-in', - type: InfraMetricModelMetricType.cumulative_sum, + type: 'cumulative_sum', }, { id: 'deriv-csum-sum-net-in', unit: '1s', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', field: 'csum-sum-net-in', }, { id: 'posonly-deriv-csum-sum-net-in', field: 'deriv-csum-sum-net-in', - type: InfraMetricModelMetricType.positive_only, + type: 'positive_only', }, { id: 'inverted-posonly-deriv-csum-sum-net-in', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'posonly-deriv-csum-sum-net-in' }], script: 'params.rate * -1', }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_network_packets.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_packets.ts similarity index 67% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_network_packets.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_packets.ts index 8fea9a427bff0..e2e6c4846a412 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_network_packets.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_network_packets.ts @@ -4,19 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsNetworkPackets: InfraMetricModelCreator = ( +export const awsNetworkPackets: TSVBMetricModelCreator = ( timeField, - indexPattern, - interval -): InfraMetricModel => ({ - id: InfraMetric.awsNetworkPackets, + indexPattern +): TSVBMetricModel => ({ + id: 'awsNetworkPackets', requires: ['aws.ec2'], index_pattern: indexPattern, map_field_to: 'cloud.instance.id', @@ -31,7 +25,7 @@ export const awsNetworkPackets: InfraMetricModelCreator = ( { field: 'aws.ec2.network.out.packets', id: 'avg-net-out', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', @@ -42,11 +36,11 @@ export const awsNetworkPackets: InfraMetricModelCreator = ( { field: 'aws.ec2.network.in.packets', id: 'avg-net-in', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, { id: 'inverted-avg-net-in', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-avg', name: 'avg', field: 'avg-net-in' }], script: 'params.avg * -1', }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_overview.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_overview.ts similarity index 70% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_overview.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_overview.ts index c7033e5b30845..5ba61d1f92517 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/aws/aws_overview.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/aws_overview.ts @@ -4,19 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const awsOverview: InfraMetricModelCreator = ( - timeField, - indexPattern, - interval -): InfraMetricModel => ({ - id: InfraMetric.awsOverview, +export const awsOverview: TSVBMetricModelCreator = (timeField, indexPattern): TSVBMetricModel => ({ + id: 'awsOverview', requires: ['aws.ec2'], index_pattern: indexPattern, map_field_to: 'cloud.instance.id', @@ -32,7 +23,7 @@ export const awsOverview: InfraMetricModelCreator = ( { field: 'aws.ec2.cpu.total.pct', id: 'cpu-total-pct', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], }, @@ -43,7 +34,7 @@ export const awsOverview: InfraMetricModelCreator = ( { field: 'aws.ec2.status.check_failed', id: 'status-check-failed', - type: InfraMetricModelMetricType.max, + type: 'max', }, ], }, @@ -54,7 +45,7 @@ export const awsOverview: InfraMetricModelCreator = ( { field: 'aws.ec2.network.out.packets', id: 'network-out-packets', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, @@ -65,7 +56,7 @@ export const awsOverview: InfraMetricModelCreator = ( { field: 'aws.ec2.network.in.packets', id: 'network-in-packets', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_active_connections.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_active_connections.ts similarity index 63% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_active_connections.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_active_connections.ts index 9d8b30c8bf967..61e7fc88496a3 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_active_connections.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_active_connections.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const nginxActiveConnections: InfraMetricModelCreator = ( +export const nginxActiveConnections: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.nginxActiveConnections, +): TSVBMetricModel => ({ + id: 'nginxActiveConnections', requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, @@ -29,7 +24,7 @@ export const nginxActiveConnections: InfraMetricModelCreator = ( { field: 'nginx.stubstatus.active', id: 'avg-active', - type: InfraMetricModelMetricType.avg, + type: 'avg', }, ], split_mode: 'everything', diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_hits.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_hits.ts similarity index 64% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_hits.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_hits.ts index bc7340bd8ac23..546102ec0ad8b 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_hits.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_hits.ts @@ -4,21 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, - InfraMetricModelQueryType, -} from '../../adapter_types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -import { InfraMetric } from '../../../../../graphql/types'; - -export const nginxHits: InfraMetricModelCreator = ( +export const nginxHits: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.nginxHits, +): TSVBMetricModel => ({ + id: 'nginxHits', requires: ['nginx.access'], index_pattern: indexPattern, interval, @@ -30,13 +23,13 @@ export const nginxHits: InfraMetricModelCreator = ( metrics: [ { id: 'count-200', - type: InfraMetricModelMetricType.count, + type: 'count', }, ], split_mode: 'filter', filter: { query: 'http.response.status_code:[200 TO 299]', - language: InfraMetricModelQueryType.lucene, + language: 'lucene', }, }, { @@ -44,13 +37,13 @@ export const nginxHits: InfraMetricModelCreator = ( metrics: [ { id: 'count-300', - type: InfraMetricModelMetricType.count, + type: 'count', }, ], split_mode: 'filter', filter: { query: 'http.response.status_code:[300 TO 399]', - language: InfraMetricModelQueryType.lucene, + language: 'lucene', }, }, { @@ -58,13 +51,13 @@ export const nginxHits: InfraMetricModelCreator = ( metrics: [ { id: 'count-400', - type: InfraMetricModelMetricType.count, + type: 'count', }, ], split_mode: 'filter', filter: { query: 'http.response.status_code:[400 TO 499]', - language: InfraMetricModelQueryType.lucene, + language: 'lucene', }, }, { @@ -72,13 +65,13 @@ export const nginxHits: InfraMetricModelCreator = ( metrics: [ { id: 'count-500', - type: InfraMetricModelMetricType.count, + type: 'count', }, ], split_mode: 'filter', filter: { query: 'http.response.status_code:[500 TO 599]', - language: InfraMetricModelQueryType.lucene, + language: 'lucene', }, }, ], diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_request_rate.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_request_rate.ts similarity index 67% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_request_rate.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_request_rate.ts index b3d6118e057af..5904ba62cd309 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_request_rate.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_request_rate.ts @@ -3,20 +3,14 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; - -export const nginxRequestRate: InfraMetricModelCreator = ( +export const nginxRequestRate: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.nginxRequestRate, +): TSVBMetricModel => ({ + id: 'nginxRequestRate', requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, @@ -29,17 +23,17 @@ export const nginxRequestRate: InfraMetricModelCreator = ( { field: 'nginx.stubstatus.requests', id: 'max-requests', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'max-requests', id: 'derv-max-requests', - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: 'posonly-derv-max-requests', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [{ id: 'var-rate', name: 'rate', field: 'derv-max-requests' }], script: 'params.rate > 0.0 ? params.rate : 0.0', }, diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_requests_per_connection.ts b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_requests_per_connection.ts similarity index 69% rename from x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_requests_per_connection.ts rename to x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_requests_per_connection.ts index 65114cdda0606..c76d5a9edf8fc 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/nginx/nginx_requests_per_connection.ts +++ b/x-pack/legacy/plugins/infra/common/inventory_models/shared/metrics/tsvb/nginx_requests_per_connection.ts @@ -4,19 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - InfraMetricModelCreator, - InfraMetricModelMetricType, - InfraMetricModel, -} from '../../adapter_types'; -import { InfraMetric } from '../../../../../graphql/types'; +import { TSVBMetricModelCreator, TSVBMetricModel } from '../../../types'; -export const nginxRequestsPerConnection: InfraMetricModelCreator = ( +export const nginxRequestsPerConnection: TSVBMetricModelCreator = ( timeField, indexPattern, interval -): InfraMetricModel => ({ - id: InfraMetric.nginxRequestsPerConnection, +): TSVBMetricModel => ({ + id: 'nginxRequestsPerConnection', requires: ['nginx.stubstatus'], index_pattern: indexPattern, interval, @@ -29,16 +24,16 @@ export const nginxRequestsPerConnection: InfraMetricModelCreator = ( { field: 'nginx.stubstatus.handled', id: 'max-handled', - type: InfraMetricModelMetricType.max, + type: 'max', }, { field: 'nginx.stubstatus.requests', id: 'max-requests', - type: InfraMetricModelMetricType.max, + type: 'max', }, { id: 'reqs-per-connection', - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { id: 'var-handled', name: 'handled', field: 'max-handled' }, { id: 'var-requests', name: 'requests', field: 'max-requests' }, diff --git a/x-pack/legacy/plugins/infra/common/inventory_models/types.ts b/x-pack/legacy/plugins/infra/common/inventory_models/types.ts new file mode 100644 index 0000000000000..9c9f11048ee63 --- /dev/null +++ b/x-pack/legacy/plugins/infra/common/inventory_models/types.ts @@ -0,0 +1,285 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import * as rt from 'io-ts'; +import { EuiTheme } from '../../../../common/eui_styled_components'; + +export const ItemTypeRT = rt.keyof({ + host: null, + pod: null, + container: null, + awsEC2: null, + awsS3: null, + awsSQS: null, + awsRDS: null, +}); + +export const InventoryVisTypeRT = rt.keyof({ + line: null, + area: null, + bar: null, +}); + +export type InventoryVisType = rt.TypeOf; + +export const InventoryFormatterTypeRT = rt.keyof({ + abbreviatedNumber: null, + bits: null, + bytes: null, + number: null, + percent: null, +}); +export type InventoryItemType = rt.TypeOf; + +export const InventoryMetricRT = rt.string; +export type InventoryMetric = rt.TypeOf; + +export const SeriesOverridesRT = rt.intersection([ + rt.type({ + color: rt.string, + }), + rt.partial({ + type: InventoryVisTypeRT, + name: rt.string, + formatter: InventoryFormatterTypeRT, + formatterTemplate: rt.string, + gaugeMax: rt.number, + }), +]); + +export const VisConfigRT = rt.partial({ + stacked: rt.boolean, + type: InventoryVisTypeRT, + formatter: InventoryFormatterTypeRT, + formatterTemplate: rt.string, + seriesOverrides: rt.record(rt.string, rt.union([rt.undefined, SeriesOverridesRT])), +}); + +export const InventorySectionTypeRT = rt.keyof({ + chart: null, + gauges: null, +}); + +export type InventorySectionType = rt.TypeOf; + +export const SectionRT = rt.intersection([ + rt.type({ + id: InventoryMetricRT, + label: rt.string, + requires: rt.array(rt.string), + visConfig: VisConfigRT, + type: InventorySectionTypeRT, + }), + rt.partial({ + linkToId: rt.string, + }), +]); + +export const InventoryDetailLayoutRT = rt.type({ + id: rt.string, + label: rt.string, + sections: rt.array(SectionRT), +}); + +export type InventoryDetailSection = rt.TypeOf; +export type InventoryDetailLayout = rt.TypeOf; + +export type InventoryDetailLayoutCreator = (theme: EuiTheme) => InventoryDetailLayout[]; + +export const TSVBMetricTypeRT = rt.keyof({ + avg: null, + max: null, + min: null, + calculation: null, + cardinality: null, + series_agg: null, + positive_only: null, + derivative: null, + count: null, + sum: null, + cumulative_sum: null, +}); + +export type TSVBMetricType = rt.TypeOf; + +export const TSVBMetricModelCountRT = rt.type({ + id: rt.string, + type: rt.literal('count'), +}); + +export const TSVBMetricModelBasicMetricRT = rt.intersection([ + rt.type({ + id: rt.string, + type: TSVBMetricTypeRT, + }), + rt.partial({ + field: rt.string, + }), +]); + +export const TSVBMetricModelVariableRT = rt.type({ + field: rt.string, + id: rt.string, + name: rt.string, +}); + +export const TSVBMetricModelBucketScriptRT = rt.type({ + id: rt.string, + script: rt.string, + type: rt.literal('calculation'), + variables: rt.array(TSVBMetricModelVariableRT), +}); + +export const TSVBMetricModelDerivativeRT = rt.type({ + id: rt.string, + field: rt.string, + unit: rt.string, + type: rt.literal('derivative'), +}); + +export const TSVBMetricModelSeriesAggRT = rt.type({ + id: rt.string, + function: rt.string, + type: rt.literal('series_agg'), +}); + +export const TSVBMetricRT = rt.union([ + TSVBMetricModelCountRT, + TSVBMetricModelBasicMetricRT, + TSVBMetricModelBucketScriptRT, + TSVBMetricModelDerivativeRT, + TSVBMetricModelSeriesAggRT, +]); +export type TSVBMetric = rt.TypeOf; + +export const TSVBSeriesRT = rt.intersection([ + rt.type({ + id: rt.string, + metrics: rt.array(TSVBMetricRT), + split_mode: rt.string, + }), + rt.partial({ + terms_field: rt.string, + terms_size: rt.number, + terms_order_by: rt.string, + filter: rt.type({ + query: rt.string, + language: rt.keyof({ + lucene: null, + kuery: null, + }), + }), + }), +]); + +export const TSVBMetricModelRT = rt.intersection([ + rt.type({ + id: InventoryMetricRT, + requires: rt.array(rt.string), + index_pattern: rt.union([rt.string, rt.array(rt.string)]), + interval: rt.string, + time_field: rt.string, + type: rt.string, + series: rt.array(TSVBSeriesRT), + }), + rt.partial({ + filter: rt.string, + map_field_to: rt.string, + id_type: rt.keyof({ cloud: null, node: null }), + }), +]); + +export type TSVBMetricModel = rt.TypeOf; + +export type TSVBMetricModelCreator = ( + timeField: string, + indexPattern: string | string[], + interval: string +) => TSVBMetricModel; + +export const SnapshotModelMetricAggRT = rt.record( + rt.string, + rt.union([ + rt.undefined, + rt.type({ + field: rt.string, + }), + ]) +); + +export const SnapshotModelBucketScriptRT = rt.type({ + bucket_script: rt.intersection([ + rt.type({ + buckets_path: rt.record(rt.string, rt.union([rt.undefined, rt.string])), + script: rt.type({ + source: rt.string, + lang: rt.keyof({ painless: null, expression: null }), + }), + }), + rt.partial({ gap_policy: rt.keyof({ skip: null, insert_zeros: null }) }), + ]), +}); + +export const SnapshotModelCumulativeSumRT = rt.type({ + cumulative_sum: rt.type({ + buckets_path: rt.string, + }), +}); + +export const SnapshotModelDerivativeRT = rt.type({ + derivative: rt.type({ + buckets_path: rt.string, + gap_policy: rt.keyof({ skip: null, insert_zeros: null }), + unit: rt.string, + }), +}); + +export const SnapshotModelSumBucketRT = rt.type({ + sum_bucket: rt.type({ + buckets_path: rt.string, + }), +}); + +interface SnapshotTermsWithAggregation { + terms: { field: string }; + aggregations: SnapshotModel; +} + +export const SnapshotTermsWithAggregationRT: rt.Type = rt.recursion( + 'SnapshotModelRT', + () => + rt.type({ + terms: rt.type({ field: rt.string }), + aggregations: SnapshotModelRT, + }) +); + +export const SnapshotModelAggregationRT = rt.union([ + SnapshotModelMetricAggRT, + SnapshotModelBucketScriptRT, + SnapshotModelCumulativeSumRT, + SnapshotModelDerivativeRT, + SnapshotModelSumBucketRT, + SnapshotTermsWithAggregationRT, +]); + +export const SnapshotModelRT = rt.record( + rt.string, + rt.union([rt.undefined, SnapshotModelAggregationRT]) +); +export type SnapshotModel = rt.TypeOf; + +export interface InventoryMetrics { + tsvb: { [name: string]: TSVBMetricModelCreator }; + snapshot?: { [name: string]: SnapshotModel }; +} + +export interface InventoryModel { + id: string; + requiredModules: string[]; + layout: InventoryDetailLayoutCreator; + metrics: InventoryMetrics; +} diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/index.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/index.tsx index 2bab642bb337c..a80525e3a9cac 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/index.tsx +++ b/x-pack/legacy/plugins/infra/public/components/metrics/index.tsx @@ -10,15 +10,18 @@ import { FormattedMessage } from '@kbn/i18n/react'; import React from 'react'; import { InfraMetricData } from '../../graphql/types'; -import { InfraMetricLayout, InfraMetricLayoutSection } from '../../pages/metrics/layouts/types'; import { NoData } from '../empty_states'; import { InfraLoadingPanel } from '../loading'; import { Section } from './section'; import { MetricsTimeInput } from '../../containers/metrics/with_metrics_time'; +import { + InventoryDetailLayout, + InventoryDetailSection, +} from '../../../common/inventory_models/types'; interface Props { metrics: InfraMetricData[]; - layouts: InfraMetricLayout[]; + layouts: InventoryDetailLayout[]; loading: boolean; refetch: () => void; nodeId: string; @@ -74,7 +77,7 @@ export const Metrics = class extends React.PureComponent { this.props.refetch(); }; - private renderLayout = (layout: InfraMetricLayout) => { + private renderLayout = (layout: InventoryDetailLayout) => { return ( @@ -95,7 +98,7 @@ export const Metrics = class extends React.PureComponent { ); }; - private renderSection = (layout: InfraMetricLayout) => (section: InfraMetricLayoutSection) => { + private renderSection = (layout: InventoryDetailLayout) => (section: InventoryDetailSection) => { let sectionProps = {}; if (section.type === 'chart') { const { onChangeRangeTime, isLiveStreaming, stopLiveStreaming } = this.props; diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/section.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/section.tsx index 69981086637b6..ff416bf4541b2 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/section.tsx +++ b/x-pack/legacy/plugins/infra/public/components/metrics/section.tsx @@ -6,12 +6,12 @@ import React from 'react'; import { InfraMetricData } from '../../graphql/types'; -import { InfraMetricLayoutSection } from '../../pages/metrics/layouts/types'; import { sections } from './sections'; import { MetricsTimeInput } from '../../containers/metrics/with_metrics_time'; +import { InventoryDetailSection } from '../../../common/inventory_models/types'; interface Props { - section: InfraMetricLayoutSection; + section: InventoryDetailSection; metrics: InfraMetricData[]; onChangeRangeTime?: (time: MetricsTimeInput) => void; crosshairValue?: number; diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/sections/chart_section.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/sections/chart_section.tsx index e13b8134e38dd..e265329e6d78c 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/sections/chart_section.tsx +++ b/x-pack/legacy/plugins/infra/public/components/metrics/sections/chart_section.tsx @@ -17,7 +17,6 @@ import { TooltipValue, } from '@elastic/charts'; import { EuiPageContentBody, EuiTitle } from '@elastic/eui'; -import { InfraMetricLayoutSection } from '../../../pages/metrics/layouts/types'; import { InfraMetricData } from '../../../graphql/types'; import { getChartTheme } from '../../metrics_explorer/helpers/get_chart_theme'; import { InfraFormatterType } from '../../../lib/lib'; @@ -33,9 +32,10 @@ import { import { ErrorMessage } from './error_message'; import { useKibanaUiSetting } from '../../../utils/use_kibana_ui_setting'; import { MetricsTimeInput } from '../../../containers/metrics/with_metrics_time'; +import { InventoryDetailSection } from '../../../../common/inventory_models/types'; interface Props { - section: InfraMetricLayoutSection; + section: InventoryDetailSection; metric: InfraMetricData; onChangeRangeTime?: (time: MetricsTimeInput) => void; isLiveStreaming?: boolean; diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/sections/gauges_section.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/sections/gauges_section.tsx index 2c49d778d55b7..6b73ac62872c9 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/sections/gauges_section.tsx +++ b/x-pack/legacy/plugins/infra/public/components/metrics/sections/gauges_section.tsx @@ -19,15 +19,15 @@ import React, { ReactText } from 'react'; import euiStyled from '../../../../../../common/eui_styled_components'; import { InfraMetricData } from '../../../graphql/types'; import { InfraFormatterType } from '../../../lib/lib'; -import { InfraMetricLayoutSection } from '../../../pages/metrics/layouts/types'; import { createFormatter } from '../../../utils/formatters'; +import { InventoryDetailSection } from '../../../../common/inventory_models/types'; interface Props { - section: InfraMetricLayoutSection; + section: InventoryDetailSection; metric: InfraMetricData; } -const getFormatter = (section: InfraMetricLayoutSection, seriesId: string) => (val: ReactText) => { +const getFormatter = (section: InventoryDetailSection, seriesId: string) => (val: ReactText) => { if (val == null) { return ''; } diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/sections/helpers/index.ts b/x-pack/legacy/plugins/infra/public/components/metrics/sections/helpers/index.ts index 660295c11ec2c..2e8d6b056caef 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/sections/helpers/index.ts +++ b/x-pack/legacy/plugins/infra/public/components/metrics/sections/helpers/index.ts @@ -11,9 +11,9 @@ import { InfraFormatterType } from '../../../../lib/lib'; import { createFormatter } from '../../../../utils/formatters'; import { InfraDataSeries, InfraMetricData } from '../../../../graphql/types'; import { - InfraMetricLayoutVisualizationType, - InfraMetricLayoutSection, -} from '../../../../pages/metrics/layouts/types'; + InventoryDetailSection, + InventoryVisTypeRT, +} from '../../../../../common/inventory_models/types'; /** * Returns a formatter @@ -47,11 +47,7 @@ export const getMaxMinTimestamp = (metric: InfraMetricData): [number, number] => * Returns the chart name from the visConfig based on the series id, otherwise it * just returns the seriesId */ -export const getChartName = ( - section: InfraMetricLayoutSection, - seriesId: string, - label: string -) => { +export const getChartName = (section: InventoryDetailSection, seriesId: string, label: string) => { return get(section, ['visConfig', 'seriesOverrides', seriesId, 'name'], label); }; @@ -59,7 +55,7 @@ export const getChartName = ( * Returns the chart color from the visConfig based on the series id, otherwise it * just returns null if the color doesn't exists in the overrides. */ -export const getChartColor = (section: InfraMetricLayoutSection, seriesId: string) => { +export const getChartColor = (section: InventoryDetailSection, seriesId: string) => { const rawColor: string | null = get(section, ['visConfig', 'seriesOverrides', seriesId, 'color']); if (!rawColor) { return null; @@ -68,26 +64,17 @@ export const getChartColor = (section: InfraMetricLayoutSection, seriesId: strin return color.hex().toString(); }; -/** - * Type guard for InfraMetricLayoutVisualizationType - */ -const isInfraMetricLayoutVisualizationType = ( - subject: any -): subject is InfraMetricLayoutVisualizationType => { - return subject in InfraMetricLayoutVisualizationType; -}; - /** * Gets the chart type based on the section and seriesId */ -export const getChartType = (section: InfraMetricLayoutSection, seriesId: string) => { +export const getChartType = (section: InventoryDetailSection, seriesId: string) => { const value = get(section, ['visConfig', 'type']); const overrideValue = get(section, ['visConfig', 'seriesOverrides', seriesId, 'type']); - if (isInfraMetricLayoutVisualizationType(overrideValue)) { + if (InventoryVisTypeRT.is(overrideValue)) { return overrideValue; } - if (isInfraMetricLayoutVisualizationType(value)) { + if (InventoryVisTypeRT.is(value)) { return value; } - return InfraMetricLayoutVisualizationType.line; + return 'line'; }; diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/sections/index.ts b/x-pack/legacy/plugins/infra/public/components/metrics/sections/index.ts index f5a8fcfed6dd6..39844868ecbea 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/sections/index.ts +++ b/x-pack/legacy/plugins/infra/public/components/metrics/sections/index.ts @@ -4,12 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricLayoutSectionType } from '../../../pages/metrics/layouts/types'; -// import { ChartSection } from './chart_section'; import { GaugesSection } from './gauges_section'; import { ChartSection } from './chart_section'; export const sections = { - [InfraMetricLayoutSectionType.chart]: ChartSection, - [InfraMetricLayoutSectionType.gauges]: GaugesSection, + chart: ChartSection, + gauges: GaugesSection, }; diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/sections/series_chart.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/sections/series_chart.tsx index 9dc7004837064..b75f669a6d1ec 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/sections/series_chart.tsx +++ b/x-pack/legacy/plugins/infra/public/components/metrics/sections/series_chart.tsx @@ -16,20 +16,20 @@ import { BarSeriesStyle, AreaSeriesStyle, } from '@elastic/charts'; -import { InfraMetricLayoutVisualizationType } from '../../../pages/metrics/layouts/types'; import { InfraDataSeries } from '../../../graphql/types'; +import { InventoryVisType } from '../../../../common/inventory_models/types'; interface Props { id: string; name: string; color: string | null; series: InfraDataSeries; - type: InfraMetricLayoutVisualizationType; + type: InventoryVisType; stack: boolean | undefined; } export const SeriesChart = (props: Props) => { - if (props.type === InfraMetricLayoutVisualizationType.bar) { + if (props.type === 'bar') { return ; } return ; @@ -39,10 +39,10 @@ export const AreaChart = ({ id, color, series, name, type, stack }: Props) => { const style: RecursivePartial = { area: { opacity: 1, - visible: InfraMetricLayoutVisualizationType.area === type, + visible: 'area' === type, }, line: { - strokeWidth: InfraMetricLayoutVisualizationType.area === type ? 1 : 2, + strokeWidth: 'area' === type ? 1 : 2, visible: true, }, }; diff --git a/x-pack/legacy/plugins/infra/public/components/metrics/side_nav.tsx b/x-pack/legacy/plugins/infra/public/components/metrics/side_nav.tsx index 106d22db169ad..f20adadce6042 100644 --- a/x-pack/legacy/plugins/infra/public/components/metrics/side_nav.tsx +++ b/x-pack/legacy/plugins/infra/public/components/metrics/side_nav.tsx @@ -9,13 +9,16 @@ import { EuiHideFor, EuiPageSideBar, EuiShowFor, EuiSideNav } from '@elastic/eui import React from 'react'; import euiStyled from '../../../../../common/eui_styled_components'; -import { InfraMetricLayout, InfraMetricLayoutSection } from '../../pages/metrics/layouts/types'; +import { + InventoryDetailLayout, + InventoryDetailSection, +} from '../../../common/inventory_models/types'; interface Props { - layouts: InfraMetricLayout[]; + layouts: InventoryDetailLayout[]; loading: boolean; nodeName: string; - handleClick: (section: InfraMetricLayoutSection) => () => void; + handleClick: (section: InventoryDetailSection) => () => void; } export const MetricsSideNav = class extends React.PureComponent { diff --git a/x-pack/legacy/plugins/infra/public/containers/metadata/lib/get_filtered_layouts.ts b/x-pack/legacy/plugins/infra/public/containers/metadata/lib/get_filtered_layouts.ts index a543365aa68d5..6c7a9d6dcad38 100644 --- a/x-pack/legacy/plugins/infra/public/containers/metadata/lib/get_filtered_layouts.ts +++ b/x-pack/legacy/plugins/infra/public/containers/metadata/lib/get_filtered_layouts.ts @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ import { InfraMetadataFeature } from '../../../../common/http_api/metadata_api'; -import { InfraMetricLayout } from '../../../pages/metrics/layouts/types'; +import { InventoryDetailLayout } from '../../../../common/inventory_models/types'; export const getFilteredLayouts = ( - layouts: InfraMetricLayout[], + layouts: InventoryDetailLayout[], metadata: Array | undefined -): InfraMetricLayout[] => { +): InventoryDetailLayout[] => { if (!metadata) { return layouts; } @@ -26,9 +26,9 @@ export const getFilteredLayouts = ( }; export const getFilteredLayout = ( - layout: InfraMetricLayout, + layout: InventoryDetailLayout, metricMetadata: Array -): InfraMetricLayout => { +): InventoryDetailLayout => { // A section is only displayed if at least one of its requirements is met // All others are filtered out. const filteredSections = layout.sections.filter( diff --git a/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts b/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts index 4f97d9aa3e3b1..718178ecb4fa2 100644 --- a/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts +++ b/x-pack/legacy/plugins/infra/public/containers/metadata/use_metadata.ts @@ -9,16 +9,16 @@ import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { pipe } from 'fp-ts/lib/pipeable'; import { InfraNodeType } from '../../graphql/types'; -import { InfraMetricLayout } from '../../pages/metrics/layouts/types'; import { InfraMetadata, InfraMetadataRT } from '../../../common/http_api/metadata_api'; import { getFilteredLayouts } from './lib/get_filtered_layouts'; import { useHTTPRequest } from '../../hooks/use_http_request'; import { throwErrors, createPlainError } from '../../../common/runtime_types'; +import { InventoryDetailLayout } from '../../../common/inventory_models/types'; export function useMetadata( nodeId: string, nodeType: InfraNodeType, - layouts: InfraMetricLayout[], + layouts: InventoryDetailLayout[], sourceId: string ) { const decodeResponse = (response: any) => { diff --git a/x-pack/legacy/plugins/infra/public/containers/metrics/with_metrics.tsx b/x-pack/legacy/plugins/infra/public/containers/metrics/with_metrics.tsx index af45e6ea5d488..bb346553a4bf9 100644 --- a/x-pack/legacy/plugins/infra/public/containers/metrics/with_metrics.tsx +++ b/x-pack/legacy/plugins/infra/public/containers/metrics/with_metrics.tsx @@ -6,6 +6,7 @@ import { ApolloError } from 'apollo-client'; import React from 'react'; import { Query } from 'react-apollo'; +import { i18n } from '@kbn/i18n'; import { InfraMetric, InfraMetricData, @@ -13,8 +14,8 @@ import { MetricsQuery, InfraTimerangeInput, } from '../../graphql/types'; -import { InfraMetricLayout } from '../../pages/metrics/layouts/types'; import { metricsQuery } from './metrics.gql_query'; +import { InventoryDetailLayout, InventoryMetric } from '../../../common/inventory_models/types'; interface WithMetricsArgs { metrics: InfraMetricData[]; @@ -25,7 +26,7 @@ interface WithMetricsArgs { interface WithMetricsProps { children: (args: WithMetricsArgs) => React.ReactNode; - layouts: InfraMetricLayout[]; + layouts: InventoryDetailLayout[]; nodeType: InfraNodeType; nodeId: string; cloudId: string; @@ -33,6 +34,10 @@ interface WithMetricsProps { timerange: InfraTimerangeInput; } +const isInfraMetrics = (subject: string[]): subject is InfraMetric[] => { + return subject.every(s => s in InfraMetric); +}; + export const WithMetrics = ({ children, layouts, @@ -44,7 +49,15 @@ export const WithMetrics = ({ }: WithMetricsProps) => { const metrics = layouts.reduce((acc, item) => { return acc.concat(item.sections.map(s => s.id)); - }, [] as InfraMetric[]); + }, [] as InventoryMetric[]); + + if (!isInfraMetrics(metrics)) { + throw new Error( + i18n.translate('xpack.infra.invalidInventoryMetricsError', { + defaultMessage: 'One of the InfraMetric is invalid', + }) + ); + } return ( diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx b/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx index 619096a22c62b..1996d51b4f26b 100644 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx +++ b/x-pack/legacy/plugins/infra/public/pages/metrics/index.tsx @@ -34,14 +34,14 @@ import { WithMetricsTimeUrlState, } from '../../containers/metrics/with_metrics_time'; import { InfraNodeType } from '../../graphql/types'; -import { Error, ErrorPageBody } from '../error'; -import { layoutCreators } from './layouts'; -import { InfraMetricLayoutSection } from './layouts/types'; +import { ErrorPageBody } from '../error'; import { withMetricPageProviders } from './page_providers'; import { useMetadata } from '../../containers/metadata/use_metadata'; import { Source } from '../../containers/source'; import { InfraLoadingPanel } from '../../components/loading'; import { NodeDetails } from '../../components/metrics/node_details'; +import { findInventoryModel } from '../../../common/inventory_models'; +import { InventoryDetailSection } from '../../../common/inventory_models/types'; const DetailPageContent = euiStyled(PageContent)` overflow: auto; @@ -68,19 +68,8 @@ export const MetricDetail = withMetricPageProviders( withTheme(({ uiCapabilities, match, theme }: Props) => { const nodeId = match.params.node; const nodeType = match.params.type as InfraNodeType; - const layoutCreator = layoutCreators[nodeType]; - if (!layoutCreator) { - return ( - - ); - } + const inventoryModel = findInventoryModel(nodeType); + const layoutCreator = inventoryModel.layout; const { sourceId } = useContext(Source.Context); const layouts = layoutCreator(theme); const { name, filteredLayouts, loading: metadataLoading, cloudId, metadata } = useMetadata( @@ -100,7 +89,7 @@ export const MetricDetail = withMetricPageProviders( ]; const handleClick = useCallback( - (section: InfraMetricLayoutSection) => () => { + (section: InventoryDetailSection) => () => { const id = section.linkToId || section.id; const el = document.getElementById(id); if (el) { diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/host.ts b/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/host.ts deleted file mode 100644 index d8856158e7779..0000000000000 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/host.ts +++ /dev/null @@ -1,610 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { i18n } from '@kbn/i18n'; -import { InfraMetric } from '../../../graphql/types'; -import { InfraFormatterType } from '../../../lib/lib'; -import { nginxLayoutCreator } from './nginx'; -import { awsLayoutCreator } from './aws'; -import { - InfraMetricLayoutCreator, - InfraMetricLayoutSectionType, - InfraMetricLayoutVisualizationType, -} from './types'; - -export const hostLayoutCreator: InfraMetricLayoutCreator = theme => [ - { - id: 'hostOverview', - label: i18n.translate('xpack.infra.metricDetailPage.hostMetricsLayout.layoutLabel', { - defaultMessage: 'Host', - }), - sections: [ - { - id: InfraMetric.hostSystemOverview, - linkToId: 'hostOverview', - label: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.sectionLabel', - { - defaultMessage: 'Overview', - } - ), - requires: ['system.cpu', 'system.load', 'system.memory', 'system.network'], - type: InfraMetricLayoutSectionType.gauges, - visConfig: { - seriesOverrides: { - cpu: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.cpuUsageSeriesLabel', - { - defaultMessage: 'CPU Usage', - } - ), - color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, - gaugeMax: 1, - }, - load: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.loadSeriesLabel', - { - defaultMessage: 'Load (5m)', - } - ), - color: theme.eui.euiColorFullShade, - }, - memory: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.memoryCapacitySeriesLabel', - { - defaultMessage: 'Memory Usage', - } - ), - color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.percent, - gaugeMax: 1, - }, - rx: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.inboundRXSeriesLabel', - { - defaultMessage: 'Inbound (RX)', - } - ), - color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.bits, - formatterTemplate: '{{value}}/s', - }, - tx: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.outboundTXSeriesLabel', - { - defaultMessage: 'Outbound (TX)', - } - ), - color: theme.eui.euiColorFullShade, - formatter: InfraFormatterType.bits, - formatterTemplate: '{{value}}/s', - }, - }, - }, - }, - { - id: InfraMetric.hostCpuUsage, - label: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.sectionLabel', - { - defaultMessage: 'CPU Usage', - } - ), - requires: ['system.cpu'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - stacked: true, - type: InfraMetricLayoutVisualizationType.area, - formatter: InfraFormatterType.percent, - seriesOverrides: { - user: { - color: theme.eui.euiColorVis0, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.user', - { defaultMessage: 'user' } - ), - }, - system: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.system', - { defaultMessage: 'system' } - ), - }, - steal: { - color: theme.eui.euiColorVis9, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.steal', - { defaultMessage: 'steal' } - ), - }, - irq: { - color: theme.eui.euiColorVis4, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.irq', - { defaultMessage: 'irq' } - ), - }, - softirq: { - color: theme.eui.euiColorVis6, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.softirq', - { defaultMessage: 'softirq' } - ), - }, - iowait: { - color: theme.eui.euiColorVis7, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.iowait', - { defaultMessage: 'iowait' } - ), - }, - nice: { - color: theme.eui.euiColorVis5, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.cpuUsageSection.seriesLabel.nice', - { defaultMessage: 'nice' } - ), - }, - }, - }, - }, - { - id: InfraMetric.hostLoad, - label: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.sectionLabel', - { - defaultMessage: 'Load', - } - ), - requires: ['system.load'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - seriesOverrides: { - load_1m: { - color: theme.eui.euiColorVis0, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.oneMinuteSeriesLabel', - { - defaultMessage: '1m', - } - ), - }, - load_5m: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.fiveMinuteSeriesLabel', - { - defaultMessage: '5m', - } - ), - }, - load_15m: { - color: theme.eui.euiColorVis3, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.loadSection.fifteenMinuteSeriesLabel', - { - defaultMessage: '15m', - } - ), - }, - }, - }, - }, - { - id: InfraMetric.hostMemoryUsage, - label: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.memoryUsageSection.sectionLabel', - { - defaultMessage: 'Memory Usage', - } - ), - requires: ['system.memory'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - stacked: true, - formatter: InfraFormatterType.bytes, - type: InfraMetricLayoutVisualizationType.area, - seriesOverrides: { - used: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.memoryUsageSection.seriesLabel.used', - { defaultMessage: 'Used' } - ), - }, - free: { - color: theme.eui.euiColorVis0, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.memoryUsageSection.seriesLabel.free', - { defaultMessage: 'Free' } - ), - }, - cache: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.memoryUsageSection.seriesLabel.cache', - { defaultMessage: 'Cache' } - ), - }, - }, - }, - }, - { - id: InfraMetric.hostNetworkTraffic, - label: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.networkTrafficSection.sectionLabel', - { - defaultMessage: 'Network Traffic', - } - ), - requires: ['system.network'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.bits, - formatterTemplate: '{{value}}/s', - type: InfraMetricLayoutVisualizationType.area, - seriesOverrides: { - rx: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.networkTrafficSection.networkRxRateSeriesLabel', - { - defaultMessage: 'In', - } - ), - }, - tx: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.hostMetricsLayout.networkTrafficSection.networkTxRateSeriesLabel', - { - defaultMessage: 'Out', - } - ), - }, - }, - }, - }, - ], - }, - { - id: 'k8sOverview', - label: 'Kubernetes', - sections: [ - { - id: InfraMetric.hostK8sOverview, - linkToId: 'k8sOverview', - label: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.sectionLabel', - { - defaultMessage: 'Overview', - } - ), - requires: ['kubernetes.node'], - type: InfraMetricLayoutSectionType.gauges, - visConfig: { - seriesOverrides: { - cpucap: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.cpuUsageSeriesLabel', - { - defaultMessage: 'CPU Capacity', - } - ), - color: 'secondary', - formatter: InfraFormatterType.percent, - gaugeMax: 1, - }, - load: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.loadSeriesLabel', - { - defaultMessage: 'Load (5m)', - } - ), - color: 'secondary', - }, - memorycap: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.memoryUsageSeriesLabel', - { - defaultMessage: 'Memory Capacity', - } - ), - color: 'secondary', - formatter: InfraFormatterType.percent, - gaugeMax: 1, - }, - podcap: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.podCapacitySeriesLabel', - { - defaultMessage: 'Pod Capacity', - } - ), - color: 'secondary', - formatter: InfraFormatterType.percent, - gaugeMax: 1, - }, - diskcap: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.overviewSection.diskCapacitySeriesLabel', - { - defaultMessage: 'Disk Capacity', - } - ), - color: 'secondary', - formatter: InfraFormatterType.percent, - gaugeMax: 1, - }, - }, - }, - }, - { - id: InfraMetric.hostK8sCpuCap, - label: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeCpuCapacitySection.sectionLabel', - { - defaultMessage: 'Node CPU Capacity', - } - ), - requires: ['kubernetes.node'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.abbreviatedNumber, - seriesOverrides: { - capacity: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeCpuCapacitySection.seriesLabel.capacity', - { defaultMessage: 'Capacity' } - ), - }, - used: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeCpuCapacitySection.seriesLabel.used', - { defaultMessage: 'Used' } - ), - type: InfraMetricLayoutVisualizationType.area, - }, - }, - }, - }, - { - id: InfraMetric.hostK8sMemoryCap, - label: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeMemoryCapacitySection.sectionLabel', - { - defaultMessage: 'Node Memory Capacity', - } - ), - requires: ['kubernetes.node'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.bytes, - seriesOverrides: { - capacity: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeMemoryCapacitySection.seriesLabel.capacity', - { defaultMessage: 'Capacity' } - ), - }, - used: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeMemoryCapacitySection.seriesLabel.used', - { defaultMessage: 'Used' } - ), - type: InfraMetricLayoutVisualizationType.area, - }, - }, - }, - }, - { - id: InfraMetric.hostK8sDiskCap, - label: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeDiskCapacitySection.sectionLabel', - { - defaultMessage: 'Node Disk Capacity', - } - ), - requires: ['kubernetes.node'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.bytes, - seriesOverrides: { - capacity: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeDiskCapacitySection.seriesLabel.capacity', - { defaultMessage: 'Capacity' } - ), - }, - used: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeDiskCapacitySection.seriesLabel.used', - { defaultMessage: 'Used' } - ), - type: InfraMetricLayoutVisualizationType.area, - }, - }, - }, - }, - { - id: InfraMetric.hostK8sPodCap, - label: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodePodCapacitySection.sectionLabel', - { - defaultMessage: 'Node Pod Capacity', - } - ), - requires: ['kubernetes.node'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.number, - seriesOverrides: { - capacity: { - color: theme.eui.euiColorVis2, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodePodCapacitySection.seriesLabel.capacity', - { defaultMessage: 'Capacity' } - ), - }, - used: { - color: theme.eui.euiColorVis1, - name: i18n.translate( - 'xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodePodCapacitySection.seriesLabel.used', - { defaultMessage: 'Used' } - ), - type: InfraMetricLayoutVisualizationType.area, - }, - }, - }, - }, - ], - }, - { - id: 'dockerOverview', - label: 'Docker', - sections: [ - { - id: InfraMetric.hostDockerOverview, - linkToId: 'dockerOverview', - label: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.overviewSection.sectionLabel', - { - defaultMessage: 'Overview', - } - ), - requires: ['docker.info'], - type: InfraMetricLayoutSectionType.gauges, - visConfig: { - seriesOverrides: { - total: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.overviewSection.totalLabel', - { - defaultMessage: 'Total', - } - ), - color: 'secondary', - }, - running: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.overviewSection.runningLabel', - { - defaultMessage: 'Running', - } - ), - color: 'secondary', - }, - paused: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.overviewSection.pausedLabel', - { - defaultMessage: 'Paused', - } - ), - color: 'secondary', - }, - stopped: { - name: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.overviewSection.stoppedLabel', - { - defaultMessage: 'Stopped', - } - ), - color: 'secondary', - }, - }, - }, - }, - { - id: InfraMetric.hostDockerInfo, - label: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.containerStates.sectionLabel', - { - defaultMessage: 'Container States', - } - ), - requires: ['docker.info'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.abbreviatedNumber, - stacked: true, - seriesOverrides: { - running: { - color: theme.eui.euiColorVis2, - type: InfraMetricLayoutVisualizationType.bar, - name: i18n.translate( - 'xpack.infra.metricDetailPage.containerStates.seriesLabel.running', - { defaultMessage: 'Running' } - ), - }, - stopped: { - color: theme.eui.euiColorVis1, - type: InfraMetricLayoutVisualizationType.bar, - name: i18n.translate( - 'xpack.infra.metricDetailPage.containerStates.seriesLabel.stopped', - { defaultMessage: 'Stopped' } - ), - }, - paused: { - color: theme.eui.euiColorVis7, - type: InfraMetricLayoutVisualizationType.bar, - name: i18n.translate( - 'xpack.infra.metricDetailPage.containerStates.seriesLabel.paused', - { defaultMessage: 'Paused' } - ), - }, - }, - }, - }, - { - id: InfraMetric.hostDockerTop5ByCpu, - label: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.top5Cpu.sectionLabel', - { - defaultMessage: 'Top 5 Containers by CPU', - } - ), - requires: ['docker.cpu'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.percent, - seriesOverrides: {}, - }, - }, - { - id: InfraMetric.hostDockerTop5ByMemory, - label: i18n.translate( - 'xpack.infra.metricDetailPage.dockerMetricsLayout.top5Memory.sectionLabel', - { - defaultMessage: 'Top 5 Containers by Memory', - } - ), - requires: ['docker.memory'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.percent, - seriesOverrides: {}, - }, - }, - ], - }, - ...nginxLayoutCreator(theme), - ...awsLayoutCreator(theme), -]; diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/index.ts b/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/index.ts deleted file mode 100644 index d81bde64e230b..0000000000000 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { containerLayoutCreator } from './container'; -import { hostLayoutCreator } from './host'; -import { podLayoutCreator } from './pod'; -import { InfraMetricLayoutCreator } from './types'; - -interface Layouts { - [key: string]: InfraMetricLayoutCreator; -} - -export const layoutCreators: Layouts = { - host: hostLayoutCreator, - pod: podLayoutCreator, - container: containerLayoutCreator, -}; diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/nginx.ts b/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/nginx.ts deleted file mode 100644 index 05f27c2e650bc..0000000000000 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/nginx.ts +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { i18n } from '@kbn/i18n'; -import { InfraMetric } from '../../../graphql/types'; -import { InfraFormatterType } from '../../../lib/lib'; -import { - InfraMetricLayoutCreator, - InfraMetricLayoutSectionType, - InfraMetricLayoutVisualizationType, -} from './types'; - -export const nginxLayoutCreator: InfraMetricLayoutCreator = theme => [ - { - id: 'nginxOverview', - label: 'Nginx', - sections: [ - { - id: InfraMetric.nginxHits, - label: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.hitsSection.sectionLabel', - { - defaultMessage: 'Hits', - } - ), - requires: ['nginx.access'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.abbreviatedNumber, - stacked: true, - seriesOverrides: { - '200s': { - color: theme.eui.euiColorVis1, - type: InfraMetricLayoutVisualizationType.bar, - name: '200s', - }, - '300s': { - color: theme.eui.euiColorVis5, - type: InfraMetricLayoutVisualizationType.bar, - name: '300s', - }, - '400s': { - color: theme.eui.euiColorVis2, - type: InfraMetricLayoutVisualizationType.bar, - name: '400s', - }, - '500s': { - color: theme.eui.euiColorVis9, - type: InfraMetricLayoutVisualizationType.bar, - name: '500s', - }, - }, - }, - }, - { - id: InfraMetric.nginxRequestRate, - label: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestRateSection.sectionLabel', - { - defaultMessage: 'Request Rate', - } - ), - requires: ['nginx.stubstatus'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.abbreviatedNumber, - formatterTemplate: '{{value}}/s', - seriesOverrides: { - rate: { - color: theme.eui.euiColorVis1, - type: InfraMetricLayoutVisualizationType.area, - name: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestRateSection.seriesLabel.rate', - { defaultMessage: 'rate' } - ), - }, - }, - }, - }, - { - id: InfraMetric.nginxActiveConnections, - label: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.activeConnectionsSection.sectionLabel', - { - defaultMessage: 'Active Connections', - } - ), - requires: ['nginx.stubstatus'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.abbreviatedNumber, - seriesOverrides: { - connections: { - color: theme.eui.euiColorVis1, - type: InfraMetricLayoutVisualizationType.bar, - name: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.activeConnectionsSection.seriesLabel.connections', - { defaultMessage: 'connections' } - ), - }, - }, - }, - }, - { - id: InfraMetric.nginxRequestsPerConnection, - label: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestsPerConnectionsSection.sectionLabel', - { - defaultMessage: 'Requests per Connections', - } - ), - requires: ['nginx.stubstatus'], - type: InfraMetricLayoutSectionType.chart, - visConfig: { - formatter: InfraFormatterType.abbreviatedNumber, - seriesOverrides: { - reqPerConns: { - color: theme.eui.euiColorVis1, - type: InfraMetricLayoutVisualizationType.bar, - name: i18n.translate( - 'xpack.infra.metricDetailPage.nginxMetricsLayout.requestsPerConnectionsSection.reqsPerConnSeriesLabel', - { - defaultMessage: 'reqs per conn', - } - ), - }, - }, - }, - }, - ], - }, -]; diff --git a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/types.ts b/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/types.ts deleted file mode 100644 index 74e701981b999..0000000000000 --- a/x-pack/legacy/plugins/infra/public/pages/metrics/layouts/types.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { EuiTheme } from '../../../../../../common/eui_styled_components'; -import { InfraMetric } from '../../../graphql/types'; -import { InfraFormatterType } from '../../../lib/lib'; - -export enum InfraMetricLayoutVisualizationType { - line = 'line', - area = 'area', - bar = 'bar', -} - -export enum InfraMetricLayoutSectionType { - chart = 'chart', - gauges = 'gauges', -} - -interface SeriesOverrides { - type?: InfraMetricLayoutVisualizationType; - color: string; - name?: string; - formatter?: InfraFormatterType; - formatterTemplate?: string; - gaugeMax?: number; -} - -interface SeriesOverrideObject { - [name: string]: SeriesOverrides | undefined; -} - -export interface InfraMetricLayoutVisualizationConfig { - stacked?: boolean; - type?: InfraMetricLayoutVisualizationType; - formatter?: InfraFormatterType; - formatterTemplate?: string; - seriesOverrides: SeriesOverrideObject; -} - -export interface InfraMetricLayoutSection { - id: InfraMetric; - linkToId?: string; - label: string; - requires: string[]; - visConfig: InfraMetricLayoutVisualizationConfig; - type: InfraMetricLayoutSectionType; -} - -export interface InfraMetricLayout { - id: string; - label: string; - sections: InfraMetricLayoutSection[]; -} - -export type InfraMetricLayoutCreator = (theme: EuiTheme) => InfraMetricLayout[]; diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts index 583d7c20dc124..1ff9b7ab62039 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/adapter_types.ts @@ -11,7 +11,7 @@ import { Legacy } from 'kibana'; import { KibanaConfig } from 'src/legacy/server/kbn_server'; import { JsonObject } from '../../../../common/typed_json'; -import { InfraMetricModel } from '../metrics/adapter_types'; +import { TSVBMetricModel } from '../../../../common/inventory_models/types'; export const internalInfraFrameworkRequest = Symbol('internalInfraFrameworkRequest'); @@ -63,7 +63,7 @@ export interface InfraBackendFrameworkAdapter { getSpaceId(request: InfraFrameworkRequest): string; makeTSVBRequest( req: InfraFrameworkRequest, - model: InfraMetricModel, + model: TSVBMetricModel, timerange: { min: number; max: number }, filters: JsonObject[] ): Promise; diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts index 31c14aba4610f..e96f1687bbb2e 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts @@ -10,7 +10,6 @@ import { Legacy } from 'kibana'; import { KibanaConfig } from 'src/legacy/server/kbn_server'; import { get } from 'lodash'; -import { InfraMetricModel } from '../metrics/adapter_types'; import { InfraBackendFrameworkAdapter, InfraFrameworkRequest, @@ -26,6 +25,7 @@ import { HapiGraphiQLPluginOptions, HapiGraphQLPluginOptions, } from './apollo_server_hapi'; +import { TSVBMetricModel } from '../../../../common/inventory_models/types'; interface CallWithRequestParams extends GenericParams { max_concurrent_shard_requests?: number; @@ -169,7 +169,7 @@ export class InfraKibanaBackendFrameworkAdapter implements InfraBackendFramework public async makeTSVBRequest( req: InfraFrameworkRequest, - model: InfraMetricModel, + model: TSVBMetricModel, timerange: { min: number; max: number }, filters: any[] ) { diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts index cb1729788ea6b..49d445e5f3930 100644 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts +++ b/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/kibana_metrics_adapter.ts @@ -5,14 +5,15 @@ */ import { i18n } from '@kbn/i18n'; -import { flatten } from 'lodash'; +import { flatten, get } from 'lodash'; import { InfraMetric, InfraMetricData, InfraNodeType } from '../../../graphql/types'; import { InfraBackendFrameworkAdapter, InfraFrameworkRequest } from '../framework'; import { InfraMetricsAdapter, InfraMetricsRequestOptions } from './adapter_types'; import { checkValidNode } from './lib/check_valid_node'; import { InvalidNodeError } from './lib/errors'; -import { metricModels } from './models'; +import { metrics } from '../../../../common/inventory_models'; +import { TSVBMetricModelCreator } from '../../../../common/inventory_models/types'; export class KibanaMetricsAdapter implements InfraMetricsAdapter { private framework: InfraBackendFrameworkAdapter; @@ -55,7 +56,21 @@ export class KibanaMetricsAdapter implements InfraMetricsAdapter { } const requests = options.metrics.map(metricId => { - const model = metricModels[metricId](timeField, indexPattern, interval); + const createTSVBModel = get(metrics, ['tsvb', metricId]) as + | TSVBMetricModelCreator + | undefined; + if (!createTSVBModel) { + throw new Error( + i18n.translate('xpack.infra.metrics.missingTSVBModelError', { + defaultMessage: 'The TSVB model for {metricId} does not exist for {nodeType}', + values: { + metricId, + nodeType: options.nodeType, + }, + }) + ); + } + const model = createTSVBModel(timeField, indexPattern, interval); if (model.id_type === 'cloud' && !options.nodeIds.cloudId) { throw new InvalidNodeError( i18n.translate('xpack.infra.kibanaMetrics.cloudIdMissingErrorMessage', { diff --git a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/index.ts b/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/index.ts deleted file mode 100644 index 64d8dc1d4f8ed..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/adapters/metrics/models/index.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraMetric } from '../../../../graphql/types'; -import { InfraMetricModelCreator } from '../adapter_types'; - -import { hostCpuUsage } from './host/host_cpu_usage'; -import { hostFilesystem } from './host/host_filesystem'; -import { hostK8sCpuCap } from './host/host_k8s_cpu_cap'; -import { hostK8sDiskCap } from './host/host_k8s_disk_cap'; -import { hostK8sMemoryCap } from './host/host_k8s_memory_cap'; -import { hostK8sOverview } from './host/host_k8s_overview'; -import { hostK8sPodCap } from './host/host_k8s_pod_cap'; -import { hostLoad } from './host/host_load'; -import { hostMemoryUsage } from './host/host_memory_usage'; -import { hostNetworkTraffic } from './host/host_network_traffic'; -import { hostSystemOverview } from './host/host_system_overview'; -import { hostDockerOverview } from './host/host_docker_overview'; -import { hostDockerInfo } from './host/host_docker_info'; -import { hostDockerTop5ByCpu } from './host/host_docker_top_5_by_cpu'; -import { hostDockerTop5ByMemory } from './host/host_docker_top_5_by_memory'; - -import { podCpuUsage } from './pod/pod_cpu_usage'; -import { podLogUsage } from './pod/pod_log_usage'; -import { podMemoryUsage } from './pod/pod_memory_usage'; -import { podNetworkTraffic } from './pod/pod_network_traffic'; -import { podOverview } from './pod/pod_overview'; - -import { containerCpuKernel } from './container/container_cpu_kernel'; -import { containerCpuUsage } from './container/container_cpu_usage'; -import { containerDiskIOBytes } from './container/container_disk_io_bytes'; -import { containerDiskIOOps } from './container/container_diskio_ops'; -import { containerMemory } from './container/container_memory'; -import { containerNetworkTraffic } from './container/container_network_traffic'; -import { containerOverview } from './container/container_overview'; -import { nginxActiveConnections } from './nginx/nginx_active_connections'; -import { nginxHits } from './nginx/nginx_hits'; -import { nginxRequestRate } from './nginx/nginx_request_rate'; -import { nginxRequestsPerConnection } from './nginx/nginx_requests_per_connection'; - -import { awsOverview } from './aws/aws_overview'; -import { awsCpuUtilization } from './aws/aws_cpu_utilization'; -import { awsNetworkBytes } from './aws/aws_network_bytes'; -import { awsNetworkPackets } from './aws/aws_network_packets'; -import { awsDiskioBytes } from './aws/aws_diskio_bytes'; -import { awsDiskioOps } from './aws/aws_diskio_ops'; - -interface InfraMetricModels { - [key: string]: InfraMetricModelCreator; -} - -export const metricModels: InfraMetricModels = { - [InfraMetric.hostSystemOverview]: hostSystemOverview, - [InfraMetric.hostCpuUsage]: hostCpuUsage, - [InfraMetric.hostFilesystem]: hostFilesystem, - [InfraMetric.hostK8sOverview]: hostK8sOverview, - [InfraMetric.hostK8sCpuCap]: hostK8sCpuCap, - [InfraMetric.hostK8sDiskCap]: hostK8sDiskCap, - [InfraMetric.hostK8sMemoryCap]: hostK8sMemoryCap, - [InfraMetric.hostK8sPodCap]: hostK8sPodCap, - [InfraMetric.hostLoad]: hostLoad, - [InfraMetric.hostMemoryUsage]: hostMemoryUsage, - [InfraMetric.hostNetworkTraffic]: hostNetworkTraffic, - [InfraMetric.hostDockerOverview]: hostDockerOverview, - [InfraMetric.hostDockerInfo]: hostDockerInfo, - [InfraMetric.hostDockerTop5ByCpu]: hostDockerTop5ByCpu, - [InfraMetric.hostDockerTop5ByMemory]: hostDockerTop5ByMemory, - - [InfraMetric.podOverview]: podOverview, - [InfraMetric.podCpuUsage]: podCpuUsage, - [InfraMetric.podMemoryUsage]: podMemoryUsage, - [InfraMetric.podLogUsage]: podLogUsage, - [InfraMetric.podNetworkTraffic]: podNetworkTraffic, - - [InfraMetric.containerCpuKernel]: containerCpuKernel, - [InfraMetric.containerCpuUsage]: containerCpuUsage, - [InfraMetric.containerDiskIOBytes]: containerDiskIOBytes, - [InfraMetric.containerDiskIOOps]: containerDiskIOOps, - [InfraMetric.containerNetworkTraffic]: containerNetworkTraffic, - [InfraMetric.containerMemory]: containerMemory, - [InfraMetric.containerOverview]: containerOverview, - [InfraMetric.nginxHits]: nginxHits, - [InfraMetric.nginxRequestRate]: nginxRequestRate, - [InfraMetric.nginxActiveConnections]: nginxActiveConnections, - [InfraMetric.nginxRequestsPerConnection]: nginxRequestsPerConnection, - - [InfraMetric.awsOverview]: awsOverview, - [InfraMetric.awsCpuUtilization]: awsCpuUtilization, - [InfraMetric.awsNetworkBytes]: awsNetworkBytes, - [InfraMetric.awsNetworkPackets]: awsNetworkPackets, - [InfraMetric.awsDiskioBytes]: awsDiskioBytes, - [InfraMetric.awsDiskioOps]: awsDiskioOps, -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/cpu.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/cpu.ts deleted file mode 100644 index e0a44ef9036e1..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/cpu.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; - -const FIELDS = { - [InfraNodeType.host]: 'system.cpu.user.pct', - [InfraNodeType.pod]: 'kubernetes.pod.cpu.usage.node.pct', - [InfraNodeType.container]: 'docker.cpu.total.pct', -}; - -export const cpu = (nodeType: InfraNodeType) => { - if (nodeType === InfraNodeType.host) { - return { - cpu_user: { - avg: { - field: 'system.cpu.user.pct', - }, - }, - cpu_system: { - avg: { - field: 'system.cpu.system.pct', - }, - }, - cpu_cores: { - max: { - field: 'system.cpu.cores', - }, - }, - cpu: { - bucket_script: { - buckets_path: { - user: 'cpu_user', - system: 'cpu_system', - cores: 'cpu_cores', - }, - script: { - source: '(params.user + params.system) / params.cores', - lang: 'painless', - }, - gap_policy: 'skip', - }, - }, - }; - } else { - return { - cpu: { - avg: { - field: FIELDS[nodeType], - }, - }, - }; - } -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/index.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/index.ts deleted file mode 100644 index e4c321324a9a9..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraSnapshotMetricType } from '../../../graphql/types'; -import { count } from './count'; -import { cpu } from './cpu'; -import { load } from './load'; -import { logRate } from './log_rate'; -import { memory } from './memory'; -import { rx } from './rx'; -import { tx } from './tx'; - -export const metricAggregationCreators = { - [InfraSnapshotMetricType.count]: count, - [InfraSnapshotMetricType.cpu]: cpu, - [InfraSnapshotMetricType.memory]: memory, - [InfraSnapshotMetricType.rx]: rx, - [InfraSnapshotMetricType.tx]: tx, - [InfraSnapshotMetricType.load]: load, - [InfraSnapshotMetricType.logRate]: logRate, -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/load.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/load.ts deleted file mode 100644 index 3a5b97a36e7cd..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/load.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; - -const FIELDS = { - [InfraNodeType.host]: 'system.load.5', - [InfraNodeType.pod]: '', - [InfraNodeType.container]: '', -}; - -export const load = (nodeType: InfraNodeType) => { - const field = FIELDS[nodeType]; - if (field) { - return { load: { avg: { field } } }; - } -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/memory.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/memory.ts deleted file mode 100644 index fec0c0ede3438..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/memory.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; - -const FIELDS = { - [InfraNodeType.host]: 'system.memory.actual.used.pct', - [InfraNodeType.pod]: 'kubernetes.pod.memory.usage.node.pct', - [InfraNodeType.container]: 'docker.memory.usage.pct', -}; - -export const memory = (nodeType: InfraNodeType) => { - return { memory: { avg: { field: FIELDS[nodeType] } } }; -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/network_traffic.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/network_traffic.ts deleted file mode 100644 index da9e48c334e78..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/network_traffic.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; -import { rate } from './rate'; - -interface MetricFields { - [InfraNodeType.container]: string; - [InfraNodeType.pod]: string; - [InfraNodeType.host]: string; -} - -interface InterfaceFields { - [InfraNodeType.container]: string; - [InfraNodeType.pod]: null; - [InfraNodeType.host]: string; -} - -export const networkTraffic = ( - id: string, - metricFields: MetricFields, - interfaceFields: InterfaceFields -) => { - const rateAggregations = rate(id, metricFields); - return (nodeType: InfraNodeType) => { - // Metricbeat doesn't collect interface data for Kubernetes Pods, - // for these we'll use a standard rate calculation. - if (nodeType === InfraNodeType.pod) { - return rateAggregations(nodeType); - } - const metricField = metricFields[nodeType]; - const interfaceField = interfaceFields[nodeType]; - - if (metricField && interfaceField) { - return { - [`${id}_interfaces`]: { - terms: { field: interfaceField }, - aggregations: { - [`${id}_interface_max`]: { max: { field: metricField } }, - }, - }, - [`${id}_sum_of_interfaces`]: { - sum_bucket: { - buckets_path: `${id}_interfaces>${id}_interface_max`, - }, - }, - [`${id}_deriv`]: { - derivative: { - buckets_path: `${id}_sum_of_interfaces`, - gap_policy: 'skip', - unit: '1s', - }, - }, - [id]: { - bucket_script: { - buckets_path: { value: `${id}_deriv[normalized_value]` }, - script: { - source: 'params.value > 0.0 ? params.value : 0.0', - lang: 'painless', - }, - gap_policy: 'skip', - }, - }, - }; - } - }; -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/rate.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/rate.ts deleted file mode 100644 index 4024fa7563bef..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/rate.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; - -interface Fields { - [InfraNodeType.container]: string; - [InfraNodeType.pod]: string; - [InfraNodeType.host]: string; -} - -export const rate = (id: string, fields: Fields) => { - return (nodeType: InfraNodeType) => { - const field = fields[nodeType]; - if (field) { - return { - [`${id}_max`]: { max: { field } }, - [`${id}_deriv`]: { - derivative: { - buckets_path: `${id}_max`, - gap_policy: 'skip', - unit: '1s', - }, - }, - [id]: { - bucket_script: { - buckets_path: { value: `${id}_deriv[normalized_value]` }, - script: { - source: 'params.value > 0.0 ? params.value : 0.0', - lang: 'painless', - }, - gap_policy: 'skip', - }, - }, - }; - } - }; -}; diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/rx.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/rx.ts deleted file mode 100644 index 71b7897e38b7c..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/rx.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; -import { networkTraffic } from './network_traffic'; - -const METRIC_FIELDS = { - [InfraNodeType.host]: 'system.network.in.bytes', - [InfraNodeType.pod]: 'kubernetes.pod.network.rx.bytes', - [InfraNodeType.container]: 'docker.network.in.bytes', -}; - -const INTERFACE_FIELDS = { - [InfraNodeType.host]: 'system.network.name', - [InfraNodeType.pod]: null, - [InfraNodeType.container]: 'docker.network.interface', -}; - -export const rx = networkTraffic('rx', METRIC_FIELDS, INTERFACE_FIELDS); diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/tx.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/tx.ts deleted file mode 100644 index 119329ee5649f..0000000000000 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/metric_aggregation_creators/tx.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { InfraNodeType } from '../../../graphql/types'; -import { networkTraffic } from './network_traffic'; - -const METRIC_FIELDS = { - [InfraNodeType.host]: 'system.network.out.bytes', - [InfraNodeType.pod]: 'kubernetes.pod.network.tx.bytes', - [InfraNodeType.container]: 'docker.network.out.bytes', -}; - -const INTERFACE_FIELDS = { - [InfraNodeType.host]: 'system.network.name', - [InfraNodeType.pod]: null, - [InfraNodeType.container]: 'docker.network.interface', -}; - -export const tx = networkTraffic('tx', METRIC_FIELDS, INTERFACE_FIELDS); diff --git a/x-pack/legacy/plugins/infra/server/lib/snapshot/query_helpers.ts b/x-pack/legacy/plugins/infra/server/lib/snapshot/query_helpers.ts index 076cd9e03c557..6ebbe8775562c 100644 --- a/x-pack/legacy/plugins/infra/server/lib/snapshot/query_helpers.ts +++ b/x-pack/legacy/plugins/infra/server/lib/snapshot/query_helpers.ts @@ -4,10 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { metricAggregationCreators } from './metric_aggregation_creators'; +import { get } from 'lodash'; +import { i18n } from '@kbn/i18n'; +import { findInventoryModel } from '../../../common/inventory_models/index'; import { InfraSnapshotRequestOptions } from './snapshot'; import { NAME_FIELDS } from '../constants'; import { getIntervalInSeconds } from '../../utils/get_interval_in_seconds'; +import { SnapshotModelRT, SnapshotModel } from '../../../common/inventory_models/types'; interface GroupBySource { [id: string]: { @@ -37,8 +40,21 @@ export const getMetricsSources = (options: InfraSnapshotRequestOptions) => { return [{ id: { terms: { field: options.sourceConfiguration.fields[options.nodeType] } } }]; }; -export const getMetricsAggregations = (options: InfraSnapshotRequestOptions) => { - return metricAggregationCreators[options.metric.type](options.nodeType); +export const getMetricsAggregations = (options: InfraSnapshotRequestOptions): SnapshotModel => { + const model = findInventoryModel(options.nodeType); + const aggregation = get(model, ['metrics', 'snapshot', options.metric.type]); + if (!SnapshotModelRT.is(aggregation)) { + throw new Error( + i18n.translate('xpack.infra.snapshot.missingSnapshotMetricError', { + defaultMessage: 'The aggregation for {metric} for {nodeType} is not available.', + values: { + nodeType: options.nodeType, + metric: options.metric.type, + }, + }) + ); + } + return aggregation; }; export const getDateHistogramOffset = (options: InfraSnapshotRequestOptions): string => { diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts b/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts index dd8e0edad7672..6b7f85f7e5952 100644 --- a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts +++ b/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/lib/create_metrics_model.ts @@ -4,10 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { InfraMetricModel, InfraMetricModelMetricType } from '../../../lib/adapters/metrics'; +import { InfraMetricModelMetricType } from '../../../lib/adapters/metrics'; import { MetricsExplorerAggregation, MetricsExplorerRequest } from '../types'; import { InfraMetric } from '../../../graphql/types'; -export const createMetricModel = (options: MetricsExplorerRequest): InfraMetricModel => { +import { TSVBMetricModel } from '../../../../common/inventory_models/types'; +export const createMetricModel = (options: MetricsExplorerRequest): TSVBMetricModel => { return { id: InfraMetric.custom, requires: [], @@ -20,7 +21,7 @@ export const createMetricModel = (options: MetricsExplorerRequest): InfraMetricM series: options.metrics.map((metric, index) => { // If the metric is a rate then we need to add TSVB metrics for calculating the derivative if (metric.aggregation === MetricsExplorerAggregation.rate) { - const aggType = InfraMetricModelMetricType.max; + const aggType = 'max'; return { id: `metric_${index}`, split_mode: 'everything', @@ -33,12 +34,12 @@ export const createMetricModel = (options: MetricsExplorerRequest): InfraMetricM { id: `metric_deriv_${aggType}_${index}`, field: `metric_${aggType}_${index}`, - type: InfraMetricModelMetricType.derivative, + type: 'derivative', unit: '1s', }, { id: `metric_posonly_deriv_${aggType}_${index}`, - type: InfraMetricModelMetricType.calculation, + type: 'calculation', variables: [ { id: 'var-rate', name: 'rate', field: `metric_deriv_${aggType}_${index}` }, ], diff --git a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/types.ts b/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/types.ts index e4a4ab40ceb1a..b29c41fcbff18 100644 --- a/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/types.ts +++ b/x-pack/legacy/plugins/infra/server/routes/metrics_explorer/types.ts @@ -24,7 +24,7 @@ export enum MetricsExplorerAggregation { export interface MetricsExplorerMetric { aggregation: MetricsExplorerAggregation; - field?: string | null; + field?: string | undefined; } export interface MetricsExplorerRequest { diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index a5c950a3f2be0..08812ab876f8d 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -5947,7 +5947,6 @@ "xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.memoryCapacitySeriesLabel": "メモリー使用状況", "xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.outboundTXSeriesLabel": "送信 (TX)", "xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.sectionLabel": "概要", - "xpack.infra.metricDetailPage.invalidNodeTypeErrorMessage": "{nodeType} は有効なノードタイプではありません", "xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeCpuCapacitySection.sectionLabel": "ノード CPU 処理能力", "xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeDiskCapacitySection.sectionLabel": "ノードディスク容量", "xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeMemoryCapacitySection.sectionLabel": "ノードメモリー容量", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index bb876ca1eb8b9..ad680f2fb7307 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -5949,7 +5949,6 @@ "xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.memoryCapacitySeriesLabel": "内存利用率", "xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.outboundTXSeriesLabel": "出站 (TX)", "xpack.infra.metricDetailPage.hostMetricsLayout.overviewSection.sectionLabel": "概览", - "xpack.infra.metricDetailPage.invalidNodeTypeErrorMessage": "{nodeType} 不是有效的节点类型", "xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeCpuCapacitySection.sectionLabel": "节点 CPU 容量", "xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeDiskCapacitySection.sectionLabel": "节点磁盘容量", "xpack.infra.metricDetailPage.kubernetesMetricsLayout.nodeMemoryCapacitySection.sectionLabel": "节点内存容量",