将可卷曲的POST自定义指标发布到cloudwatch

时间:2019-03-25 12:35:20

标签: amazon-web-services curl metrics amazon-cloudwatch

我想将api调用的结果记录到云监视。 我要做的是将消耗量指标发布到云监视中。 我的体系结构设计为位于弹性beantalk上,因此我希望在其上安装尽可能少的东西。

我试图了解是否可以通过简单的CURL POST发布云监视。

我有这个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。 我知道我可以用。我想尽量不要使用它。

2 个答案:

答案 0 :(得分:1)

以下是说明如何发出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

产生的卷曲看起来像这样:

.ToString()

请注意,以上示例中的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 } ] }' 头具有两个占位符,AuthorizationYOUR_ACCESS_KEY_GOES_HERE。这些是您将用来对请求进行签名的凭据中的访问密钥,以及使用此算法必须构建的签名:https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html,这是使用CLI或SDK的原因之一。推荐的请求方式。

答案 1 :(得分:0)

这里是一个纯bash示例,仅需要curl和openssl。它的灵感来自:https://github.com/riboseinc/aws-authenticating-secgroup-scripts

UIResponder