Skip to content

Commit

Permalink
Refactor kafka dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
cfln123 committed Jul 9, 2024
1 parent 690e8e1 commit ae5d138
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 65 deletions.
2 changes: 2 additions & 0 deletions lib/cfnguardian/compile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
require 'cfnguardian/resources/port'
require 'cfnguardian/resources/internal_port'
require 'cfnguardian/resources/nrpe'
require 'cfnguardian/resources/kafka_cluster'
require 'cfnguardian/resources/kafka_topic'
require 'cfnguardian/resources/lambda'
require 'cfnguardian/resources/network_targetgroup'
require 'cfnguardian/resources/rds_cluster'
Expand Down
8 changes: 4 additions & 4 deletions lib/cfnguardian/models/alarm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ def initialize(resource,environment)
end

class KafkaClusterAlarm < BaseAlarm
def initialize(resource)
def initialize(resource,broker)
super(resource)
@group = 'KafkaCluster'
@namespace = 'AWS/Kafka'
@dimensions = { ClusterName: resource['Id'] }
@dimensions = { 'Cluster Name': resource['Id'], 'Broker ID': broker }
@statistic = 'Average'
@evaluation_periods = 1
@datapoints_to_alarm = 1
Expand All @@ -409,11 +409,11 @@ def initialize(resource)
end

class KafkaTopicAlarm < BaseAlarm
def initialize(resource)
def initialize(resource,broker)
super(resource)
@group = 'KafkaTopic'
@namespace = 'AWS/Kafka'
@dimensions = { ClusterName: resource['ClusterName'], Topic: resource['Id'] }
@dimensions = { 'Cluster Name': resource['ClusterName'], 'Broker ID': broker, Topic: resource['Id'] }
@statistic = 'Average'
@evaluation_periods = 1
@datapoints_to_alarm = 1
Expand Down
114 changes: 60 additions & 54 deletions lib/cfnguardian/resources/kafka_cluster.rb
Original file line number Diff line number Diff line change
@@ -1,68 +1,74 @@
module CfnGuardian::Resource
class KafkaCluster < Base

def default_alarms
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'CPUUserCritical'
alarm.metric_name = 'CPUUser'
alarm.threshold = 80
@alarms.push(alarm)
def initialize(resource, override_group = nil)
super(resource, override_group)
@brokers_list = resource['Brokers']
end

def default_alarms
@brokers_list.each do |broker|
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-CPUUserCritical"
alarm.metric_name = 'CpuUser'
alarm.threshold = 80
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'CPUUserWarning'
alarm.metric_name = 'CPUUser'
alarm.threshold = 50
alarm.alarm_action = 'Warning'
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-CPUUserWarning"
alarm.metric_name = 'CpuUser'
alarm.threshold = 50
alarm.alarm_action = 'Warning'
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'KafkaDataLogsDiskUsedCritical'
alarm.metric_name = 'KafkaDataLogsDiskUsed'
alarm.threshold = 85
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-KafkaDataLogsDiskUsedCritical"
alarm.metric_name = 'KafkaDataLogsDiskUsed'
alarm.threshold = 85
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'KafkaDataLogsDiskUsedWarning'
alarm.metric_name = 'KafkaDataLogsDiskUsed'
alarm.threshold = 70
alarm.alarm_action = 'Warning'
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-KafkaDataLogsDiskUsedWarning"
alarm.metric_name = 'KafkaDataLogsDiskUsed'
alarm.threshold = 70
alarm.alarm_action = 'Warning'
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'BurstBalance'
alarm.metric_name = 'BurstBalance'
alarm.threshold = 1
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-BurstBalance"
alarm.metric_name = 'BurstBalance'
alarm.threshold = 1
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'MemoryFreeCritical'
alarm.metric_name = 'MemoryFree'
alarm.threshold = 10
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-MemoryFreeCritical"
alarm.metric_name = 'MemoryFree'
alarm.threshold = 10
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'MemoryFreeWarning'
alarm.metric_name = 'MemoryFree'
alarm.threshold = 50
alarm.alarm_action = 'Warning'
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-MemoryFreeWarning"
alarm.metric_name = 'MemoryFree'
alarm.threshold = 50
alarm.alarm_action = 'Warning'
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'NetworkRxErrorsCritical'
alarm.metric_name = 'NetworkRxErrors'
alarm.threshold = 10
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-NetworkRxErrorsCritical"
alarm.metric_name = 'NetworkRxErrors'
alarm.threshold = 10
@alarms.push(alarm)

alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource)
alarm.name = 'NetworkRxErrorsWarning'
alarm.metric_name = 'NetworkRxErrors'
alarm.threshold = 5
alarm.alarm_action = 'Warning'
@alarms.push(alarm)
alarm = CfnGuardian::Models::KafkaClusterAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-NetworkRxErrorsWarning"
alarm.metric_name = 'NetworkRxErrors'
alarm.threshold = 5
alarm.alarm_action = 'Warning'
@alarms.push(alarm)
end
end

end
end
21 changes: 14 additions & 7 deletions lib/cfnguardian/resources/kafka_topic.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
module CfnGuardian::Resource
class KafkaTopic < Base

def default_alarms
alarm = CfnGuardian::Models::KafkaTopicAlarm.new(@resource)
alarm.name = 'MessagesInPerSec'
alarm.metric_name = 'MessagesInPerSec'
alarm.threshold = 5
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)
def initialize(resource, override_group = nil)
super(resource, override_group)
@brokers_list = resource['Brokers']
end

def default_alarms
@brokers_list.each do |broker|
alarm = CfnGuardian::Models::KafkaTopicAlarm.new(@resource,broker)
alarm.name = "Broker#{broker}-MessagesInPerSec"
alarm.metric_name = 'MessagesInPerSec'
alarm.threshold = 5
alarm.comparison_operator = 'LessThanThreshold'
@alarms.push(alarm)
end
end
end
end

0 comments on commit ae5d138

Please sign in to comment.