可以为度量标准在许多方面一个CloudWatch的警报定义度量、警报、定义、方面

2023-09-11 10:39:30 作者:是我输了爱情

我使用Python和博托对CloudWatch的指标。我希望能够为定义一个警报的 MetricName 这将是积极的所有其他方面。

I'm using python and boto for cloudwatch metrics. I would like to be able to define an alarm for a MetricName which will be active for all the other dimensions.

比如我有的MemoryUsage I-XXX 。是否有可能定义将触发的MemoryUsage 为单次闹钟的所有的 INSTANCEID 尺寸?

For instance I have a metric in the sandbox namespace with MetricName of MemoryUsage and InstanceId of i-xxx. Is it possible to define a single alarm that will be triggered for MemoryUsage for all InstanceId dimensions?

推荐答案

是的,你可以创建任何单一指标报警。在这种情况下,单个度量具有重新presents所有实例的尺寸。下面是如何在博托做到这一点。

Yes, you can create an alarm for any single metric. In this case, the single metric has a dimension that represents all instances. Here's how you can do it in boto.

In [1]: import boto

In [2]: cw = boto.connect_cloudwatch()

In [3]: cw.list_metrics(metric_name='CPUUtilization')
Out[3]: 
[Metric:CPUUtilization,
 Metric:CPUUtilization,
 Metric:CPUUtilization,
 Metric:CPUUtilization]

In [4]: l = _

In [5]: for m in l:
   ...:     print m.name, m.dimensions
   ...: 
CPUUtilization {u'ImageId': [u'ami-1b814f72']}
CPUUtilization {u'InstanceId': [u'i-366c4354']}
CPUUtilization {}
CPUUtilization {u'InstanceType': [u'm1.large']}

您可以在这里看到,有与METRIC_NAME CPU利用率相关的四个独立的指标。第一有所有使用该特定的AMI,第二个为现在正在运行的特定实例的尺寸实例的尺寸,第四具有特定的类型的所有实例的尺寸,但第三没有指定的尺寸。在所有我的实例该指标重新presents CPU利用率。所以:

You can see here that there are four separate metrics associated with the metric_name CPUUtilization. The first has a dimension of all instances that use that particular AMI, the second has a dimension for a particular instance that is now running, the fourth has a dimension of all instances of a particular type, but the third has no specified dimension. This metric represents CPUUtilization across all of my instances. So:

In [6]: m = l[2]

In [7]: m.create_alarm(name='cpu_all_instances', comparison='>', threshold=80.0, period=60, evaluation_periods=2, statistic='Average')
Out[7]: MetricAlarm:cpu_all_instances[CPUUtilization(Average) GreaterThanThreshold 80.0]

此警报应该火,如果在所有我的情况下,CPU的平均使用率超过80%,两个评估期。你也可以选择不同的统计,像'最大',这将触发对是否在所有情况下,CPU利用率的最大值超过了80%,超过2评估期。

This alarm should fire if the average CPU utilization across all my instances exceeds 80% for two evaluation periods. You could also choose a different statistic, like 'Maximum', that would fire if the maximum value for CPU utilization across all instances exceeded 80% for more than 2 evaluation periods.

我不知道你是专门寻找的MemoryUsage,或者这只是一个例子,但我不认为的MemoryUsage是CloudWatch的可用的衡量标准之一。

I don't know if you are specifically looking for MemoryUsage or if that was just an example but I don't think MemoryUsage is one of the available metrics from CloudWatch.