Skip to content

Commit

Permalink
[WIP] Add nginx section
Browse files Browse the repository at this point in the history
  • Loading branch information
jennypavlova committed Aug 30, 2023
1 parent 030fa9e commit a319b1d
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
memoryUsed,
memoryFreeExcludingCache,
memoryCache,
nginxActiveConnections,
nginxRequestRate,
rx,
tx,
hostCount,
Expand Down Expand Up @@ -63,6 +65,8 @@ export const hostLensFormulas = {
memoryUsed,
memoryFreeExcludingCache,
memoryCache,
nginxActiveConnections,
nginxRequestRate,
rx,
tx,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { nginxActiveConnections, nginxRequestRate } from '../metric_charts/nginx';
import type { XYConfig } from '../metric_charts/types';

export const nginxStubstatusMetrics: XYConfig[] = [nginxActiveConnections, nginxRequestRate];

export const nginxAccessMetrics: XYConfig[] = []; // TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { hostLensFormulas } from '../../../../constants';
import { XY_OVERRIDES } from '../../constants';
import type { XYConfig } from './types';

export const nginxRequestRate: XYConfig = {
id: 'RequestRate',
title: i18n.translate('xpack.infra.assetDetails.metricsCharts.nginx.requestRate', {
defaultMessage: 'Request Rate',
}),

layers: [
{
data: [hostLensFormulas.nginxRequestRate],
type: 'visualization',
},
],
dataViewOrigin: 'metrics',
overrides: {
axisLeft: XY_OVERRIDES.axisLeft,
},
};

export const nginxActiveConnections: XYConfig = {
id: 'ActiveConnections',
title: i18n.translate('xpack.infra.assetDetails.metricsCharts.nginx.ActiveConnections', {
defaultMessage: 'Active Connections',
}),

layers: [
{
data: [hostLensFormulas.nginxActiveConnections],
type: 'visualization',
},
],
dataViewOrigin: 'metrics',
overrides: {
axisLeft: XY_OVERRIDES.axisLeft,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ export { memoryFree } from './memory_free';
export { memoryUsed } from './memory_used';
export { memoryFreeExcludingCache } from './memory_free_excluding_cache';
export { memoryCache } from './memory_cache';
export { nginxRequestRate } from './nginx_request_rate';
export { nginxActiveConnections } from './nginx_active_connections';
export { rx } from './rx';
export { tx } from './tx';
Original file line number Diff line number Diff line change
@@ -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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { FormulaValueConfig } from '@kbn/lens-embeddable-utils';

export const nginxActiveConnections: FormulaValueConfig = {
label: 'Active Connections',
value: 'average(nginx.stubstatus.active)',
format: {
id: 'number',
params: {
decimals: 0,
},
},
};
Original file line number Diff line number Diff line change
@@ -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
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { FormulaValueConfig } from '@kbn/lens-embeddable-utils';

export const nginxRequestRate: FormulaValueConfig = {
label: 'Request Rate',
value: 'max(nginx.stubstatus.requests)', // TODO
format: {
id: 'number',
params: {
decimals: 0,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type { DataView } from '@kbn/data-views-plugin/public';
import type { TimeRange } from '@kbn/es-query';
import { FormattedMessage } from '@kbn/i18n-react';
import { LensEmbeddableInput } from '@kbn/lens-plugin/public';
import {
nginxStubstatusMetrics,
nginxAccessMetrics,
} from '../../../../../common/visualizations/lens/dashboards/asset_details/host/nginx_charts';
import {
assetDetailsDashboards,
XY_MISSING_VALUE_DOTTED_LINE_CONFIG,
Expand All @@ -30,10 +34,20 @@ interface Props {
metricsDataView?: DataView;
logsDataView?: DataView;
isCompactView: boolean;
showNginxStubstatus: boolean;
showNginxAccess: boolean;
}

export const MetricsGrid = React.memo(
({ nodeName, metricsDataView, logsDataView, timeRange, isCompactView }: Props) => {
({
nodeName,
metricsDataView,
logsDataView,
timeRange,
isCompactView,
showNginxStubstatus,
showNginxAccess,
}: Props) => {
const { setDateRange } = useDateRangeProviderContext();
const getDataView = useCallback(
(dataViewOrigin: DataViewOrigin) => {
Expand All @@ -42,6 +56,9 @@ export const MetricsGrid = React.memo(
[logsDataView, metricsDataView]
);

const nginxStubstatusCharts = showNginxStubstatus ? nginxStubstatusMetrics : [];
const nginxAccessCharts = showNginxAccess ? nginxAccessMetrics : [];

const getFilters = useCallback(
(dataViewOrigin: DataViewOrigin) => {
return [
Expand Down Expand Up @@ -81,7 +98,11 @@ export const MetricsGrid = React.memo(
>
{(isCompactView
? assetDetailsDashboards.host.hostMetricCharts
: assetDetailsDashboards.host.hostMetricChartsFullPage
: [
...assetDetailsDashboards.host.hostMetricChartsFullPage,
// ...nginxStubstatusCharts,
// ...nginxAccessCharts,
]
).map(({ dataViewOrigin, id, layers, title, overrides }, index) => (
<EuiFlexItem key={index} grow={false}>
<LensChart
Expand All @@ -102,6 +123,49 @@ export const MetricsGrid = React.memo(
))}
</EuiFlexGrid>
</EuiFlexItem>
{!isCompactView && (
<>
<EuiFlexItem grow={false}>
<EuiTitle size="xxs">
<span>
<FormattedMessage
id="xpack.infra.assetDetails.overview.nginxMetricsSectionTitle"
defaultMessage="Nginx Metrics"
/>
</span>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiSpacer size="s" />
<EuiFlexGrid
columns={2}
gutterSize="s"
data-test-subj="infraAssetDetailsMetricsChartGrid"
>
{[...nginxStubstatusCharts, ...nginxAccessCharts].map(
({ dataViewOrigin, id, layers, title, overrides }, index) => (
<EuiFlexItem key={index} grow={false}>
<LensChart
id={`infraAssetDetailsMetricsChart${id}`}
borderRadius="m"
dataView={getDataView(dataViewOrigin)}
dateRange={timeRange}
height={METRIC_CHART_HEIGHT}
visualOptions={XY_MISSING_VALUE_DOTTED_LINE_CONFIG}
layers={layers}
filters={getFilters(dataViewOrigin)}
title={title}
overrides={overrides}
visualizationType="lnsXY"
onBrushEnd={handleBrushEnd}
/>
</EuiFlexItem>
)
)}
</EuiFlexGrid>
</EuiFlexItem>
</>
)}
</EuiFlexGroup>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export const Overview = () => {
metricsDataView={metrics.dataView}
nodeName={asset.name}
isCompactView={renderMode?.mode === 'flyout'}
showNginxStubstatus={
!!metadata?.features.find((feature) => feature.name === 'nginx.stubstatus')
}
showNginxAccess={!!metadata?.features.find((feature) => feature.name === 'nginx.acces')}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down

0 comments on commit a319b1d

Please sign in to comment.