Skip to content

Commit

Permalink
Add metrics for OS and OSD processes (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Dec 13, 2023
1 parent 68679fc commit 5ea6747
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
31 changes: 24 additions & 7 deletions lib/cloudwatch/metrics-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,35 @@ The OpenSearch Contributors require contributions made to
this file be licensed under the Apache-2.0 license or a
compatible open source license. */

import { Unit } from 'aws-cdk-lib/aws-cloudwatch';

type MeasurementDefinition = string | { name: string, rename?: string, unit?: Unit }

interface MetricDefinition {
measurement: string[];
}
resources?: string[],
measurement: MeasurementDefinition[],
// eslint-disable-next-line camelcase
metrics_collection_interval?: number,
}

export interface ProcstatMetricDefinition {
pattern?: string;
// eslint-disable-next-line camelcase
append_dimensions?: string[];
measurement: string[]; // procstat does not support the common measurement standard for rename/unit
// eslint-disable-next-line camelcase
metrics_collection_interval: number;
}

interface EditableCloudwatchMetricsSection {
// eslint-disable-next-line camelcase
metrics_collected: {
cpu: MetricDefinition,
disk: MetricDefinition,
diskio: MetricDefinition,
mem: MetricDefinition,
net: MetricDefinition,
procstat?: ProcstatMetricDefinition[],
cpu?: MetricDefinition,
disk?: MetricDefinition,
diskio?: MetricDefinition,
mem?: MetricDefinition,
net?: MetricDefinition,
};
}

Expand Down
39 changes: 37 additions & 2 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import {
AutoScalingGroup, BlockDeviceVolume, EbsDeviceVolumeType, Signals,
} from 'aws-cdk-lib/aws-autoscaling';
import { Unit } from 'aws-cdk-lib/aws-cloudwatch';
import {
AmazonLinuxCpuType,
AmazonLinuxGeneration,
Expand Down Expand Up @@ -38,6 +39,7 @@ import { readFileSync } from 'fs';
import { dump, load } from 'js-yaml';
import { join } from 'path';
import { CloudwatchAgent } from '../cloudwatch/cloudwatch-agent';
import { ProcstatMetricDefinition } from '../cloudwatch/metrics-section';
import { nodeConfig } from '../opensearch-config/node-config';
import { RemoteStoreResources } from './remote-store-resources';

Expand Down Expand Up @@ -375,6 +377,23 @@ export class InfraStack extends Stack {
private static getCfnInitElement(scope: Stack, logGroup: LogGroup, props: infraProps, nodeType?: string): InitElement[] {
const configFileDir = join(__dirname, '../opensearch-config');
let opensearchConfig: string;
const procstatConfig: ProcstatMetricDefinition[] = [{
pattern: '-Dopensearch',
measurement: [
'pid_count',
],
metrics_collection_interval: 10,
},
];
if (props.dashboardsUrl !== 'undefined') {
procstatConfig.push({
pattern: 'opensearch-dashboards',
measurement: [
'pid_count',
],
metrics_collection_interval: 15,
});
}

const cfnInitConfig: InitElement[] = [
InitPackage.yum('amazon-cloudwatch-agent'),
Expand All @@ -388,6 +407,7 @@ export class InfraStack extends Stack {
},
metrics: {
metrics_collected: {
procstat: procstatConfig,
cpu: {
measurement: [
// eslint-disable-next-line max-len
Expand All @@ -396,7 +416,13 @@ export class InfraStack extends Stack {
},
disk: {
measurement: [
'free', 'total', 'used', 'used_percent', 'inodes_free', 'inodes_used', 'inodes_total',
{ name: 'free', unit: Unit.PERCENT },
{ name: 'total', unit: Unit.PERCENT },
{ name: 'used', unit: Unit.PERCENT },
{ name: 'used_percent', unit: Unit.PERCENT },
{ name: 'inodes_free', unit: Unit.PERCENT },
{ name: 'inodes_used', unit: Unit.PERCENT },
{ name: 'inodes_total', unit: Unit.PERCENT },
],
},
diskio: {
Expand All @@ -406,7 +432,16 @@ export class InfraStack extends Stack {
},
mem: {
measurement: [
'active', 'available', 'available_percent', 'buffered', 'cached', 'free', 'inactive', 'total', 'used', 'used_percent',
{ name: 'active', unit: Unit.PERCENT },
{ name: 'available', unit: Unit.PERCENT },
{ name: 'available_percent', unit: Unit.PERCENT },
{ name: 'buffered', unit: Unit.PERCENT },
{ name: 'cached', unit: Unit.PERCENT },
{ name: 'free', unit: Unit.PERCENT },
{ name: 'inactive', unit: Unit.PERCENT },
{ name: 'total', unit: Unit.PERCENT },
{ name: 'used', unit: Unit.PERCENT },
{ name: 'used_percent', unit: Unit.PERCENT },
],
},
net: {
Expand Down

0 comments on commit 5ea6747

Please sign in to comment.