Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Amazon CloudWatch boto API插件,不返回通过UI可用的所有指标_Python_Amazon Web Services_Amazon Ec2 - Fatal编程技术网

Python Amazon CloudWatch boto API插件,不返回通过UI可用的所有指标

Python Amazon CloudWatch boto API插件,不返回通过UI可用的所有指标,python,amazon-web-services,amazon-ec2,Python,Amazon Web Services,Amazon Ec2,问题#1:我正在为Nagios编写一个监控脚本,以从CloudWatch提取数据并在特定阈值下发出警报。我正在使用python的boto插件。当我查询list_度量时,它不会返回CloudWatch UI下所有可用的度量 例如,我试图获得以下指标: **metric_list = [ 'Metric:GetMisses', 'Metric:CmdGet', 'Metric:CPUUtilization',

问题#1:我正在为Nagios编写一个监控脚本,以从CloudWatch提取数据并在特定阈值下发出警报。我正在使用python的boto插件。当我查询list_度量时,它不会返回CloudWatch UI下所有可用的度量

例如,我试图获得以下指标:

**metric_list = [ 'Metric:GetMisses',
                'Metric:CmdGet',
                'Metric:CPUUtilization',
                'Metric:CmdSet']**
唯一的问题是,CmdSet无法从列表度量返回。虽然如果我登录到集群并查看该度量,则会记录该度量的数据。API不返回此度量,但返回CmdSet

从boto的站点读取的conn.list_metrics()应返回所有记录指标的列表

 ***list_metrics(next_token=None, dimensions=None, metric_name=None, namespace=None)

    Returns a list of the valid metrics for which there is recorded data available.
    Parameters: 

        next_token (str) – A maximum of 500 metrics will be returned at one time. If more results are available, the ResultSet returned will contain a non-Null next_token attribute. Passing that token as a parameter to list_metrics will retrieve the next page of metrics.
        dimensions (dict) – A dictionary containing name/value pairs that will be used to filter the results. The key in the dictionary is the name of a Dimension. The value in the dictionary is either a scalar value of that Dimension name that you want to filter on or None if you want all metrics with that Dimension name. To be included in the result a metric must contain all specified dimensions, although the metric may contain additional dimensions beyond the requested metrics. The Dimension names, and values must be strings between 1 and 250 characters long. A maximum of 10 dimensions are allowed.
        metric_name (str) – The name of the Metric to filter against. If None, all Metric names will be returned.
        namespace (str) – A Metric namespace to filter against (e.g. AWS/EC2). If None, Metrics from all namespaces will be returned.***


import boto.ec2.cloudwatch
import datetime
import os
import subprocess

end = datetime.datetime.utcnow()
start = end - datetime.timedelta(minutes=5)

conn = boto.ec2.cloudwatch.connect_to_region("us-east-1")

metrics = conn.list_metrics()

metric_list = [ 'Metric:GetMisses',
                'Metric:CmdGet',
                'Metric:CPUUtilization',
                'Metric:CmdSet']

for metric in metrics:
    print metric
    define_metric_name = str(metric)
    if 'Set' in define_metric_name:
        print metric

    if define_metric_name in metric_list:
        if 'Metric:CPUUtilization' == define_metric_name:
            datapoints = metric.query(start,end, 'Average', 'Percent')
            for data in datapoints:
                try:
                    print 'Average', data['Average'], 'Timestamp',data['Timestamp'], metric, metric.dimensions['CacheClusterId']
                except:
                    continue
        else:
            datapoints = metric.query(start,end, 'Sum', 'Count')
            for data in datapoints:
                try:
                    print 'Sum', data['Sum'], 'Timestamp',['Timestamp'], metric, metric.dimensions['CacheClusterId']
                except:
                    continue
    else:
        continue
如果我打印出度量列表,则不存在CmdSet

链接到Boto的网站

链接到CloudWatch文档


这是一个相当大的问题。您可以通过将这些文件拆分为单独的文件来获得更有效的帮助。@NE1410谢谢。是的,我可以这样做。谢谢您的提示。