Skip to content

Commit 4957e47

Browse files
feat(ec2): Also plot EBS disk metrics when NITRO instance type is specified (#321)
EC2 provides different metrics for Nitro-based instances. These metrics have the prefix `EBS`. These instances either have the `Disk*` or `EBSDisk*` metrics, never both. Because of this I thought in using [metric math](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html) where if any of the time series is empty, it would be removed, and then it would display a single metric. This gets trickier when monitoring an ASG because it can have both metrics there, so what should be done with the 2 time series? An average of them? If you think this would be a better idea, please advise so I change the implementation. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 4217bb9 commit 4957e47

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

API.md

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/monitoring/aws-ec2/EC2MetricFactory.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class EC2MetricFactory {
161161
* This can be used to determine the speed of the application.
162162
*/
163163
metricAverageDiskReadBytes() {
164-
return this.createMetrics("DiskReadBytes", MetricStatistic.AVERAGE);
164+
return this.createDiskMetrics("ReadBytes", MetricStatistic.AVERAGE);
165165
}
166166

167167
/**
@@ -170,21 +170,21 @@ export class EC2MetricFactory {
170170
* This can be used to determine the speed of the application.
171171
*/
172172
metricAverageDiskWriteBytes() {
173-
return this.createMetrics("DiskWriteBytes", MetricStatistic.AVERAGE);
173+
return this.createDiskMetrics("WriteBytes", MetricStatistic.AVERAGE);
174174
}
175175

176176
/**
177177
* Completed read operations from all instance store volumes available to the instance in a specified period of time.
178178
*/
179179
metricAverageDiskReadOps() {
180-
return this.createMetrics("DiskReadOps", MetricStatistic.AVERAGE);
180+
return this.createDiskMetrics("ReadOps", MetricStatistic.AVERAGE);
181181
}
182182

183183
/**
184184
* Completed write operations to all instance store volumes available to the instance in a specified period of time.
185185
*/
186186
metricAverageDiskWriteOps() {
187-
return this.createMetrics("DiskWriteOps", MetricStatistic.AVERAGE);
187+
return this.createDiskMetrics("WriteOps", MetricStatistic.AVERAGE);
188188
}
189189

190190
/**
@@ -203,6 +203,33 @@ export class EC2MetricFactory {
203203
return this.createMetrics("NetworkOut", MetricStatistic.AVERAGE);
204204
}
205205

206+
private createDiskMetrics(metricName: string, statistic: MetricStatistic) {
207+
const classicMetrics = this.strategy.createMetrics(
208+
this.metricFactory,
209+
`Disk${metricName}`,
210+
statistic
211+
);
212+
const ebsMetrics = this.strategy.createMetrics(
213+
this.metricFactory,
214+
`EBS${metricName}`,
215+
statistic
216+
);
217+
218+
return classicMetrics.map((classic, i) => {
219+
const ebs = ebsMetrics[i];
220+
const usingMetrics: Record<string, IMetric> = {};
221+
const classicId = `${metricName.toLowerCase()}_classic_${i}`;
222+
const ebsId = `${metricName.toLowerCase()}_ebs_${i}`;
223+
usingMetrics[classicId] = classic;
224+
usingMetrics[ebsId] = ebs;
225+
return this.metricFactory.createMetricMath(
226+
`AVG(REMOVE_EMPTY([${classicId}, ${ebsId}]))`,
227+
usingMetrics,
228+
`Disk${metricName}`
229+
);
230+
});
231+
}
232+
206233
private createMetrics(metricName: string, statistic: MetricStatistic) {
207234
return this.strategy.createMetrics(
208235
this.metricFactory,

test/facade/__snapshots__/MonitoringAspect.test.ts.snap

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)