11import {
2+ Column ,
23 GraphWidget ,
34 HorizontalAnnotation ,
45 IWidget ,
@@ -13,6 +14,7 @@ import {
1314 BaseMonitoringProps ,
1415 CountAxisFromZero ,
1516 DefaultGraphWidgetHeight ,
17+ DefaultTwoLinerGraphWidgetHalfHeight ,
1618 DefaultSummaryWidgetHeight ,
1719 ElastiCacheAlarmFactory ,
1820 MaxItemsCountThreshold ,
@@ -42,10 +44,18 @@ export interface ElastiCacheClusterMonitoringOptions
4244 readonly clusterType : ElastiCacheClusterType ;
4345
4446 /**
45- * Add CPU usage alarm
47+ * Add CPU usage alarm (useful for all clusterTypes including Redis)
4648 */
4749 readonly addCpuUsageAlarm ?: Record < string , UsageThreshold > ;
4850
51+ /**
52+ * Add Redis engine CPU usage alarm.
53+ *
54+ * It is recommended to monitor CPU utilization with `addCpuUsageAlarm`
55+ * as well for hosts with two vCPUs or less.
56+ */
57+ readonly addRedisEngineCpuUsageAlarm ?: Record < string , UsageThreshold > ;
58+
4959 /**
5060 * Add alarm on total number of items
5161 */
@@ -81,9 +91,11 @@ export interface ElastiCacheClusterMonitoringProps
8191export class ElastiCacheClusterMonitoring extends Monitoring {
8292 readonly title : string ;
8393 readonly clusterUrl ?: string ;
94+ readonly clusterType : ElastiCacheClusterType ;
8495
8596 readonly connectionsMetric : MetricWithAlarmSupport ;
8697 readonly cpuUsageMetric : MetricWithAlarmSupport ;
98+ readonly redisEngineCpuUsageMetric : MetricWithAlarmSupport ;
8799 readonly freeableMemoryMetric : MetricWithAlarmSupport ;
88100 readonly unusedMemoryMetric : MetricWithAlarmSupport ;
89101 readonly swapMemoryMetric : MetricWithAlarmSupport ;
@@ -94,6 +106,7 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
94106 readonly usageAlarmFactory : UsageAlarmFactory ;
95107 readonly elastiCacheAlarmFactory : ElastiCacheAlarmFactory ;
96108 readonly cpuUsageAnnotations : HorizontalAnnotation [ ] ;
109+ readonly redisEngineCpuUsageAnnotations : HorizontalAnnotation [ ] ;
97110 readonly itemsCountAnnotations : HorizontalAnnotation [ ] ;
98111 readonly evictedItemsCountAnnotations : HorizontalAnnotation [ ] ;
99112 readonly memoryUsageAnnotations : HorizontalAnnotation [ ] ;
@@ -104,6 +117,8 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
104117 ) {
105118 super ( scope , props ) ;
106119
120+ this . clusterType = props . clusterType ;
121+
107122 const clusterType = capitalizeFirstLetterOnly (
108123 ElastiCacheClusterType [ props . clusterType ]
109124 ) ;
@@ -127,6 +142,8 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
127142 ) ;
128143 this . connectionsMetric = metricFactory . metricAverageConnections ( ) ;
129144 this . cpuUsageMetric = metricFactory . metricMaxCpuUtilizationInPercent ( ) ;
145+ this . redisEngineCpuUsageMetric =
146+ metricFactory . metricMaxRedisEngineCpuUtilizationInPercent ( ) ;
130147 this . freeableMemoryMetric =
131148 metricFactory . metricAverageFreeableMemoryInBytes ( ) ;
132149 this . unusedMemoryMetric = metricFactory . metricAverageUnusedMemoryInBytes ( ) ;
@@ -137,6 +154,7 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
137154 this . itemsEvictedMetrics = metricFactory . metricEvictions ( ) ;
138155
139156 this . cpuUsageAnnotations = [ ] ;
157+ this . redisEngineCpuUsageAnnotations = [ ] ;
140158 this . itemsCountAnnotations = [ ] ;
141159 this . evictedItemsCountAnnotations = [ ] ;
142160 this . memoryUsageAnnotations = [ ] ;
@@ -157,6 +175,29 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
157175 this . cpuUsageAnnotations . push ( createdAlarm . annotation ) ;
158176 this . addAlarm ( createdAlarm ) ;
159177 }
178+
179+ if (
180+ props . addRedisEngineCpuUsageAlarm !== undefined &&
181+ props . clusterType !== ElastiCacheClusterType . REDIS
182+ ) {
183+ throw new Error (
184+ "It is only possible to alarm on Redis Engine CPU Usage for Redis clusters"
185+ ) ;
186+ }
187+
188+ for ( const disambiguator in props . addRedisEngineCpuUsageAlarm ) {
189+ const alarmProps = props . addRedisEngineCpuUsageAlarm [ disambiguator ] ;
190+ const createdAlarm = this . usageAlarmFactory . addMaxCpuUsagePercentAlarm (
191+ this . redisEngineCpuUsageMetric ,
192+ alarmProps ,
193+ disambiguator ,
194+ undefined ,
195+ "RedisEngine"
196+ ) ;
197+ this . redisEngineCpuUsageAnnotations . push ( createdAlarm . annotation ) ;
198+ this . addAlarm ( createdAlarm ) ;
199+ }
200+
160201 for ( const disambiguator in props . addMaxItemsCountAlarm ) {
161202 const alarmProps = props . addMaxItemsCountAlarm [ disambiguator ] ;
162203 const createdAlarm = this . elastiCacheAlarmFactory . addMaxItemsCountAlarm (
@@ -214,13 +255,32 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
214255 }
215256
216257 widgets ( ) : IWidget [ ] {
217- return [
218- this . createTitleWidget ( ) ,
219- this . createCpuUsageWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
220- this . createMemoryUsageWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
221- this . createConnectionsWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
222- this . createItemCountWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
223- ] ;
258+ if ( this . clusterType === ElastiCacheClusterType . REDIS ) {
259+ return [
260+ this . createTitleWidget ( ) ,
261+ new Column (
262+ this . createCpuUsageWidget (
263+ QuarterWidth ,
264+ DefaultTwoLinerGraphWidgetHalfHeight
265+ ) ,
266+ this . createRedisEngineCpuUsageWidget (
267+ QuarterWidth ,
268+ DefaultTwoLinerGraphWidgetHalfHeight
269+ )
270+ ) ,
271+ this . createMemoryUsageWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
272+ this . createConnectionsWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
273+ this . createItemCountWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
274+ ] ;
275+ } else {
276+ return [
277+ this . createTitleWidget ( ) ,
278+ this . createCpuUsageWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
279+ this . createMemoryUsageWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
280+ this . createConnectionsWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
281+ this . createItemCountWidget ( QuarterWidth , DefaultGraphWidgetHeight ) ,
282+ ] ;
283+ }
224284 }
225285
226286 createTitleWidget ( ) {
@@ -242,6 +302,17 @@ export class ElastiCacheClusterMonitoring extends Monitoring {
242302 } ) ;
243303 }
244304
305+ createRedisEngineCpuUsageWidget ( width : number , height : number ) {
306+ return new GraphWidget ( {
307+ width,
308+ height,
309+ title : "Engine CPU Utilization" ,
310+ left : [ this . redisEngineCpuUsageMetric ] ,
311+ leftYAxis : PercentageAxisFromZeroToHundred ,
312+ leftAnnotations : this . redisEngineCpuUsageAnnotations ,
313+ } ) ;
314+ }
315+
245316 createMemoryUsageWidget ( width : number , height : number ) {
246317 return new GraphWidget ( {
247318 width,
0 commit comments