本文整理汇总了Python中boto.ec2.cloudwatch.CloudWatchConnection.list_metrics方法的典型用法代码示例。如果您正苦于以下问题:Python CloudWatchConnection.list_metrics方法的具体用法?Python CloudWatchConnection.list_metrics怎么用?Python CloudWatchConnection.list_metrics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.ec2.cloudwatch.CloudWatchConnection
的用法示例。
在下文中一共展示了CloudWatchConnection.list_metrics方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_metric_statistics
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
def test_get_metric_statistics(self):
c = CloudWatchConnection()
m = c.list_metrics()[0]
end = datetime.datetime.now()
start = end - datetime.timedelta(hours=24*14)
c.get_metric_statistics(
3600*24, start, end, m.name, m.namespace, ['Average', 'Sum'])
示例2: get_cloudwatch_top_metrics
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
def get_cloudwatch_top_metrics():
conn = CloudWatchConnection()
metrics_names = []
next_token = None
while True:
res = conn.list_metrics(next_token=next_token,
dimensions=settings.CLOUDWATCH_DIMENSIONS,
namespace=settings.CLOUDWATCH_NAMESPACE)
metrics_names.extend([m.name for m in res])
next_token = res.next_token
if next_token is None:
break
# List of tuples like [(metric_name, count), ...]
metrics = []
for metric_name in metrics_names:
res = conn.get_metric_statistics(int(START_DELTA_AGO.total_seconds()),
datetime.datetime.now() - START_DELTA_AGO,
datetime.datetime.now(),
metric_name,
settings.CLOUDWATCH_NAMESPACE,
'Sum',
settings.CLOUDWATCH_DIMENSIONS,
'Count')
if not res:
# Some metrics will not have (or no longer have) results
continue
count = int(res[0]['Sum'])
if count >= TOP_THRESHOLD_COUNT:
metrics.append((metric_name, count))
metrics.sort(key=lambda x: x[1], reverse=True)
text = 'Responses sent\n----------------------\n'
for metric in metrics:
metric_name = 'TOTAL' if metric[0] == settings.CLOUDWATCH_TOTAL_SENT_METRIC_NAME else metric[0]
if metric_name == settings.CLOUDWATCH_PROCESSING_TIME_METRIC_NAME:
continue
text += '%s %s\n' % (str(metric[1]).rjust(5), metric_name)
return text
示例3: BotoWatchInterface
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
class BotoWatchInterface(WatchInterface):
conn = None
saveclcdata = False
def __init__(self, clc_host, access_id, secret_key, token):
#boto.set_stream_logger('foo')
path='/services/CloudWatch'
port=8773
if clc_host[len(clc_host)-13:] == 'amazonaws.com':
clc_host = clc_host.replace('ec2', 'monitoring', 1)
path = '/'
reg = None
port=443
reg = RegionInfo(name='eucalyptus', endpoint=clc_host)
if boto.__version__ < '2.6':
self.conn = CloudWatchConnection(access_id, secret_key, region=reg,
port=port, path=path,
is_secure=True, security_token=token, debug=0)
else:
self.conn = CloudWatchConnection(access_id, secret_key, region=reg,
port=port, path=path, validate_certs=False,
is_secure=True, security_token=token, debug=0)
self.conn.http_connection_kwargs['timeout'] = 30
def __save_json__(self, obj, name):
f = open(name, 'w')
json.dump(obj, f, cls=BotoJsonWatchEncoder, indent=2)
f.close()
def get_metric_statistics(self, period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit):
obj = self.conn.get_metric_statistics(period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit)
if self.saveclcdata:
self.__save_json__(obj, "mockdata/CW_Statistics.json")
return obj
def list_metrics(self, next_token, dimensions, metric_name, namespace):
obj = self.conn.list_metrics(next_token, dimensions, metric_name, namespace)
if self.saveclcdata:
self.__save_json__(obj, "mockdata/CW_Metrics.json")
return obj
def put_metric_data(self, namespace, name, value, timestamp, unit, dimensions, statistics):
return self.conn.put_metric_data(namespace, name, value, timestamp, unit, dimensions, statistics)
示例4: BotoWatchInterface
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
class BotoWatchInterface(WatchInterface):
conn = None
saveclcdata = False
def __init__(self, clc_host, access_id, secret_key, token):
# boto.set_stream_logger('foo')
path = "/services/CloudWatch"
port = 8773
if clc_host[len(clc_host) - 13 :] == "amazonaws.com":
clc_host = clc_host.replace("ec2", "monitoring", 1)
path = "/"
reg = None
port = 443
reg = RegionInfo(name="eucalyptus", endpoint=clc_host)
self.conn = CloudWatchConnection(
access_id, secret_key, region=reg, port=port, path=path, is_secure=True, security_token=token, debug=0
)
self.conn.https_validate_certificates = False
self.conn.http_connection_kwargs["timeout"] = 30
def __save_json__(self, obj, name):
f = open(name, "w")
json.dump(obj, f, cls=BotoJsonWatchEncoder, indent=2)
f.close()
def get_metric_statistics(self, period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit):
obj = self.conn.get_metric_statistics(
period, start_name, end_time, metric_name, namespace, statistics, dimensions, unit
)
if self.saveclcdata:
self.__save_json__(obj, "mockdata/CW_Statistics.json")
return obj
def list_metrics(self, next_token=None, dimensions=None, metric_name=None, namespace=None):
obj = self.conn.list_metrics(next_token, dimensions, metric_name, namespace)
if self.saveclcdata:
self.__save_json__(obj, "mockdata/CW_Metrics.json")
return obj
def put_metric_data(self, namespace, name, value, timestamp, unit, dimensions, statistics):
return self.conn.put_metric_data(namespace, name, value, timestamp, unit, dimensions, statistics)
def describe_alarms(
self,
action_prefix=None,
alarm_name_prefix=None,
alarm_names=None,
max_records=None,
state_value=None,
next_token=None,
):
obj = self.conn.describe_alarms(
action_prefix, alarm_name_prefix, alarm_names, max_records, state_value, next_token
)
if self.saveclcdata:
self.__save_json__(obj, "mockdata/CW_Alarms.json")
return obj
def delete_alarms(self, alarm_names):
return self.conn.delete_alarms(alarm_names)
def enable_alarm_actions(self, alarm_names):
return self.conn.enable_alarm_actions(alarm_names)
def disable_alarm_actions(self, alarm_names):
return self.conn.disable_alarm_actions(alarm_names)
def put_metric_alarm(self, alarm):
return self.conn.put_metric_alarm(alarm)
示例5: __init__
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
#.........这里部分代码省略.........
try:
# only monitor if we are told to (this will break, if not set)
monitoring = self.userdata['monitoring']
except:
monitoring = 'on'
if monitoring in ['on', 'all']:
# first get all we need
[names, values, units, dimensions] = self.collect(monitoring)
while len(names) > 0:
names20 = names[:20]
values20 = values[:20]
units20 = units[:20]
# we can't send all at once, only 20 at a time
# first aggregated over all
result = self.cloudwatch.put_metric_data(self.namespace,
names20, value=values20, unit=units20)
for dimension in dimensions:
dimension = { dimension : dimensions[dimension] }
result &= self.cloudwatch.put_metric_data(
self.namespace, names20, value=values20,
unit=units20, dimensions=dimension)
del names[:20]
del values[:20]
del units[:20]
else:
print "we are not monitoring"
return result
def metrics(self):
return self.cloudwatch.list_metrics()
def _get_nr_wal_files(self):
try:
cursor = self.connection.cursor()
sql = "select count(name) from (select pg_ls_dir('pg_xlog') as name) as xlogs where name != 'archive_status'"
cursor.execute(sql)
[size] = cursor.fetchone()
finally:
cursor.close()
return size
def _get_tables_size(self, connection):
try:
cursor = connection.cursor()
sql = "select sum(pg_relation_size(relid)) from pg_stat_user_tables"
cursor.execute(sql)
[size] = cursor.fetchone()
finally:
cursor.close()
return size
def _get_indexes_size(self, connection):
try:
cursor = connection.cursor()
sql = "select sum(pg_relation_size(indexrelid)) from pg_stat_user_indexes"
示例6: __init__
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
#.........这里部分代码省略.........
units.append('Count')
#
names.append('loading')
values.append(items['loading'])
units.append('Count')
names.append('bgsave_in_progress')
values.append(items['bgsave_in_progress'])
units.append('Count')
# clients
names.append('connected_clients')
values.append(items['connected_clients'])
units.append('Count')
names.append('blocked_clients')
values.append(items['blocked_clients'])
units.append('Count')
# connection/command totals
#names.append('total_connections_received')
#values.append(items['total_connections_received'])
#units.append('Count')
#names.append('total_commands_processed')
#values.append(items['total_commands_processed'])
#units.append('Count')
# client input/output
names.append('client_biggest_input_buf')
values.append(items['client_biggest_input_buf'])
units.append('Bytes')
names.append('client_longest_output_list')
values.append(items['client_longest_output_list'])
units.append('Bytes')
# keys
names.append('expired_keys')
values.append(items['expired_keys'])
units.append('Count')
names.append('evicted_keys')
values.append(items['evicted_keys'])
units.append('Count')
# last_save
names.append('changes_since_last_save')
values.append(items['changes_since_last_save'])
units.append('Count')
# keyspace
#names.append('keyspace_misses')
#values.append(items['keyspace_misses'])
#units.append('Count')
#names.append('keyspace_hits')
#values.append(items['keyspace_hits'])
#units.append('Count')
return [names, values, units, dimensions]
def put(self):
result = False
try:
# only monitor if we are told to (this will break, if not set)
monitoring = self.userdata['monitoring']
except:
monitoring = 'on'
if monitoring in ['on', 'all']:
# first get all we need
[names, values, units, dimensions] = self.collect(monitoring)
print [names, values, units, dimensions]
while len(names) > 0:
names20 = names[:20]
values20 = values[:20]
units20 = units[:20]
# we can't send all at once, only 20 at a time
# first aggregated over all
result = self.cloudwatch.put_metric_data(self.namespace,
names20, value=values20, unit=units20)
for dimension in dimensions:
dimension = { dimension : dimensions[dimension] }
result &= self.cloudwatch.put_metric_data(
self.namespace, names20, value=values20,
unit=units20, dimensions=dimension)
del names[:20]
del values[:20]
del units[:20]
else:
print "we are not monitoring"
return result
def metrics(self):
return self.cloudwatch.list_metrics()
示例7: __init__
# 需要导入模块: from boto.ec2.cloudwatch import CloudWatchConnection [as 别名]
# 或者: from boto.ec2.cloudwatch.CloudWatchConnection import list_metrics [as 别名]
#.........这里部分代码省略.........
values.append(items['used_memory_rss'])
units.append('Bytes')
names.append('mem_fragmentation_ratio')
values.append(items['mem_fragmentation_ratio'])
units.append('None')
names.append('connected_slaves')
values.append(items['connected_slaves'])
units.append('Count')
#
names.append('loading')
values.append(items['loading'])
units.append('Count')
names.append('bgsave_in_progress')
values.append(items['bgsave_in_progress'])
units.append('Count')
# clients
names.append('connected_clients')
values.append(items['connected_clients'])
units.append('Count')
names.append('blocked_clients')
values.append(items['blocked_clients'])
units.append('Count')
# connection/command totals
names.append('total_connections_received')
values.append(items['total_connections_received'])
units.append('Count')
names.append('total_commands_processed')
values.append(items['total_commands_processed'])
units.append('Count')
# client input/output
names.append('client_biggest_input_buf')
values.append(items['client_biggest_input_buf'])
units.append('Bytes')
names.append('client_longest_output_list')
values.append(items['client_longest_output_list'])
units.append('Bytes')
# keys
names.append('expired_keys')
values.append(items['expired_keys'])
units.append('Count')
names.append('evicted_keys')
values.append(items['evicted_keys'])
units.append('Count')
# last_save
names.append('changes_since_last_save')
values.append(items['changes_since_last_save'])
units.append('Count')
# keyspace
names.append('keyspace_misses')
values.append(items['keyspace_misses'])
units.append('Count')
names.append('keyspace_hits')
values.append(items['keyspace_hits'])
units.append('Count')
return [names, values, units, dimensions]
def put(self):
# first get all we need
[names, values, units, dimensions] = self.collect()
while len(names) > 0:
names20 = names[:20]
values20 = values[:20]
units20 = units[:20]
# we can't send all at once, only 20 at a time
# first aggregated over all
self.__log('put aggregated ReDiS metrics data', 'info')
result = self.cloudwatch.put_metric_data(self.namespace,
names20, value=values20, unit=units20)
for dimension in dimensions:
self.__log('put ReDiS metrics data for {0}'.format(dimensions[dimension]), 'info')
dimension = { dimension : dimensions[dimension] }
result &= self.cloudwatch.put_metric_data(self.namespace,
names20, value=values20, unit=units20,
dimensions=dimension)
del names[:20]
del values[:20]
del units[:20]
return result
def metrics(self):
return self.cloudwatch.list_metrics()