Skip to content

Commit

Permalink
Add metrics for cloud watch agent (opensearch-project#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Suraj Singh <[email protected]>
  • Loading branch information
dreamer-89 authored Feb 28, 2023
1 parent 1184e2c commit 2885928
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/cloudwatch/cloudwatch-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ compatible open source license. */
import { InitFile, InitFileOptions } from 'aws-cdk-lib/aws-ec2';
import { CloudwatchAgentSection } from './agent-section';
import { CloudwatchLogsSection } from './logs-section';
import { CloudwatchMetricsSection } from "./metrics-section";

export interface CloudwatchAgentConfig {
agent: CloudwatchAgentSection,
metrics: CloudwatchMetricsSection
logs: CloudwatchLogsSection
}

Expand Down
44 changes: 44 additions & 0 deletions lib/cloudwatch/metrics-section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright OpenSearch Contributors
SPDX-License-Identifier: Apache-2.0
The OpenSearch Contributors require contributions made to
this file be licensed under the Apache-2.0 license or a
compatible open source license. */

interface MetricDefinition {
measurement: string[];
}

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

/**
* Cloudwatch configuration - Metrics Section
*
* See definition at https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Metricssection
*
* Example configuration:
* ```
* metrics: {
* metrics_collected: {
* "cpu": {
* "measurement": [
* "cpu_usage_idle",
* "cpu_usage_nice",
* "cpu_usage_guest",
* ],
* },
* }
* metrics_collection_interval: 60, // seconds between collections
* }
* ```
*/
export type CloudwatchMetricsSection = Readonly<EditableCloudwatchMetricsSection>;
30 changes: 30 additions & 0 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,36 @@ export class InfraStack extends Stack {
omit_hostname: true,
debug: false,
},
metrics: {
metrics_collected: {
cpu: {
measurement: [
// eslint-disable-next-line max-len
'usage_active', 'usage_guest', 'usage_guest_nice', 'usage_idle', 'usage_iowait', 'usage_irq', 'usage_nice', 'usage_softirq', 'usage_steal', 'usage_system', 'usage_user', 'time_active', 'time_iowait', 'time_system', 'time_user'
],
},
disk: {
measurement: [
'free', 'total', 'used', 'used_percent', 'inodes_free', 'inodes_used', 'inodes_total',
],
},
diskio: {
measurement: [
'reads', 'writes', 'read_bytes', 'write_bytes', 'read_time', 'write_time', 'io_time',
],
},
mem: {
measurement: [
'active', 'available', 'available_percent', 'buffered', 'cached', 'free', 'inactive', 'total', 'used', 'used_percent',
],
},
net: {
measurement: [
'bytes_sent', 'bytes_recv', 'drop_in', 'drop_out', 'err_in', 'err_out', 'packets_sent', 'packets_recv',
],
},
},
},
logs: {
logs_collected: {
files: {
Expand Down

0 comments on commit 2885928

Please sign in to comment.