他的回复:
本帖最后由 Mercy 于 2017-11-21 10:13 编辑云监控数据查询示例: 以华为云华北区为示例: os.environ.setdefault( ´OS_CLOUD_EYE_ENDPOINT_OVERRIDE´, ´https://ces.cn-north-1.myhwclouds.com/V1.0/%(project_id)s´ ) now = datetime.datetime.now() dimensions = [{ "name": "instance_id", "value": "9d81ea96-6f25-4124-b826-36b70569ae2b" }] def get_epoch_time(datetime_): if datetime_: seconds = time.mktime(datetime_.timetuple()) return int(seconds)*1000 else: return None def list_metrics(): query = { "namespace": "SYS.ECS", "metric_name": "cpu_util", "limit": 1 } metrics = conn.cloud_eye.metrics(**query) for metric in metrics: print(metric) def list_metric_aggr_data(): query = { "namespace": "SYS.ECS", "metric_name": "cpu_util", "from": get_epoch_time(now - datetime.timedelta(minutes=20)), "to": get_epoch_time(now), "period": 300, "filter": "average", "dimensions": dimensions } # we query for the data add by add_metric_data() aggregations = list(conn.cloud_eye.metric_aggregations(**query)) for aggr in aggregations: print(aggr) list_metric_aggr_data()