AWSTemplateFormatVersion: "2010-09-09"
Description: HACOBE-CLOUD CloudWatch Dashboard and Alerm

Metadata:
  AWS::CloudFormation::Interface:
    ParameterGroups:
      -
        Label:
          default: Target Instance Configuration
        Parameters:
          - TargetECSTaskId
      -
        Label:
          default: Alarm Configuration
        Parameters:
          - InputBitrateAlarmThreshold
          - DataBitrateAlarmThreshold
          - VideoBitrateAlarmThreshold
          - AudioBitrateAlarmThreshold          
#####################################################################
# Parameters 設定
#####################################################################
Parameters:
  TargetECSTaskId:
    Type: String
  InputBitrateAlarmThreshold:
    Default: 20000000
    Type: Number
  DataBitrateAlarmThreshold:
    Default: 10000000
    Type: Number
  VideoBitrateAlarmThreshold:
    Default: 8000000
    Type: Number
  AudioBitrateAlarmThreshold:
    Default: 2000000
    Type: Number
#####################################################################
# Resources 設定
#####################################################################
Resources:
#####################################################################
# アラーム設定 ストリーム関連
#####################################################################
  SRTLoss:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub SRT_loss_${TargetECSTaskId}
      MetricName: srt.pktRcvLoss
      Namespace: HACOBE_CLOUD
      Statistic: Maximum 
      Period: 60  
      EvaluationPeriods: 1  
      Threshold: 0  
      TreatMissingData: missing  
      ComparisonOperator: GreaterThanThreshold  
      Dimensions:
        - Name: ecs_task_id
          Value: 
            Ref: TargetECSTaskId
  RTPLost:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub RTP_lost_${TargetECSTaskId}
      MetricName: rtp.error.lost
      Namespace: HACOBE_CLOUD
      Statistic: Maximum 
      Period: 60  
      EvaluationPeriods: 1  
      Threshold: 0  
      TreatMissingData: missing  
      ComparisonOperator: GreaterThanThreshold  
      Dimensions:
        - Name: ecs_task_id
          Value: 
            Ref: TargetECSTaskId
#####################################################################
# アラーム設定 　ビットレート関連
#####################################################################
  InputBitrate:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Input_Bitrate_${TargetECSTaskId}
      MetricName: ts.bitrate.total.input.ave
      Namespace: HACOBE_CLOUD
      Statistic: Maximum 
      Period: 300  
      EvaluationPeriods: 1  
      Threshold: !Ref InputBitrateAlarmThreshold
      TreatMissingData: missing  
      ComparisonOperator: GreaterThanThreshold  
      Dimensions:
        - Name: ecs_task_id
          Value: 
            Ref: TargetECSTaskId
  DataBitrate:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Data_Bitrate_${TargetECSTaskId}
      MetricName: ts.bitrate.total.data.ave
      Namespace: HACOBE_CLOUD
      Statistic: Average 
      Period: 60  
      EvaluationPeriods: 1  
      Threshold: !Ref DataBitrateAlarmThreshold
      TreatMissingData: missing  
      ComparisonOperator: GreaterThanThreshold  
      Dimensions:
        - Name: ecs_task_id
          Value: 
            Ref: TargetECSTaskId
  VideoBitrate:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Video_Bitrate_${TargetECSTaskId}
      MetricName: ts.bitrate.group.VIDEO.ave
      Namespace: HACOBE_CLOUD
      Statistic: Average 
      Period: 60  
      EvaluationPeriods: 1  
      Threshold: !Ref VideoBitrateAlarmThreshold
      TreatMissingData: missing  
      ComparisonOperator: GreaterThanThreshold  
      Dimensions:
        - Name: ecs_task_id
          Value: 
            Ref: TargetECSTaskId
  AudioBitrate:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Audio_Bitrate_${TargetECSTaskId}
      MetricName: ts.bitrate.group.AUDIO.ave
      Namespace: HACOBE_CLOUD
      Statistic: Average 
      Period: 60  
      EvaluationPeriods: 1  
      Threshold: !Ref AudioBitrateAlarmThreshold
      TreatMissingData: missing  
      ComparisonOperator: GreaterThanThreshold  
      Dimensions:
        - Name: ecs_task_id
          Value: 
            Ref: TargetECSTaskId
