简体   繁体   English

CloudWatch 自定义指标可以是变量而不是硬编码字符串吗

[英]Can a CloudWatch Custom Metric be a variable instead of a hard-coded string

I have created a AWS custom metric in CloudWatch.我在 CloudWatch 中创建了一个 AWS 自定义指标。 I am using NodeJs Lambda function to create a custom metric along with dimensions.我正在使用 NodeJs Lambda function 来创建自定义指标和维度。 I would like to know if we can pass variable value to dimensions instead of string (hardcoded strings).我想知道我们是否可以将变量值传递给尺寸而不是字符串(硬编码字符串)。 Does dimension values accept anything other then string value?维度值是否接受字符串值以外的任何值?

This works:这有效:

var params = {
    MetricData: [
      {
        MetricName: 'PAGES_VISITED',
        Dimensions: [
          {
            Name: 'UNIQUE_PAGES',
            Value: '**URLS**'
          },
        ],
        Unit: 'None',
        Value: 1.0
      },
    ],
    Namespace: 'SITE/TRAFFIC'
  }

But I want to pass something like this:但我想传递这样的东西:

MetricData: [
    {
      MetricName: 'PAGES_VISITED',
      Dimensions: [
        {
          Name: 'MessageAttributes',
          Value: msgattr
        },
        {
          Name: 'CompanyName',
          Value: process.env.CompanyName
        },
        {
          Name: 'short_description',
          Value: message
        },
      ],
      Unit: 'None',
      Value: 10.0
    },
  ],

Yes, that will work fine.是的,那会很好用。

The Value variables for Dimensions can only be strings, but you can provide those strings by referencing variables. Dimensions 的Value变量只能是字符串,但您可以通过引用变量来提供这些字符串。

To see the result, simply print(params) and you will see that the values from the variables have been stored.要查看结果,只需print(params)即可,您将看到变量的值已被存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 GKE kubeconfig 中获取硬编码凭据 - Get hard-coded credentials in GKE kubeconfig 来自状态输入的参考值,结合使用 JSONPath 语法和硬编码字符串 - Reference value from state’s input, using JSONPath syntax in combination with a hard-coded string 在 AWS cloudwatch 仪表板中,我可以 select 绘制指标的所有维度吗 - in AWS cloudwatch dashboard, can i select to chart all dimensions of a metric 从 CloudWatch 获取最新指标 - Obtain latest metric from CloudWatch CloudWatch 指标过滤器中的布尔值问题 - Problem with booleans in CloudWatch Metric Filters Flutter Firestore 问题:无法在 Cloud Firestore 数据库中存储注册表单数据,而是存储硬编码数据 - Flutter Firestore Issue: Not able to store Sign Up form data in Cloud Firestore DB, instead hard coded data is getting stored CloudWatch 日志过滤器计数指标值 < 1 - CloudWatch log filter count metric values are < 1 我可以使用自定义 CloudWatch 指标做什么? - What can I use custom CloudWatch metrics for? 如何在 AWS Cloudwatch 自定义事件中使用 JSON 逻辑? - How can I use JSON logic in an AWS Cloudwatch custom event? 使 CloudWatch Event 传递 integer 时间戳而不是 UTC 时间字符串 - Make CloudWatch Event pass an integer timestamp instead of string of UTC time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM