Class: RoutesAlerts::SuccessRate

Inherits:
Base
  • Object
show all
Defined in:
lib/routes_alerts/metrics/success_rate.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #route_info

Instance Method Summary collapse

Methods inherited from Base

#actions, #create!, #initialize, #log_group_name, #namespace, #prefix, #route_name

Constructor Details

This class inherits a constructor from RoutesAlerts::Base

Instance Method Details

#alarm_paramsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/routes_alerts/metrics/success_rate.rb', line 25

def alarm_params
  {
    alarm_name: "#{prefix}Alarm-#{RoutesAlerts::Metrics::SUCCESS_METRIC_NAME}-#{route_name}",
    actions_enabled: !!actions&.any?,
    ok_actions: actions,
    alarm_actions: actions,
    metrics: [
      {
        id: "m1",
        metric_stat: {
          metric: {
            namespace: namespace,
            metric_name: "#{RoutesAlerts::Metrics::SUCCESS_METRIC_NAME}-#{route_name}",
            dimensions: [],
          },
          period: route_info.alarm_period,
          stat: "Sum",
        },
        return_data: false
      },
      {
        id: "m2", 
        metric_stat: {
          metric: {
            namespace: namespace,
            metric_name: "#{RoutesAlerts::Metrics::COUNT_METRIC_NAME}-#{route_name}",
            dimensions: [],
          },
          period: route_info.alarm_period,
          stat: "Sum",
        },
        return_data: false
      },
      {
        id: "e1",
        expression: "(m1/m2)*100",
      }
    ],
    evaluation_periods: route_info.number_of_datapoints,
    datapoints_to_alarm: route_info.number_of_datapoints,
    threshold: route_info.success_rate,
    comparison_operator: "LessThanThreshold",
    treat_missing_data: "notBreaching",
  }
end

#filter_patternObject



4
5
6
# File 'lib/routes_alerts/metrics/success_rate.rb', line 4

def filter_pattern
  "{ $.path = \"#{route_info.path}\" && $.method = \"#{route_info.method}\" && $.status >= 200 && $.status < 300 }"
end

#metric_paramsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/routes_alerts/metrics/success_rate.rb', line 8

def metric_params
  {
    log_group_name: log_group_name,
    filter_name: "#{RoutesAlerts::Metrics::SUCCESS_METRIC_NAME}-#{route_name}",
    filter_pattern: filter_pattern,
    metric_transformations: [
      {
        metric_name: "#{RoutesAlerts::Metrics::SUCCESS_METRIC_NAME}-#{route_name}",
        metric_namespace: namespace,
        metric_value: "1",
        default_value: 0,
        unit: "Count",
      },
    ]
  }
end