#####################################################################
# アラーム設定 エラー関連
#####################################################################
  TSSyncLoss:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub TS_Sync_loss_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.1_1.TS_sync_Loss
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  SyncByteError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Sync_byte_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.1_2.Sync_byte_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  PATError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub PAT_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.1_3.PAT_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  ContinuityCountError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Continuity_count_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.1_4.Continuity_count_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  PMTError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub PMT_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.1_5.PMT_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  TransportError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub Transport_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.2_1.Transport_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  CRCError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub CRC_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.2_2.CRC_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  PTSError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub PTS_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.2_5.PTS_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing
  CATError:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub CAT_error_${TargetECSTaskId}
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      EvaluationPeriods: 1
      Threshold: 0
      Metrics:
        - Expression: IF(DIFF(m1) >= 0, DIFF(m1), 0)
          Id: result
          ReturnData: true
        - Id: m1
          MetricStat:
            Metric:
              MetricName: ts.etr290.priority.2_6.CAT_error
              Dimensions:
                - Name: ecs_task_id
                  Value:  
                    Ref: TargetECSTaskId
              Namespace: HACOBE_CLOUD
            Period: 300
            Stat: Maximum
          ReturnData: false
      TreatMissingData: missing 
#####################################################################
# ダッシュボード設定
#####################################################################
  CWDashboard:
    Type: AWS::CloudWatch::Dashboard
    Properties:
      DashboardName: !Sub hacobe-cloud-${TargetECSTaskId}
      DashboardBody: !Sub |
        {
            "widgets": [
        {
            "height": 6,
            "width": 6,
            "y": 2,
            "x": 6,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "ts.bitrate.total.input.ave", "ecs_task_id", "${TargetECSTaskId}", { "label": "入力レート(平均)", "color": "#2ca02c" } ],
                    [ "...", { "stat": "Maximum", "color": "#d62728", "label": "入力レート(最大)" } ],
                    [ "...", { "stat": "Minimum", "color": "#1f77b4", "label": "入力レート(最小)" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 60,
                "title": "入力レート"
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 2,
            "x": 12,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "ts.bitrate.total.ts.ave", "ecs_task_id", "${TargetECSTaskId}", { "color": "#2ca02c", "label": "TSレート(平均)" } ],
                    [ "...", { "stat": "Maximum", "color": "#d62728", "label": "TSレート(最大)" } ],
                    [ "...", { "stat": "Minimum", "color": "#1f77b4", "label": "TSレート(最小)" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "period": 60,
                "stat": "Average",
                "title": "TSレート"
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 2,
            "x": 18,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "ts.bitrate.total.data.ave", "ecs_task_id", "${TargetECSTaskId}", { "color": "#2ca02c", "label": "データレート(平均)" } ],
                    [ "...", { "stat": "Maximum", "color": "#d62728", "label": "データレート(最大)" } ],
                    [ "...", { "stat": "Minimum", "color": "#1f77b4", "label": "データレート(最小)" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 60,
                "title": "データレート"
            }
        },
        {
            "height": 6,
            "width": 9,
            "y": 8,
            "x": 6,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "ts.bitrate.group.PSI/SI.ave", "ecs_task_id", "${TargetECSTaskId}", { "label": "PSI/SI" } ],
                    [ ".", "ts.bitrate.group.VIDEO.ave", ".", ".", { "label": "Video" } ],
                    [ ".", "ts.bitrate.group.AUDIO.ave", ".", ".", { "label": "Audio" } ],
                    [ ".", "ts.bitrate.group.OTHER.ave", ".", ".", { "label": "Other" } ],
                    [ ".", "ts.bitrate.group.NULL.ave", ".", ".", { "label": "Null" } ]
                ],
                "view": "timeSeries",
                "stacked": true,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 60,
                "title": "パケット別帯域グラフ"
            }
        },
        {
            "height": 6,
            "width": 9,
            "y": 8,
            "x": 15,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "ts.bitrate.group.PSI/SI.ave", "ecs_task_id", "${TargetECSTaskId}", { "label": "PSI/SI" } ],
                    [ ".", "ts.bitrate.group.VIDEO.ave", ".", ".", { "label": "Video" } ],
                    [ ".", "ts.bitrate.group.AUDIO.ave", ".", ".", { "label": "Audio" } ],
                    [ ".", "ts.bitrate.group.OTHER.ave", ".", ".", { "label": "Other" } ],
                    [ ".", "ts.bitrate.group.NULL.ave", ".", ".", { "label": "Null" } ]
                ],
                "view": "pie",
                "stacked": true,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 60,
                "setPeriodToTimeRange": true,
                "legend": {
                    "position": "right"
                },
                "labels": {
                    "visible": false
                },
                "liveData": false,
                "title": "パケット別帯域円グラフ"
            }
        },
        {
            "height": 5,
            "width": 24,
            "y": 14,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "TS_sync_Loss", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m2) >= 0, DIFF(m2), 0)", "label": "Sync_byte_error", "id": "e2", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m3) >= 0, DIFF(m3), 0)", "label": "PAT_error", "id": "e3", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m4) >= 0, DIFF(m4), 0)", "label": "Continuity_count_error", "id": "e4", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m5) >= 0, DIFF(m5), 0)", "label": "PMT_error", "id": "e5", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m6) >= 0, DIFF(m6), 0)", "label": "Transport_error", "id": "e6", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m7) >= 0, DIFF(m7), 0)", "label": "CRC_error", "id": "e7", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m8) >= 0, DIFF(m8), 0)", "label": "PTS_error", "id": "e8", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m9) >= 0, DIFF(m9), 0)", "label": "CAT_error", "id": "e9", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.1_1.TS_sync_Loss", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false } ],
                    [ ".", "ts.etr290.priority.1_2.Sync_byte_error", ".", ".", { "id": "m2", "visible": false } ],
                    [ ".", "ts.etr290.priority.1_3.PAT_error", ".", ".", { "id": "m3", "visible": false } ],
                    [ ".", "ts.etr290.priority.1_4.Continuity_count_error", ".", ".", { "id": "m4", "visible": false } ],
                    [ ".", "ts.etr290.priority.1_5.PMT_error", ".", ".", { "id": "m5", "visible": false } ],
                    [ ".", "ts.etr290.priority.2_1.Transport_error", ".", ".", { "id": "m6", "visible": false } ],
                    [ ".", "ts.etr290.priority.2_2.CRC_error", ".", ".", { "id": "m7", "visible": false } ],
                    [ ".", "ts.etr290.priority.2_5.PTS_error", ".", ".", { "id": "m8", "visible": false } ],
                    [ ".", "ts.etr290.priority.2_6.CAT_error", ".", ".", { "id": "m9", "visible": false } ]
                ],
                "sparkline": true,
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 60,
                "liveData": false,
                "setPeriodToTimeRange": false,
                "trend": true,
                "singleValueFullPrecision": false,
                "title": "エラーカウント",
                "yAxis": {
                    "left": {
                        "label": "Count",
                        "showUnits": false
                    },
                    "right": {
                        "label": "",
                        "showUnits": false
                    }
                },
                "legend": {
                    "position": "bottom"
                }
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 5,
            "x": 0,
            "type": "alarm",
            "properties": {
                "title": "エラーインジケータ(TS)",
                "alarms": [
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:CRC_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Transport_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:TS_sync_loss_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:PTS_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:CAT_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Sync_byte_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Continuity_count_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:PMT_error_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:PAT_error_${TargetECSTaskId}"                ]
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 55,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "rtp.bitrate.media", "ecs_task_id", "${TargetECSTaskId}", { "color": "#dbdb8d" } ],
                    [ "...", { "stat": "Minimum", "color": "#aec7e8" } ],
                    [ "...", { "stat": "Average", "color": "#1f77b4" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 1,
                "title": "ビットレート(メディア)",
                "yAxis": {
                    "left": {
                        "min": 0
                    }
                }
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 55,
            "x": 6,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "rtp.bitrate.fec_column", "ecs_task_id", "${TargetECSTaskId}", { "color": "#dbdb8d" } ],
                    [ "...", { "stat": "Minimum", "color": "#aec7e8" } ],
                    [ "...", { "stat": "Average", "color": "#ff7f0e" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 1,
                "title": "ビットレート(FEC-COLUMN)",
                "yAxis": {
                    "left": {
                        "min": 0
                    }
                }
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 55,
            "x": 12,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "rtp.bitrate.fec_row", "ecs_task_id", "${TargetECSTaskId}", { "stat": "Maximum", "color": "#dbdb8d" } ],
                    [ "...", { "stat": "Minimum", "color": "#aec7e8" } ],
                    [ "...", { "color": "#2ca02c" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 1,
                "title": "ビットレート(FEC-ROW)",
                "yAxis": {
                    "left": {
                        "min": 0
                    }
                }
            }
        },
        {
            "height": 6,
            "width": 12,
            "y": 49,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "rtp.bitrate.input", "ecs_task_id", "${TargetECSTaskId}", { "stat": "Maximum", "color": "#dbdb8d" } ],
                    [ "...", { "stat": "Minimum", "color": "#aec7e8" } ],
                    [ "...", { "color": "#9467bd" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "title": "受信ビットレート",
                "period": 1,
                "stat": "Average",
                "yAxis": {
                    "left": {
                        "min": 0
                    }
                }
            }
        },
        {
            "height": 4,
            "width": 24,
            "y": 61,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "パケット消失数", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m2) >= 0, DIFF(m2), 0)", "label": "パケットリカバリー数", "id": "e2", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m3) >= 0, DIFF(m3), 0)", "label": "パケット欠落数", "id": "e3", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m4) >= 0, DIFF(m4), 0)", "label": "シーケンス不整合", "id": "e4", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "rtp.error.drop", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "rtp.error.recover", "ecs_task_id", "${TargetECSTaskId}", { "id": "m2", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "rtp.error.lost", "ecs_task_id", "${TargetECSTaskId}", { "id": "m3", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "trtp.error.sequence_mismatch", "ecs_task_id", "${TargetECSTaskId}", { "id": "m4", "visible": false, "region": "${AWS::Region}" } ]
                ],
                "sparkline": true,
                "view": "singleValue",
                "region": "${AWS::Region}",
                "liveData": false,
                "singleValueFullPrecision": false,
                "setPeriodToTimeRange": false,
                "trend": true,
                "title": "エラーカウント(種類別)",
                "period": 60,
                "stat": "Maximum"
            }
        },
        {
            "height": 6,
            "width": 6,
            "y": 55,
            "x": 18,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "rtp.bitrate.media", "ecs_task_id", "${TargetECSTaskId}" ],
                    [ ".", "rtp.bitrate.fec_column", ".", "." ],
                    [ ".", "rtp.bitrate.fec_row", ".", "." ]
                ],
                "view": "timeSeries",
                "stacked": true,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 1,
                "title": "ビットレート(メデイア+FEC)",
                "yAxis": {
                    "left": {
                        "min": 0
                    }
                }
            }
        },
        {
            "height": 2,
            "width": 24,
            "y": 47,
            "x": 0,
            "type": "text",
            "properties": {
                "markdown": "# **▶️ RTP Receive Status**"
            }
        },
        {
            "height": 2,
            "width": 24,
            "y": 0,
            "x": 0,
            "type": "text",
            "properties": {
                "markdown": "# **▶️ Transport Stream Status**"
            }
        },
        {
            "height": 6,
            "width": 12,
            "y": 31,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "srt.mbpsRecvRate", "ecs_task_id", "${TargetECSTaskId}", { "stat": "Minimum", "color": "#1f77b4", "label": "受信ビットレート(最小)" } ],
                    [ "...", { "stat": "Maximum", "color": "#d62728", "label": "受信ビットレート(最大)" } ],
                    [ "...", { "color": "#2ca02c", "label": "受信ビットレート(平均)" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 60,
                "title": "受信ビットレート"
            }
        },
        {
            "height": 2,
            "width": 24,
            "y": 29,
            "x": 0,
            "type": "text",
            "properties": {
                "markdown": "# **▶️ SRT Receive Status**"
            }
        },
        {
            "height": 6,
            "width": 8,
            "y": 37,
            "x": 16,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "パケット欠落数", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvDrop", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 60,
                "title": "パケット欠落数",
                "yAxis": {
                    "left": {
                        "label": "Count",
                        "showUnits": false
                    },
                    "right": {
                        "label": "",
                        "showUnits": false
                    }
                }
            }
        },
        {
            "height": 6,
            "width": 8,
            "y": 37,
            "x": 8,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "パケット再送数", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvRetrans", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 60,
                "title": "パケット再送数",
                "yAxis": {
                    "left": {
                        "label": "Count",
                        "showUnits": false
                    },
                    "right": {
                        "label": "",
                        "showUnits": false
                    }
                }
            }
        },
        {
            "height": 6,
            "width": 8,
            "y": 37,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "パケット消失数", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvLoss", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 60,
                "title": "パケット消失数",
                "yAxis": {
                    "left": {
                        "label": "Count",
                        "showUnits": false
                    },
                    "right": {
                        "label": "",
                        "showUnits": false
                    }
                }
            }
        },
        {
            "height": 6,
            "width": 12,
            "y": 31,
            "x": 12,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ "HACOBE_CLOUD", "srt.msRTT", "ecs_task_id", "${TargetECSTaskId}", { "stat": "Minimum", "color": "#1f77b4", "label": "ラウンドトリップタイム(最小)" } ],
                    [ "...", { "stat": "Maximum", "color": "#d62728", "label": "ラウンドトリップタイム(最大)" } ],
                    [ "...", { "label": "ラウンドトリップタイム(平均)" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 60,
                "title": "ラウンドトリップタイム"
            }
        },
        {
            "height": 4,
            "width": 24,
            "y": 43,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "パケット消失数", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m2) >= 0, DIFF(m2), 0)", "label": "パケット再送数", "id": "e2", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m3) >= 0, DIFF(m3), 0)", "label": "パケット欠落数", "id": "e3", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m4) >= 0, DIFF(m4), 0)", "label": "デスクランブル失敗パケット数", "id": "e4", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m5) >= 0, DIFF(m5), 0)", "label": "処理が間に合わなかったパケット数", "id": "e5", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvLoss", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvRetrans", "ecs_task_id", "${TargetECSTaskId}", { "id": "m2", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvDrop", "ecs_task_id", "${TargetECSTaskId}", { "id": "m3", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvUndecrypt", "ecs_task_id", "${TargetECSTaskId}", { "id": "m4", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "srt.pktRcvBelated", "ecs_task_id", "${TargetECSTaskId}", { "id": "m5", "visible": false, "region": "${AWS::Region}" } ]
                ],
                "view": "singleValue",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 60,
                "setPeriodToTimeRange": false,
                "sparkline": true,
                "trend": true,
                "title": "エラーカウント(種類別)"
            }
        },
        {
            "height": 6,
            "width": 12,
            "y": 49,
            "x": 12,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "m1/1000", "label": "式1", "id": "e1", "visible": false } ],
                    [ { "expression": "m2/1000", "label": "式2", "id": "e2", "visible": false } ],
                    [ { "expression": "m3/1000", "label": "式3", "id": "e3", "visible": false } ],
                    [ "HACOBE_CLOUD", "rtp.jitter.max", "ecs_task_id", "${TargetECSTaskId}", { "stat": "Maximum", "color": "#dbdb8d", "id": "m1" } ],
                    [ ".", "rtp.jitter.min", ".", ".", { "stat": "Minimum", "color": "#c7c7c7", "id": "m2" } ],
                    [ ".", "rtp.jitter.ave", ".", ".", { "color": "#17becf", "id": "m3" } ]
                ],
                "view": "timeSeries",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Average",
                "period": 1,
                "title": "RTPジッター",
                "yAxis": {
                    "left": {
                        "showUnits": true
                    }
                }
            }
        },
        {
            "height": 3,
            "width": 6,
            "y": 2,
            "x": 0,
            "type": "alarm",
            "properties": {
                "title": "エラーインジケータ(ビットレート)",
                "alarms": [
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Video_Bitrate_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Audio_Bitrate_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Input_Bitrate_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:Data_Bitrate_${TargetECSTaskId}"
                ]
            }
        },
        {
            "height": 3,
            "width": 6,
            "y": 11,
            "x": 0,
            "type": "alarm",
            "properties": {
                "title": "エラーインジケータ(RTP/SRT_lost)",
                "alarms": [
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:SRT_loss_${TargetECSTaskId}",
                    "arn:aws:cloudwatch:${AWS::Region}:${AWS::AccountId}:alarm:RTP_lost_${TargetECSTaskId}"
                ]
            }
        },
        {
            "height": 6,
            "width": 24,
            "y": 23,
            "x": 0,
            "type": "log",
            "properties": {
                "query": "SOURCE 'HACOBE_CLOUD_EVENT' | fields @timestamp, ecs_task_id, message\n| filter ecs_task_id = \"${TargetECSTaskId}\"\n| sort @timestamp desc\n| limit 20",
                "region": "${AWS::Region}",
                "stacked": false,
                "title": "イベントログ",
                "view": "table"
            }
        },
        {
            "height": 4,
            "width": 24,
            "y": 19,
            "x": 0,
            "type": "metric",
            "properties": {
                "metrics": [
                    [ { "expression": "IF(DIFF(m1) >= 0, DIFF(m1), 0)", "label": "TS_sync_loss", "id": "e1", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m2) >= 0, DIFF(m2), 0)", "label": "Sync_byte_error", "id": "e2", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m3) >= 0, DIFF(m3), 0)", "label": "PAT_error", "id": "e3", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m4) >= 0, DIFF(m4), 0)", "label": "Continuity_count_error", "id": "e4", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m5) >= 0, DIFF(m5), 0)", "label": "PMT_error", "id": "e5", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m6) >= 0, DIFF(m6), 0)", "label": "Transport_error", "id": "e6", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m7) >= 0, DIFF(m7), 0)", "label": "CRC_error", "id": "e7", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m8) >= 0, DIFF(m8), 0)", "label": "PTS_error", "id": "e8", "region": "${AWS::Region}", "period": 60 } ],
                    [ { "expression": "IF(DIFF(m9) >= 0, DIFF(m9), 0)", "label": "CAT_error", "id": "e9", "region": "${AWS::Region}", "period": 60 } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.1_1.TS_sync_Loss", "ecs_task_id", "${TargetECSTaskId}", { "id": "m1", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.1_2.Sync_byte_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m2", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.1_3.PAT_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m3", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.1_4.Continuity_count_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m4", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.1_5.PMT_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m5", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.2_1.Transport_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m6", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.2_2.CRC_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m7", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.2_5.PTS_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m8", "visible": false, "region": "${AWS::Region}" } ],
                    [ "HACOBE_CLOUD", "ts.etr290.priority.2_6.CAT_error", "ecs_task_id", "${TargetECSTaskId}", { "id": "m9", "visible": false, "region": "${AWS::Region}" } ]
                ],
                "sparkline": true,
                "view": "singleValue",
                "stacked": false,
                "region": "${AWS::Region}",
                "stat": "Maximum",
                "period": 60,
                "liveData": false,
                "setPeriodToTimeRange": false,
                "trend": true,
                "singleValueFullPrecision": false,
                "title": "エラーカウント(種類別)",
                "yAxis": {
                    "left": {
                        "label": "Count",
                        "showUnits": false
                    },
                    "right": {
                        "label": "",
                        "showUnits": false
                    }
                },
                "legend": {
                    "position": "bottom"
                }
            }
        }
        ]
        }
