private async Task EnsureReadAlarms(AlarmTables alarmTables) { foreach (var table in alarmTables.Tables) { await EnsureReadAlarms(alarmTables, table); } }
private async Task EnsureWriteAlarms(AlarmTables alarmTables) { foreach (var table in alarmTables.Tables) { var monitorWrites = table.MonitorWrites ?? true; if (monitorWrites) { await EnsureWriteAlarm(alarmTables, table); } else { _logger.Detail($"Not monitoring writes to {table.Name}"); } } }
private async Task EnsureWriteAlarm(AlarmTables alarmTables, Table table) { try { var tableResource = await _tableSource.GetResourceAsync(table.Name); if (tableResource == null) { _logger.Info($"Skipping named table {table.Name} as it does not exist"); return; } var tableDescription = tableResource.Resource; var threshold = table.Threshold ?? alarmTables.Threshold; await _tableAlarmCreator.EnsureWriteCapacityAlarm(tableDescription, alarmTables.AlarmNameSuffix, threshold, alarmTables.SnsTopicArn, alarmTables.DryRun); var monitorThrottling = table.MonitorThrottling ?? alarmTables.MonitorThrottling; var throttlingThreshold = table.ThrottlingThreshold ?? alarmTables.ThrottlingThreshold; if (monitorThrottling) { await _tableAlarmCreator.EnsureWriteThrottleAlarm(tableDescription, alarmTables.AlarmNameSuffix, throttlingThreshold, alarmTables.SnsTopicArn, alarmTables.DryRun); } foreach (var index in tableDescription.GlobalSecondaryIndexes) { await _indexAlarmCreator.EnsureWriteCapacityAlarm(tableDescription, index, alarmTables.AlarmNameSuffix, threshold, alarmTables.SnsTopicArn, alarmTables.DryRun); if (monitorThrottling) { await _indexAlarmCreator.EnsureWriteThrottleAlarm(tableDescription, index, alarmTables.AlarmNameSuffix, throttlingThreshold, alarmTables.SnsTopicArn, alarmTables.DryRun); } } } catch (Exception ex) { _logger.Error(ex, $"Error when creating table write alarm for {table.Name}"); throw; } }
private async Task EnsureReadAlarms(AlarmTables alarmTables, Table table) { try { var tableResource = await _tableSource.GetResourceAsync(table.Name); var tableDescription = tableResource.Resource; var threshold = table.Threshold ?? alarmTables.Threshold; await _tableAlarmCreator.EnsureReadCapacityAlarm(tableDescription, alarmTables.AlarmNameSuffix, threshold, alarmTables.SnsTopicArn, alarmTables.DryRun); var monitorThrottling = table.MonitorThrottling ?? alarmTables.MonitorThrottling; var throttlingThreshold = table.ThrottlingThreshold ?? alarmTables.ThrottlingThreshold; if (monitorThrottling) { await _tableAlarmCreator.EnsureReadThrottleAlarm(tableDescription, alarmTables.AlarmNameSuffix, throttlingThreshold, alarmTables.SnsTopicArn, alarmTables.DryRun); } foreach (var index in tableDescription.GlobalSecondaryIndexes) { await _indexAlarmCreator.EnsureReadCapacityAlarm(tableDescription, index, alarmTables.AlarmNameSuffix, threshold, alarmTables.SnsTopicArn, alarmTables.DryRun); if (monitorThrottling) { await _indexAlarmCreator.EnsureReadThrottleAlarm(tableDescription, index, alarmTables.AlarmNameSuffix, throttlingThreshold, alarmTables.SnsTopicArn, alarmTables.DryRun); } } } catch (Exception ex) { _logger.Error(ex, $"Error when creating table read alarm for {table.Name}"); throw; } }