Hardy
Hardy

Reputation: 285

Duplicate elements in AWS cloudwatch Embedded metrics

I am trying to log my service request. First I try to get the service from my partner, upon failure I try the same from my vendor, hence I need to add the same metrics under two different dimensions. Following is my log structure, apparently, this is wrong as JSON does not support duplicate elements, and AWS picks only the latest value in case of duplicates elements. Kindly suggest the right way of doing this.

{
    "_aws": {
        "Timestamp": 1574109732004,
        "CloudWatchMetrics": [{
            "Namespace": "NameSpace1",
            "Dimensions": [["Partner"]],
            "Metrics": [{
                "Name": "requestCount",
                "Unit": "Count"
            }, {
                "Name": "requestFailure",
                "Unit": "Count"
            }, {
                "Name": "responseTime",
                "Unit": "Milliseconds"
            }]
        },
        {
            "Namespace": "NameSpace1",
            "Dimensions": [["vendor"]],
            "Metrics": [{
                "Name": "requestCount",
                "Unit": "Count"
            }, {
                "Name": "requestSuccess",
                "Unit": "Count"
            }, {
                "Name": "responseTime",
                "Unit": "Milliseconds"
            }]
        }]
    },
    "Partner": "partnerName",
    "requestCount": 1,
    "requestFailure": 1,
    "responseTime": 1,
    "vendor": "vendorName",
    "requestCount": 2,
    "requestSuccess": 2,
    "responseTime": 2,
}

Upvotes: 0

Views: 1132

Answers (1)

Dejan Peretin
Dejan Peretin

Reputation: 12119

This will give you metrics separated by partner and vendor:

{
  "Partner": "partnerName",
  "vendor": "vendorName",
  "_aws": {
    "Timestamp": 1577179437354,
    "CloudWatchMetrics": [
      {
        "Dimensions": [
          [
            "Partner"
          ],
          [
            "vendor"
          ]
        ],
        "Metrics": [
          {
            "Name": "requestCount",
            "Unit": "Count"
          },
          {
            "Name": "requestFailure",
            "Unit": "Count"
          },
          {
            "Name": "requestSuccess",
            "Unit": "Count"
          },
          {
            "Name": "responseTime",
            "Unit": "Milliseconds"
          }
        ],
        "Namespace": "NameSpace1"
      }
    ]
  },
  "requestCount": 1,
  "requestFailure": 1,
  "requestSuccess": 1,
  "responseTime": 2
}

Note that this will duplicate the metrics between the two dimensions (if partner registers failure it will be registered on the vendor failure metric also). If you need to avoid this, you can either:

  • have metric names specific to each type (like partnerRequestFailure and vendorRequestFailure)
  • or you need to publish separate json, one for partner and one for vendor.

Upvotes: 1

Related Questions