Class: MysqlFramework::Stats::DimensionMap

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_framework/stats/dimension_map.rb

Overview

Class to handle dimensions for AWS reporting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_name: nil, application: nil, environment: nil, landscape: nil, namespace: nil) ⇒ void

Initializes dimension values used for CloudWatch metrics.

Parameters:

  • service_name (String, nil) (defaults to: nil)

    service dimension

  • application (String, nil) (defaults to: nil)

    application dimension

  • environment (String, nil) (defaults to: nil)

    environment dimension

  • landscape (String, nil) (defaults to: nil)

    landscape dimension

  • namespace (String, nil) (defaults to: nil)

    CloudWatch namespace override



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mysql_framework/stats/dimension_map.rb', line 17

def initialize(
  service_name: nil,
  application: nil,
  environment: nil,
  landscape: nil,
  namespace: nil
)
  @service_name = service_name
  @application = application
  @environment = environment
  @landscape = landscape
  @namespace = namespace
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



7
8
9
# File 'lib/mysql_framework/stats/dimension_map.rb', line 7

def application
  @application
end

#environmentObject

Returns the value of attribute environment.



7
8
9
# File 'lib/mysql_framework/stats/dimension_map.rb', line 7

def environment
  @environment
end

#landscapeObject

Returns the value of attribute landscape.



7
8
9
# File 'lib/mysql_framework/stats/dimension_map.rb', line 7

def landscape
  @landscape
end

#namespaceString

Returns the CloudWatch namespace.

Returns:

  • (String)

    configured namespace or default namespace value



46
47
48
# File 'lib/mysql_framework/stats/dimension_map.rb', line 46

def namespace
  @namespace
end

#service_nameObject

Returns the value of attribute service_name.



7
8
9
# File 'lib/mysql_framework/stats/dimension_map.rb', line 7

def service_name
  @service_name
end

Instance Method Details

#to_cloudwatch_dimensionsArray<Hash{Symbol => String}>

Builds CloudWatch dimensions from configured values or environment variables.

Returns:

  • (Array<Hash{Symbol => String}>)

    dimensions with non-nil values only



34
35
36
37
38
39
40
41
# File 'lib/mysql_framework/stats/dimension_map.rb', line 34

def to_cloudwatch_dimensions
  [
    { name: 'ServiceName', value: service_name || ENV.fetch('SERVICE_NAME', nil) },
    { name: 'Application', value: application || ENV.fetch('APPLICATION', nil) },
    { name: 'Environment', value: environment || ENV.fetch('ENVIRONMENT', nil) },
    { name: 'Landscape', value: landscape || ENV.fetch('LANDSCAPE', nil) }
  ].reject { |dimension| dimension[:value].nil? }
end