Skip to content

Commit

Permalink
Changed cpu and memory metric stat to avg (#173)
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Singh <[email protected]>
  • Loading branch information
rishabh6788 authored Jul 27, 2022
1 parent 4da4009 commit 72273fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/compute/jenkins-main-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class JenkinsMainNode {
metrics_collected: {
procstat: [
{
pattern: 'jenkins',
pattern: 'Djenkins',
measurement: [
'cpu_usage',
'cpu_time_system',
Expand Down
4 changes: 2 additions & 2 deletions lib/monitoring/ci-alarms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class JenkinsMonitoring {

this.alarms.push(new Alarm(stack, 'MainNodeHighCpuUtilization', {
alarmDescription: 'The jenkins process is using much more CPU that expected, it should be investigated for a stuck process/job',
metric: mainNode.ec2InstanceMetrics.cpuTime.with({ statistic: 'max' }),
metric: mainNode.ec2InstanceMetrics.cpuTime.with({ statistic: 'avg' }),
evaluationPeriods: 5,
threshold: 50,
comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
Expand All @@ -48,7 +48,7 @@ export class JenkinsMonitoring {

this.alarms.push(new Alarm(stack, 'MainNodeHighMemoryUtilization', {
alarmDescription: 'The jenkins process is using more memory than expected, it should be investigated for a large number of jobs or heavy weight jobs',
metric: mainNode.ec2InstanceMetrics.memUsed.with({ statistic: 'max' }),
metric: mainNode.ec2InstanceMetrics.memUsed.with({ statistic: 'avg' }),
evaluationPeriods: 5,
threshold: 50,
comparisonOperator: ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
Expand Down
31 changes: 31 additions & 0 deletions test/ci-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ test('CI Stack Basic Resources', () => {
expect(stack).to(countResources('AWS::SSM::Document', 1));
expect(stack).to(countResources('AWS::SSM::Association', 1));
expect(stack).to(countResources('AWS::EFS::FileSystem', 1));
expect(stack).to(countResources('AWS::CloudWatch::Alarm', 5));
});

test('External security group is open', () => {
Expand Down Expand Up @@ -141,3 +142,33 @@ test('LoadBalancer', () => {
],
}, ResourcePart.Properties));
});

test('CloudwatchCpuAlarm', () => {
const app = new App({
context: { useSsl: 'false', runWithOidc: 'false' },
});

// WHEN
const stack = new CIStack(app, 'MyTestStack', {});

// THEN
expect(stack).to(haveResourceLike('AWS::CloudWatch::Alarm', {
MetricName: 'procstat_cpu_usage',
Statistic: 'Average',
}, ResourcePart.Properties));
});

test('CloudwatchMemoryAlarm', () => {
const app = new App({
context: { useSsl: 'false', runWithOidc: 'false' },
});

// WHEN
const stack = new CIStack(app, 'MyTestStack', {});

// THEN
expect(stack).to(haveResourceLike('AWS::CloudWatch::Alarm', {
MetricName: 'mem_used_percent',
Statistic: 'Average',
}, ResourcePart.Properties));
});

0 comments on commit 72273fa

Please sign in to comment.