json 正在为cloudwatch Jmeter 板设置小部件,获取错误“ Jmeter 板主体无效,存在1个验证错误”

xpszyzbs  于 2023-08-08  发布在  其他
关注(0)|答案(3)|浏览(87)

我无法在小部件中引用servicename。
使用给定的代码获得以下错误: Jmeter 板主体无效,存在1个验证错误:[{"dataPath ":"/widgets/0/properties/metrics/0 "," message ":"不应超过3个项目"}](服务:AmazonCloudWatch状态代码:错误代码:400无效参数输入

"CloudwatchDashboard": {
      "Type": "AWS::CloudWatch::Dashboard",
      "Properties": {

"{ \"widgets\":
[{ \"type\":\"metric\", 
\"x\":0, 
\"y\":0, 
\"width\":12, 
\"height\":6, 
\"properties\":
{ \"metrics\":
[[ \"AWS/ECS\", \"CPUUtilization\", \"ServiceName\",
{ \"Fn::Sub\": [ \"${Service}\", { \"Service\": {\"Ref\" : \"AWS::StackName\" }} ]}]], 
\"region\": \"us-east-1\", 
\"stat\":\"Average\",
\"period\": 300, 
\"view\": \"timeSeries\", 
\"title\":\"CPUUtilization\", 
\"stacked\": false } }]}"

      }
    }

字符串

1cklez4t

1cklez4t1#

Jmeter 板主体是一个字符串,因此将Sub语法放在该字符串中将使其成为 Jmeter 板定义的一部分,这反过来又使其无效。
我建议改用yaml语法。这将允许您保持 Jmeter 板定义更清晰,您可以像这样使用Sub

ExampleDashboard:
    Type: AWS::CloudWatch::Dashboard
    Properties: 
        DashboardName: 'SomeDashboard'
        DashboardBody: !Sub |
          {
              "widgets": [
                  {
                      "type": "metric",
                      "x": 0,
                      "y": 0,
                      "width": 12,
                      "height": 6,
                      "properties": {
                          "metrics": [
                              [ "AWS/ECS", "CPUUtilization", "ServiceName", "${AWS::StackName}"]
                          ],
                          "region": "us-east-1",
                          "stat": "Average",
                          "period": 300,
                          "view": "timeSeries",
                          "title": "CPUUtilization",
                          "stacked": false
                      }
                  }
              ]
          }

字符串
在JSON中也是这样:

"ExampleDashboard": {
            "Type": "AWS::CloudWatch::Dashboard",
            "Properties": {
                "DashboardName": "SomeDashboard",
                "DashboardBody": {
                    "Fn::Sub": "{\n    \"widgets\": [\n        {\n            \"type\": \"metric\",\n            \"x\": 0,\n            \"y\": 0,\n            \"width\": 12,\n            \"height\": 6,\n            \"properties\": {\n                \"metrics\": [\n                    [ \"AWS/ECS\", \"CPUUtilization\", \"ServiceName\", \"${AWS::StackName}\"]\n                ],\n                \"region\": \"us-east-1\",\n                \"stat\": \"Average\",\n                \"period\": 300,\n                \"view\": \"timeSeries\",\n                \"title\": \"CPUUtilization\",\n                \"stacked\": false\n            }\n        }\n    ]\n}\n"
                }
            }
        }

tgabmvqs

tgabmvqs2#

您可以在yaml模板中以JSON定义CloudWatch Jmeter 板,如下所示:

ExampleDashboard:
    Type: AWS::CloudWatch::Dashboard
    Properties: 
      DashboardName: 'SomeDashboard'
      DashboardBody: !Sub '
{
    "widgets": [
        {
            "type": "metric",
            "x": 0,
            "y": 0,
            "width": 12,
            "height": 6,
            "properties": {
                "metrics": [
                    [ "AWS/ECS", "CPUUtilization", "ServiceName", "${AWS::StackName}"]
                ],
                "region": "us-east-1",
                "stat": "Average",
                "period": 300,
                "view": "timeSeries",
                "title": "CPUUtilization",
                "stacked": false
            }
        }
    ]
}
'

字符串

xienkqul

xienkqul3#

我刚刚犯了这个错误:对于未来的谷歌人来说,这个错误是误导!我的问题是,我不小心把整个小部件的小写了,所以它有e.g. functionname而不是FunctionName。修复箱子让它展开。

相关问题