代码之家  ›  专栏  ›  技术社区  ›  Hellpless

使用curl向cloudwatch发布自定义度量

  •  0
  • Hellpless  · 技术社区  · 5 年前

    我想做的是将消费指标发布到CloudWatch。 我的架构被设计成坐在弹性豆茎上,所以我更喜欢尽可能少地安装在上面。

    我有这个 tutorial .

    我可以和波斯特一起去吗?(看起来像get方法)。 终点是什么?

    当我试图: curl -X POST https://monitoring.&api-domain;/doc/2010-08-01/?Action=PutMetricData&Version=2010-08-01&Namespace=TestNamespace&MetricData.member.1.MetricName=buffers&MetricData.member.1.Unit=Bytes&&MetricData.member.1.Dimensions.member.1.Name=InstanceType&MetricData.member.1.Dimensions.member.1.Value=m1.small&AUTHPARAMS

    我得到这个错误: 'api-domain' is not recognized as an internal or external command, operable program or batch file. 'Version' is not recognized as an internal or external command, operable program or batch file. 'Namespace' is not recognized as an internal or external command, operable program or batch file. 'MetricData.member.1.MetricName' is not recognized as an internal or external command, operable program or batch file. 'MetricData.member.1.Unit' is not recognized as an internal or external command, operable program or batch file. 'MetricData.member.1.Dimensions.member.1.Value' is not recognized as an internal or external command, operable program or batch file. 'AUTHPARAMS' is not recognized as an internal or external command, operable program or batch file.

    请不要告诉我使用aws cli。

    0 回复  |  直到 5 年前
        1
  •  3
  •   Dejan Peretin    5 年前

    以下是说明如何发出POST请求的文档: https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/making-api-requests.html#CloudWatch-API-requests-using-post-method

    以下是每个区域的终结点列表: https://docs.aws.amazon.com/general/latest/gr/rande.html#cw_region

    curl -X POST \
      https://monitoring.us-east-1.amazonaws.com \
      -H 'Accept: application/json' \
      -H 'Authorization: AWS4-HMAC-SHA256 Credential=YOUR_ACCESS_KEY_GOES_HERE/20190326/us-east-1/monitoring/aws4_request, SignedHeaders=accept;content-encoding;content-length;content-type;host;x-amz-date;x-amz-target, Signature=SIGV4_SIGNATURE_GOES_HERE' \
      -H 'Content-Encoding: amz-1.0' \
      -H 'Content-Length: 141' \
      -H 'Content-Type: application/json' \
      -H 'X-Amz-Date: 20190326T071934Z' \
      -H 'X-Amz-Target: GraniteServiceVersion20100801.PutMetricData' \
      -H 'host: monitoring.us-east-1.amazonaws.com' \
      -d '{
        "Namespace": "StackOverflow",
        "MetricData": [
            {
                "MetricName": "TestMetric",
                "Value": 123.0
            }
        ]
    }'
    

    请注意 Authorization YOUR_ACCESS_KEY_GOES_HERE SIGV4_SIGNATURE_GOES_HERE https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html 这也是为什么使用CLI或sdk是推荐的请求方式之一。