resource "datadog_dashboard_json" "aoma_core_db_dashboard_json" {
  dashboard = jsonencode({
    title       = "AOMA Core DB Dashboard"
    description = "RDS DB Health Board for Aoma Core Prod Instances."
    widgets = [
      {
        id = 219644621
        definition = {
          title         = "Number of Connections - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.database_connections{*} by {name}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219644863
        definition = {
          title         = "CPU Utilization - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.cpuutilization{*} by {name}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219650168
        definition = {
          title = "Available Storage Space -  AOMA-CORE"
          type  = "toplist"
          requests = [
            {
              conditional_formats = [
                {
                  palette    = "white_on_green"
                  value      = 2000000000
                  comparator = ">"
                },
                {
                  palette    = "white_on_red"
                  value      = 2000000000
                  comparator = "<"
                }
              ]
              response_format = "scalar"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.free_storage_space{*} by {name}"
                  aggregator  = "avg"
                }
              ]
              formulas = [
                {
                  formula = "query1"
                }
              ]
              sort = {
                count = 5
                order_by = [
                  {
                    type  = "formula"
                    index = 0
                    order = "desc"
                  }
                ]
              }
            }
          ]
        }
      },
      {
        id = 219652366
        definition = {
          title         = "Available Memory - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.freeable_memory{*} by {name}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219652429
        definition = {
          title         = "Read iops - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.read_iops{*} by {name}.as_count()"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219652878
        definition = {
          title         = "Read latency - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.read_latency{*} by {hostname}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "area"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219654072
        definition = {
          title         = "Read Throughput - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.read_throughput{*} by {hostname}.as_rate()"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "area"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 220228197
        definition = {
          title         = "Max read latency - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.read_latency{*} by {host}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219654087
        definition = {
          title         = "Write iops - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.write_iops{*} by {host}.as_rate()"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "area"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219654089
        definition = {
          title         = "Write latency - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.write_latency{*} by {hostname}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "area"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219654092
        definition = {
          title         = "Write Throughput - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.write_throughput{*} by {hostname}.as_rate()"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219654473
        definition = {
          title         = "Incoming network traffic - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.network_receive_throughput{*} by {hostname}.as_rate()"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219654751
        definition = {
          title         = "Outgoing network traffic - AOMA-CORE"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.network_transmit_throughput{*} by {hostname}.as_rate()"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 219655093
        definition = {
          title         = "Number of outstanding IOs (read/write requests) waiting to access the disk"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.disk_queue_depth{*} by {hostname}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 6300030203131678
        definition = {
          title         = "Oldest Replication Slot Lag"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.oldest_replication_slot_lag{dbname:aoma}"
                }
              ]
              formulas = [
                {
                  formula = "query1"
                },
                {
                  formula = "query1"
                },
                {
                  formula = "(query1 + query1) / 1"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      },
      {
        id = 2647642907221754
        definition = {
          title         = "Replication Slot - Disk Usage"
          show_legend   = true
          legend_size   = "0"
          legend_layout = "auto"
          type          = "timeseries"
          requests = [
            {
              response_format = "timeseries"
              queries = [
                {
                  data_source = "metrics"
                  name        = "query1"
                  query       = "avg:aws.rds.replication_slot_disk_usage{dbname:aoma}"
                }
              ]
              style = {
                palette    = "dog_classic"
                line_type  = "solid"
                line_width = "normal"
              }
              display_type = "line"
            }
          ]
          yaxis = {
            include_zero = true
            scale        = "linear"
            label        = ""
            min          = "auto"
            max          = "auto"
          }
        }
      }
    ]
    template_variables = [
      {
        name             = "name"
        prefix           = "name"
        available_values = []
        default          = "*"
      }
    ]
    layout_type        = "ordered"
    notify_list        = []
    pause_auto_refresh = false
    template_variable_presets = [
      {
        name               = "sfts"
        template_variables = []
      }
    ]
    reflow_type = "auto"
    tags        = ["team:aoma-amp-del-data", "team:aoma-core-team"]
  })
}
